]> git.michaelhowe.org Git - packages/n/nagios-plugins-local.git/commitdiff
New plugin to check that newaliases has run on /etc/aliases
authorMichael Howe <michael@michaelhowe.org>
Sat, 23 Dec 2023 14:03:16 +0000 (14:03 +0000)
committerMichael Howe <michael@michaelhowe.org>
Sat, 23 Dec 2023 14:03:16 +0000 (14:03 +0000)
debian/changelog
debian/nagios-plugins-local-client.install
plugins/check_newaliases [new file with mode: 0755]

index 36a71c9849dafb3a02efb16891574cb89b6f52f6..9c2dcae5c1532f67269da54283dc88c00a7c31ba 100644 (file)
@@ -1,3 +1,9 @@
+nagios-plugins-local (0.27) unstable; urgency=medium
+
+  * Add check_newaliases 
+
+ -- Michael Howe <michael@michaelhowe.org>  Sat, 23 Dec 2023 14:02:10 +0000
+
 nagios-plugins-local (0.26) unstable; urgency=medium
 
   * Remove check_running_kernel and associated overrides as the upstream
index f845d3628bae418739290c8bcfc24f64ba34ff87..ad375c1c2159d658862dc2fdc85240c3206099f4 100644 (file)
@@ -2,5 +2,6 @@
 /usr/lib/nagios/plugins/check_configtool
 /usr/lib/nagios/plugins/check_md_raid
 /usr/lib/nagios/plugins/check_monit
+/usr/lib/nagios/plugins/check_newaliases
 /usr/lib/nagios/plugins/check_iostat
 /usr/lib/nagios/plugins/check_systemd
diff --git a/plugins/check_newaliases b/plugins/check_newaliases
new file mode 100755 (executable)
index 0000000..c8396f2
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Simple script to check that /etc/aliases.db is newer than /etc/aliases for
+# systems that require the db file to exist.
+#
+# Possibly a slight race condition if you deploy /etc/aliases and run
+# newaliases within the same second, but this is highly unlikely.
+
+set -e
+set -u
+
+NEWALIASES=/usr/bin/newaliases
+REQUIRED_TARGET=/usr/sbin/sendmail
+
+ALIAS_FILE=/etc/aliases
+ALIASDB_FILE=${ALIAS_FILE}.db
+
+TARGET=$(readlink -f $NEWALIASES)
+
+if [ "$TARGET" != "$REQUIRED_TARGET" ]; then
+    echo "ALIASES OK - Looks like we're not running postfix (newaliases points to ${TARGET})"
+    exit
+fi
+
+ALIAS_TS=$(stat --format %Y $ALIAS_FILE)
+ALIASDB_TS=$(stat --format %Y $ALIASDB_FILE)
+
+sec=$((ALIASDB_TS - ALIAS_TS))
+
+if [ $sec > 0 ]; then
+    echo "ALIASES OK - aliases.db is ${sec}s newer than aliases"
+else
+    echo "ALIASES CRITICAL - aliases.db is ${sec}s older than aliases"
+    exit 2
+fi