]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/profile/files/monitoring/check_date
Add monitoring for cryptoportfolio
[perso/Immae/Projets/Puppet.git] / modules / profile / files / monitoring / check_date
diff --git a/modules/profile/files/monitoring/check_date b/modules/profile/files/monitoring/check_date
new file mode 100644 (file)
index 0000000..e7ac38a
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+STATE_OK=0
+STATE_WARNING=1
+STATE_CRITICAL=2
+STATE_UNKNOWN=3
+  
+run_command="$1"
+hours="$2"
+as_user="$3"
+
+if [ -z "$as_user" ]; then
+  last_date=$($run_command 2>/dev/null | sort | tail -n 1)
+else
+  last_date=$(sudo -u "$as_user" $run_command 2>/dev/null | sort | tail -n 1)
+fi
+
+if [ -z "$last_date" ]; then
+  echo "UNKNOWN: Could not read date"
+  exit $STATE_UNKNOWN
+else
+  last_date=$(date -d "$last_date" "+%s")
+  LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
+  min_date=$(date -d "$hours hours ago" "+%s")
+  if [ "$min_date" -lt "$last_date" ]; then
+    echo "OK: Last date $(date -d @$last_date)"
+    exit $STATE_OK
+  else
+    echo "CRITICAL: Last date $(date -d @$last_date)"
+    exit $STATE_CRITICAL
+  fi
+fi