-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxymon_to_slack.sh
60 lines (54 loc) · 1.39 KB
/
xymon_to_slack.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
#!/bin/bash
# Please reference Slack Incoming Webhooks for more information.
# https://api.slack.com/incoming-webhooks
# Variables for Slack
url="[WEBHOOKURL]"
channel="#${RCPT}"
# Variables for Xymon
hostname=$BBHOSTNAME # The name of the host that the alert is about
alert_color=$BBCOLORLEVEL # The color of the alert: "red", "yellow" or "purple"
alert_msg=$BBALPHAMSG # The full text of the status log triggering the alert
alert_title="$BBHOSTSVC $level" # HOSTNAME.SERVICE that the alert is about.
# If I'm gonna output a message, mind as well timestamp it.
time_stamp() {
date +%Y-%m-%d:%H:%M:%S"%R $*"
}
# Check the color and set Slack payload variables.
case $alert_color in
red)
emoji=":red_circle:"
color="danger" # Slack Side Bar
;;
yellow)
emoji=":warning:"
color="warning" # Slack Side Bar
;;
green)
emoji=":ok:"
color="good" # Slack Side Bar
;;
purple)
time_stamp "xymon_to_slack.sh: Received Purple Alert. Ignoring."
exit
;;
esac
# Setup the payload for delivery to Slack.
payload=$(< <(cat <<EOF
{
"channel": "${channel}",
"username": "${hostname}",
"icon_emoji": "${emoji}",
"attachments": [
{
"title": "${alert_title}",
"color": "${color}",
"text": "${alert_msg}",
}
]
}
]
}
EOF
))
# Deliver the Payload to Slack
curl -s -X POST --data-urlencode "payload=${payload}" ${url}