Nagios: Difference between revisions

Content added Content deleted
Line 244: Line 244:
import argparse
import argparse


# /usr/local/bin/nagios_slack_alert.py -nt "$NOTIFICATIONTYPE$" -ha "$HOSTALIAS$" -hs $HOSTSTATE$ -had $HOSTADDRESS$ -ho $HOSTOUTPUT$
# /usr/local/bin/nagios_slack_alert.py -nt "$NOTIFICATIONTYPE$" -ha "$HOSTALIAS$" -sd "$SERVICEDESC$" -ss "$SERVICESTATE$" -had $HOSTADDRESS$ -so $SERVICEOUTPUT$
# -nt "Down" -hs "DOWN" -ha "My-Host-Alias" -ho "sometest" -had "1.2.3.4"
# -nt "Down" -sd "SNMP SRV" -ss "Srv DOwn" -ha "My-Host-Alias" -so "sometest" -had "1.2.3.4"


token = 'xoxp-35wfw56854-309159sdf75-3591ew110-fdgdgfddg533ett34057e31wef822'
token = 'xoxp-353634854-309156544575-359146663110-95d597hfghghtr57e31166a42822'
sc = SlackClient(token)
sc = SlackClient(token)


Line 253: Line 253:
parser.add_argument("-nt", "--notificationtype")
parser.add_argument("-nt", "--notificationtype")
parser.add_argument("-ha", "--hostalias")
parser.add_argument("-ha", "--hostalias")
parser.add_argument("-hs", "--hoststate")
parser.add_argument("-sd", "--servicedesc")
parser.add_argument("-ss", "--servicestate")
parser.add_argument("-had", "--hostaddress")
parser.add_argument("-had", "--hostaddress")
parser.add_argument("-ho", "--hostoutput")
parser.add_argument("-so", "--serviceoutput")


args = parser.parse_args()
args = parser.parse_args()
Line 261: Line 262:
notificationtype = str(args.notificationtype)
notificationtype = str(args.notificationtype)
hostalias = str(args.hostalias)
hostalias = str(args.hostalias)
hoststate = str(args.hoststate)
servicedesc = str(args.servicedesc)
servicestate = str(args.servicestate)
hostaddress = str(args.hostaddress)
hostaddress = str(args.hostaddress)
hostoutput = str(args.hostoutput)
serviceoutput = str(args.serviceoutput)


colors = 0
colors = 0
if "DOWN" in hoststate:
if "CRITICAL" in servicestate:
colors = 'danger'
colors = 'danger'
elif 'UP' in hoststate:
elif 'OK' in servicestate:
colors = 'good'
colors = 'good'
else:
else:
Line 275: Line 277:
attachments = []
attachments = []
attachments.append({
attachments.append({
'title': 'Notification Type: ' + notificationtype,
'title': 'ServiceDesc: ' + servicedesc,
'text': 'Host Alias: ' + hostalias + '\n' + 'IP:' + hostaddress + '\n' + 'Host State:' + hoststate,
'text': 'Service State: ' + servicestate + '\n' + 'Host Alias: ' + hostalias + '\n' +'IP: ' + hostaddress + '\n',
'color': colors,
'color': colors,
'footer': 'Host Output:' + hostoutput
'footer': 'Service Output: ' + serviceoutput
#'ts': longdatetime
#'ts': longdatetime
})
})
Line 289: Line 291:


response = sc.api_call('chat.postMessage', channel="@aman",
response = sc.api_call('chat.postMessage', channel="@aman",
text='Nagios Alert', **formatted_result, username='My Bot',
text='Nagios Service Alert: ' + notificationtype, **formatted_result, username='My Bot',
icon_emoji=':brief_case:')
icon_emoji=':brief_case:')


Line 305: Line 307:
import argparse
import argparse


# /usr/local/bin/nagios_slack_alert.py -nt "$NOTIFICATIONTYPE$" -ha "$HOSTALIAS$" -sd "$SERVICEDESC$" -ss "$SERVICESTATE$" -had $HOSTADDRESS$ -so $SERVICEOUTPUT$
# /usr/local/bin/nagios_slack_alert.py -nt "$NOTIFICATIONTYPE$" -ha "$HOSTALIAS$" -hs $HOSTSTATE$ -had $HOSTADDRESS$ -ho $HOSTOUTPUT$
# -nt "Down" -sd "SNMP SRV" -ss "Srv DOwn" -ha "My-Host-Alias" -so "sometest" -had "1.2.3.4"
# -nt "Down" -hs "DOWN" -ha "My-Host-Alias" -ho "sometest" -had "1.2.3.4"


token = 'xoxp-35wfw56854-309159sdf75-3591ew110-fdgdgfddg533ett34057e31wef822'
token = 'xoxp-353634854-309156544575-359146663110-95d597hfghghtr57e31166a42822'
sc = SlackClient(token)
sc = SlackClient(token)


Line 314: Line 316:
parser.add_argument("-nt", "--notificationtype")
parser.add_argument("-nt", "--notificationtype")
parser.add_argument("-ha", "--hostalias")
parser.add_argument("-ha", "--hostalias")
parser.add_argument("-sd", "--servicedesc")
parser.add_argument("-hs", "--hoststate")
parser.add_argument("-ss", "--servicestate")
parser.add_argument("-had", "--hostaddress")
parser.add_argument("-had", "--hostaddress")
#parser.add_argument("-so", "--serviceoutput")
parser.add_argument("-ho", "--hostoutput")


args = parser.parse_args()
args = parser.parse_args()
Line 323: Line 324:
notificationtype = str(args.notificationtype)
notificationtype = str(args.notificationtype)
hostalias = str(args.hostalias)
hostalias = str(args.hostalias)
servicedesc = str(args.servicedesc)
hoststate = str(args.hoststate)
servicestate = str(args.servicestate)
hostaddress = str(args.hostaddress)
hostaddress = str(args.hostaddress)
#serviceoutput = str(args.serviceoutput)
hostoutput = str(args.hostoutput)


colors = 0
colors = 0
if "CRITICAL" in servicestate:
if "DOWN" in hoststate:
colors = 'danger'
colors = 'danger'
elif 'OK' in servicestate:
elif 'UP' in hoststate:
colors = 'good'
colors = 'good'
else:
else:
Line 338: Line 338:
attachments = []
attachments = []
attachments.append({
attachments.append({
'title': 'Notification Type: ' + notificationtype,
'title': 'Host Alias: ' + hostalias,
'text': 'Host Alias: ' + hostalias + '\n' +'IP:' + hostaddress + '\n' + 'Service State:' + servicestate+ '\n' + 'ServiceDesc: ' + servicedesc,
'text': 'Host State:' + hoststate + '\n' + 'IP:' + hostaddress,
'color': colors,
'color': colors,
'footer': 'Service Output:' + "serviceoutput"
'footer': 'Host Output:' + hostoutput
#'ts': longdatetime
#'ts': longdatetime
})
})
Line 352: Line 352:


response = sc.api_call('chat.postMessage', channel="@aman",
response = sc.api_call('chat.postMessage', channel="@aman",
text='Nagios Alert', **formatted_result, username='My Bot',
text='Nagios Host Alert: ' + notificationtype, **formatted_result, username='My Bot',
icon_emoji=':brief_case:')
icon_emoji=':brief_case:')