]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/monitoring/plugins/notify_by_apprise
Move notification systems to apprise
[perso/Immae/Config/Nix.git] / modules / private / monitoring / plugins / notify_by_apprise
diff --git a/modules/private/monitoring/plugins/notify_by_apprise b/modules/private/monitoring/plugins/notify_by_apprise
new file mode 100755 (executable)
index 0000000..82bc5a3
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+APPRISE_USERNAME="Naemon"
+APPRISE_USERICON="https://assets.immae.eu/monitoring.png"
+APPRISE_URLS=$(echo "$2" | sed -e "s/{username}/$APPRISE_USERNAME/g" -e "s@{image_url}@$APPRISE_USERICON@g")
+
+if [ "$SERVICESTATE" = "CRITICAL" ]; then
+  ICON="❗"
+elif [ "$SERVICESTATE" = "WARNING" ]; then
+  ICON="⚠️:"
+elif [ "$SERVICESTATE" = "OK" ]; then
+  ICON="✅"
+elif [ "$SERVICESTATE" = "UNKNOWN" ]; then
+  ICON="❓"
+elif [ "$HOSTSTATE" = "UP" ]; then
+  ICON="✅"
+elif [ "$HOSTSTATE" = "DOWN" ]; then
+  ICON="❗"
+elif [ "$HOSTSTATE" = "UNKNOWN" ]; then
+  ICON="❓"
+elif [ "$HOSTSTATE" = "UNREACHABLE" ]; then
+  ICON="❓"
+else
+  ICON="◻"
+fi
+
+if [ "$1" = "host" ]; then
+  apprise --title "${ICON} ${NOTIFICATIONTYPE} ${HOST} is ${HOSTSTATE}" --body "$HOSTOUTPUT" $APPRISE_URLS
+else
+  apprise --title "${ICON} ${NOTIFICATIONTYPE} ${SERVICEDESC} on ${HOST} is ${SERVICESTATE}" --body "$SERVICEOUTPUT" $APPRISE_URLS
+fi