forked from diogopms/monit-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslack
More file actions
executable file
·27 lines (22 loc) · 691 Bytes
/
slack
File metadata and controls
executable file
·27 lines (22 loc) · 691 Bytes
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
#!/bin/bash
if [[ -z "${SLACK_URL}" ]]; then
echo "Missing Slack url"
exit 1
fi
COLOR=${MONIT_COLOR:-$([[ $MONIT_EVENT == *"succeeded"* ]] && echo good || echo danger)}
TEXT=$(echo -e "$MONIT_EVENT: $MONIT_DESCRIPTION" | python3 -c "import json,sys;print(json.dumps(sys.stdin.read()))")
PAYLOAD="{
\"attachments\": [
{
\"text\": $TEXT,
\"color\": \"$COLOR\",
\"mrkdwn_in\": [\"text\"],
\"fields\": [
{ \"title\": \"Date\", \"value\": \"$MONIT_DATE\", \"short\": true },
{ \"title\": \"Service\", \"value\": \"$MONIT_SERVICE\", \"short\": true }
]
}
]
}"
curl -s -X POST --data-urlencode "payload=$PAYLOAD" $SLACK_URL
exit 0