]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env bash | |
2 | ||
3 | SLACK_CHANNEL="$1" | |
4 | SLACK_USERNAME="Naemon" | |
5 | SLACK_URL="$2" | |
6 | SLACK_USERICON="https://release.immae.eu/monitoring.png" | |
7 | ||
8 | if [ "$SERVICESTATE" = "CRITICAL" ]; then | |
9 | ICON=":exclamation:" | |
10 | COLOR="#DA0505" | |
11 | elif [ "$SERVICESTATE" = "WARNING" ]; then | |
12 | ICON=":warning:" | |
13 | COLOR="#F1E903" | |
14 | elif [ "$SERVICESTATE" = "OK" ]; then | |
15 | ICON=":white_check_mark:" | |
16 | COLOR="#36a64f" | |
17 | elif [ "$SERVICESTATE" = "UNKNOWN" ]; then | |
18 | ICON=":question:" | |
19 | COLOR="#000000" | |
20 | else | |
21 | ICON=":white_medium_square:" | |
22 | COLOR="#ffffff" | |
23 | fi | |
24 | ||
25 | payload=$(echo "{}" | jq -r \ | |
26 | --arg "icon_url" "$SLACK_USERICON" \ | |
27 | --arg "channel" "$SLACK_CHANNEL" \ | |
28 | --arg "username" "$SLACK_USERNAME" \ | |
29 | --arg "text" "${ICON} ${SERVICEDESC} on ${HOST} is ${SERVICESTATE}" \ | |
30 | --arg "color" "$COLOR" \ | |
31 | --arg "host" "$HOST" \ | |
32 | --arg "desc" "$SERVICEDESC" \ | |
33 | --arg "state" "$SERVICESTATE" \ | |
34 | --arg "output" "$SERVICEOUTPUT" \ | |
35 | '.icon_url = $icon_url | | |
36 | .channel = $channel | | |
37 | .username = $username | | |
38 | .text = $text | | |
39 | .attachments = [{fallback:"", color:$color,fields: [{},{},{},{}]}] | | |
40 | .attachments[0].fields[0] = {title:"Host",value:$host,short:true} | | |
41 | .attachments[0].fields[1] = {title:"Service description",value:$desc,short:true} | | |
42 | .attachments[0].fields[2] = {title:"Status",value:$state,short:true} | | |
43 | .attachments[0].fields[3] = {title:"Message",value:$output,short:false} | |
44 | ') | |
45 | ||
46 | curl -X POST --data "payload=$payload" $SLACK_URL |