-
Notifications
You must be signed in to change notification settings - Fork 20
/
slack_host_notify.sh
executable file
·37 lines (28 loc) · 1.04 KB
/
slack_host_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
#!/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
# Host Notification command example :
# define command {
# command_name slack-host
# command_line /usr/lib64/nagios/plugins/slack_host_notify "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTADDRESS$" "$HOSTSTATE$" "$HOSTOUTPUT$" "$LONGDATETIME$"
# }
case $4 in
"DOWN")
MSG_COLOR="danger"
;;
"UP")
MSG_COLOR="good"
;;
*)
MSG_COLOR="#CCCCCC"
;;
esac
IFS='%'
SLACK_MSG="payload={\"attachments\":[{\"color\": \"$MSG_COLOR\",\"title\": \"Host $1 notification\",
\"text\": \"Host: $2\\nIP: $3\\nState: $4\"},
{\"color\": \"$MSG_COLOR\",\"title\":\"Additional Info :\",\"text\":\"\\n$5\",
\"footer\": \"Nagios notification: $6\",\"footer_icon\": \"$FOOTER_ICON\"}]}"
#Send message to Slack
curl -4 -X POST --data "$SLACK_MSG" $SLACK_URL
unset IFS