-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack-service-notification.sh
66 lines (62 loc) · 1.5 KB
/
slack-service-notification.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
ICINGA_HOSTNAME="Icinga2Web Hostname"
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/TB231Z5XGC2E/B213BZRD3L4B/utiohjrekgns3misebfhk"
SLACK_CHANNEL="#monitor"
SLACK_BOTNAME="Icinga2"
#Set the message icon based on ICINGA service state
if [ "$SERVICESTATE" = "CRITICAL" ]
then
COLOR="danger"
elif [ "$SERVICESTATE" = "WARNING" ]
then
COLOR="warning"
elif [ "$SERVICESTATE" = "OK" ]
then
COLOR="good"
elif [ "$SERVICESTATE" = "UNKNOWN" ]
then
COLOR="#800080"
else
COLOR=""
fi
#Send message to Slack
read -d '' PAYLOAD << EOF
{
"channel": "${SLACK_CHANNEL}",
"username": "${SLACK_BOTNAME}",
"attachments": [
{
"fallback": "${SERVICESTATE}: ${HOSTDISPLAYNAME} - ${SERVICEDISPLAYNAME}",
"color": "${COLOR}",
"fields": [
{
"title": "",
"value": "${LONGDATETIME} - ${SERVICEDESC} on ${HOSTALIAS}",
"short": false
},
{
"title": "Type:",
"value": "${NOTIFICATIONTYPE}",
"short": false
},
{
"title": "Host:",
"value": "${HOSTNAME} (${HOSTADDRESS})",
"short": false
},
{
"title": "State:",
"value": "${SERVICESTATE}",
"short": true
},
{
"title": "Info:",
"value": "${SERVICEOUTPUT}",
"short": false
}
]
}
]
}
EOF
curl --connect-timeout 30 --max-time 60 -s -S -X POST -H 'Content-type: application/json' --data "${PAYLOAD}" "${SLACK_WEBHOOK_URL}"slack-service-notification.sh