]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - flakes/private/monitoring/plugins/notify_by_slack
Squash changes containing private information
[perso/Immae/Config/Nix.git] / flakes / private / monitoring / plugins / notify_by_slack
diff --git a/flakes/private/monitoring/plugins/notify_by_slack b/flakes/private/monitoring/plugins/notify_by_slack
new file mode 100755 (executable)
index 0000000..1b16a0d
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+SLACK_CHANNEL="$1"
+SLACK_USERNAME="Naemon"
+SLACK_URL="$2"
+SLACK_USERICON="https://assets.immae.eu/monitoring.png"
+
+if [ "$SERVICESTATE" = "CRITICAL" ]; then
+  ICON=":exclamation:"
+  COLOR="#DA0505"
+elif [ "$SERVICESTATE" = "WARNING" ]; then
+  ICON=":warning:"
+  COLOR="#F1E903"
+elif [ "$SERVICESTATE" = "OK" ]; then
+  ICON=":white_check_mark:"
+  COLOR="#36a64f"
+elif [ "$SERVICESTATE" = "UNKNOWN" ]; then
+  ICON=":question:"
+  COLOR="#000000"
+else
+  ICON=":white_medium_square:"
+  COLOR="#ffffff"
+fi
+
+payload=$(echo "{}" | jq -r \
+  --arg "icon_url" "$SLACK_USERICON" \
+  --arg "channel"  "$SLACK_CHANNEL" \
+  --arg "username" "$SLACK_USERNAME" \
+  --arg "text" "${ICON} ${SERVICEDESC} on ${HOST} is ${SERVICESTATE}" \
+  --arg "color" "$COLOR" \
+  --arg "host" "$HOST" \
+  --arg "desc" "$SERVICEDESC" \
+  --arg "state" "$SERVICESTATE" \
+  --arg "output" "$SERVICEOUTPUT" \
+  '.icon_url = $icon_url |
+   .channel = $channel |
+   .username = $username |
+   .text = $text |
+   .attachments = [{fallback:"", color:$color,fields: [{},{},{},{}]}] |
+   .attachments[0].fields[0] = {title:"Host",value:$host,short:true} |
+   .attachments[0].fields[1] = {title:"Service description",value:$desc,short:true} |
+   .attachments[0].fields[2] = {title:"Status",value:$state,short:true} |
+   .attachments[0].fields[3] = {title:"Message",value:$output,short:false}
+   ')
+
+curl -X POST --data "payload=$payload" $SLACK_URL