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$" - |
# /usr/local/bin/nagios_slack_alert.py -nt "$NOTIFICATIONTYPE$" -ha "$HOSTALIAS$" -sd "$SERVICEDESC$" -ss "$SERVICESTATE$" -had $HOSTADDRESS$ -so $SERVICEOUTPUT$ |
||
# -nt "Down" - |
# -nt "Down" -sd "SNMP SRV" -ss "Srv DOwn" -ha "My-Host-Alias" -so "sometest" -had "1.2.3.4" |
||
token = 'xoxp- |
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("- |
parser.add_argument("-sd", "--servicedesc") |
||
⚫ | |||
parser.add_argument("-had", "--hostaddress") |
parser.add_argument("-had", "--hostaddress") |
||
parser.add_argument("- |
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) |
||
servicedesc = str(args.servicedesc) |
|||
⚫ | |||
hostaddress = str(args.hostaddress) |
hostaddress = str(args.hostaddress) |
||
serviceoutput = str(args.serviceoutput) |
|||
colors = 0 |
colors = 0 |
||
if " |
if "CRITICAL" in servicestate: |
||
colors = 'danger' |
colors = 'danger' |
||
elif ' |
elif 'OK' in servicestate: |
||
colors = 'good' |
colors = 'good' |
||
else: |
else: |
||
Line 275: | Line 277: | ||
attachments = [] |
attachments = [] |
||
attachments.append({ |
attachments.append({ |
||
'title': ' |
'title': 'ServiceDesc: ' + servicedesc, |
||
'text': ' |
'text': 'Service State: ' + servicestate + '\n' + 'Host Alias: ' + hostalias + '\n' +'IP: ' + hostaddress + '\n', |
||
'color': colors, |
'color': colors, |
||
'footer': ' |
'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$" - |
# /usr/local/bin/nagios_slack_alert.py -nt "$NOTIFICATIONTYPE$" -ha "$HOSTALIAS$" -hs $HOSTSTATE$ -had $HOSTADDRESS$ -ho $HOSTOUTPUT$ |
||
# -nt "Down" - |
# -nt "Down" -hs "DOWN" -ha "My-Host-Alias" -ho "sometest" -had "1.2.3.4" |
||
token = 'xoxp- |
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("- |
parser.add_argument("-hs", "--hoststate") |
||
⚫ | |||
parser.add_argument("-had", "--hostaddress") |
parser.add_argument("-had", "--hostaddress") |
||
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) |
||
hoststate = str(args.hoststate) |
|||
⚫ | |||
hostaddress = str(args.hostaddress) |
hostaddress = str(args.hostaddress) |
||
hostoutput = str(args.hostoutput) |
|||
colors = 0 |
colors = 0 |
||
if " |
if "DOWN" in hoststate: |
||
colors = 'danger' |
colors = 'danger' |
||
elif ' |
elif 'UP' in hoststate: |
||
colors = 'good' |
colors = 'good' |
||
else: |
else: |
||
Line 338: | Line 338: | ||
attachments = [] |
attachments = [] |
||
attachments.append({ |
attachments.append({ |
||
'title': ' |
'title': 'Host Alias: ' + hostalias, |
||
'text': 'Host |
'text': 'Host State:' + hoststate + '\n' + 'IP:' + hostaddress, |
||
'color': colors, |
'color': colors, |
||
'footer': ' |
'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:') |
||