-
Notifications
You must be signed in to change notification settings - Fork 7
/
send-discord-host.sh
55 lines (46 loc) · 1.47 KB
/
send-discord-host.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
#!/bin/bash
# Nagios domain, used for generating our URLs
nagios_domain=""
# Webhook URL, change this to your channels URL
webhook_url="https://discordapp.com/api/webhooks/id/token"
# Some colours, change them if you like
clr_red=13632027
clr_yel=16098851
clr_grn=8311585
# pick colour
clr=$clr_yel
if [[ "$NAGIOS_NOTIFICATIONTYPE" = "PROBLEM" ]]; then
clr=$clr_red
fi
if [[ "$NAGIOS_NOTIFICATIONTYPE" = "RECOVERY" ]]; then
clr=$clr_grn
fi
# Our internal nagios URL
nagios_url="https://${nagios_domain}/cgi-bin/nagios3/extinfo.cgi?type=1&host=${NAGIOS_HOSTNAME}"
# totals
hosts_total=$(( $NAGIOS_TOTALHOSTSUP + $NAGIOS_TOTALHOSTSDOWN ))
services_total=$(( $NAGIOS_TOTALSERVICESOK + $NAGIOS_TOTALSERVICEPROBLEMS ))
json_data="{
\"username\": \"Nagios\",
\"embeds\": [
{
\"title\": \"Nagios alert: **${NAGIOS_HOSTNAME}** ${NAGIOS_HOSTSTATE} (${NAGIOS_NOTIFICATIONTYPE})\",
\"description\": \"\`${NAGIOS_HOSTADDRESS}\`\",
\"url\": \"${nagios_url}\",
\"color\": ${clr},
\"timestamp\": \"${NAGIOS_SHORTDATETIME}\",
\"fields\": [
{
\"name\": \"Host Output\",
\"value\": \"${NAGIOS_HOSTOUTPUT}\"
}
],
\"footer\": {
\"text\": \"${NAGIOS_TOTALHOSTSUP}/${hosts_total} hosts up, ${NAGIOS_TOTALSERVICESOK}/${services_total} services ok\",
\"icon_url\": \"\"
}
}
]
}"
curl -v -H 'Content-Type: application/json' "${webhook_url}" -d "$json_data" &> /tmp/send-discord-host.log
exit $?