forked from obaarne/Nagios2Slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack_service_notify.sh
executable file
·40 lines (31 loc) · 1.15 KB
/
slack_service_notify.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
# Edit your Slack hook URL and footer icon URL
SLACK_URL=https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
FOOTER_ICON=http://env.baarnes.com/Nagios.png
# Service Notification command example :
# define command {
# command_name slack-service
# command_line /usr/lib64/nagios/plugins/slack_service_notify "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTADDRESS$" "$SERVICEDESC$" "$SERVICESTATE$" "$SERVICEOUTPUT$" "$LONGDATETIME$" "$LASTHOSTSTATECHANGE$"
# }
case $5 in
"CRITICAL")
MSG_COLOR="danger"
;;
"WARNING")
MSG_COLOR="warning"
;;
"OK")
MSG_COLOR="good"
;;
*)
MSG_COLOR="#CCCCCC"
;;
esac
IFS='%'
SLACK_MSG="payload={\"attachments\":[{\"color\": \"$MSG_COLOR\",\"title\": \"Service $1 notification\",
\"text\": \"Host: $2\\nIP: $3\\nService: $4\\nState: $5\"},
{\"color\": \"$MSG_COLOR\",\"title\":\"Additional Info :\",\"text\":\"\\n$6\",
\"footer\": \"Nagios notification: $7\",\"footer_icon\": \"$FOOTER_ICON\"}]}"
#Send message to Slack
curl -4 -X POST --data "$SLACK_MSG" $SLACK_URL
unset IFS