]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - flakes/private/monitoring/plugins/send_nrdp.sh
Squash changes containing private information
[perso/Immae/Config/Nix.git] / flakes / private / monitoring / plugins / send_nrdp.sh
diff --git a/flakes/private/monitoring/plugins/send_nrdp.sh b/flakes/private/monitoring/plugins/send_nrdp.sh
new file mode 100755 (executable)
index 0000000..c83c8cb
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+TEMPLATE='{
+  "cmd": "submitcheck",
+  "token": $token,
+  "checkresult": [{
+    "hostname": $hostname,
+    "state": $state,
+    "output": $output,
+    "type": $type,
+    "servicename": $servicename
+  }]
+}'
+
+while getopts "u:t:H:s:S:o:" option
+do
+  case $option in
+    u) url=$OPTARG ;;
+    t) token=$OPTARG ;;
+    H) hostname=$OPTARG ;;
+    s) servicename=$OPTARG ;;
+    S) state=$OPTARG ;;
+    o) output=$OPTARG ;;
+  esac
+done
+
+if [ -n "$servicename" ]; then
+  checktype="service"
+else
+  checktype="host"
+fi
+
+payload=$(jq -n \
+   --arg type "$checktype" \
+   --arg hostname "$hostname" \
+   --arg servicename "$servicename" \
+   --arg output "$output" \
+   --arg token "$token" \
+   --arg state "$state" \
+   "$TEMPLATE")
+
+rslt=$(curl -f --silent --insecure -d "$payload" -H "Content-Type: application/json" "$url")
+ret=$?
+
+if [ $ret != 0 ];then
+  echo "ERROR: could not connect to NRDP server at $url"
+  exit 1
+fi
+
+status=$(echo "$rslt" | jq -r .status)
+message=$(echo "$rslt" | jq -r .message)
+
+if [ "$status" != "ok" ];then
+  echo "ERROR: The NRDP Server said $message"
+  exit 2
+fi
+echo "Sent 1 checks to $url"