mostly start using prometheus
[distro-setup] / mailtest-check
index cd12bc7b3738ff47d775d27ec9f444974d6d2359..81363012fc0b3de90f64b47ee3213caaa4a21256 100755 (executable)
@@ -69,22 +69,30 @@ case $HOSTNAME in
     folders=(/m/md/l/testignore)
     froms=(testignore@je.b8.nz testignore@expertpathologyreview.com testignore@amnimal.ninja ian@iankelling.org z@zroe.org iank@gnu.org)
     if ! $int; then
-      timeout 120 rsync -e "ssh -oIdentitiesOnly=yes -F /dev/null -i /root/.ssh/jtuttle" -t --inplace -r 'jtuttle@fencepost.gnu.org:/home/j/jtuttle/Maildir/new/' /m/md/l/testignore/new
+      timeout 120 rsync --chown iank:iank -e "ssh -oIdentitiesOnly=yes -F /dev/null -i /root/.ssh/jtuttle" -t --inplace -r 'jtuttle@fencepost.gnu.org:/home/j/jtuttle/Maildir/new/' /m/md/l/testignore/new
     fi
     ;;
 esac
 
 getspamdpid() {
   if [[ ! $spamdpid || ! -d /proc/$spamdpid ]]; then
-    spamdpid=$(systemctl status spamassassin| sed -n '/^ *Main PID:/s/[^0-9]//gp')
+    spamdpid=$(systemctl show --property MainPID --value spamassassin | sed 's/^1$//' ||:)
   fi
 }
 getspamdpid
+pr() {
+  cat >>/var/lib/prometheus/node-exporter/mailtest-check.prom.$$
+}
+pr <<EOF
+mailtest_check_found_spamd_pid_bool $(( ${spamdpid:-0} > 0 ))
+EOF
 e spamdpid: $spamdpid
 if [[ ! $spamdpid ]]; then
-  echo $HOSTNAME mailtest spamd pid not found
+  echo $HOSTNAME mailtest spamd pid not found. systemctl status spamassassin:
+  systemctl status spamassassin
 fi
 tmpfile=$(mktemp)
+declare -i unexpected=0
 for folder in ${folders[@]}; do
   for from in ${froms[@]}; do
     latest=
@@ -101,7 +109,10 @@ for folder in ${folders[@]}; do
       fi
     done <$tmpfile
 
-    if [[ $latest ]]; then
+    if [[ ! $latest ]]; then
+      # 10 is an arbitrary bad value
+      unexpected+=10
+    else
       to=$(awk '/^Envelope-to: / {print $2}' $latest)
       last_sec=$(awk '/^Subject: / {print $4}' $latest)
 
@@ -195,5 +206,15 @@ for folder in ${folders[@]}; do
     if (( last_sec <= limit )); then
       echo $HOSTNAME mailtest $folder $from $(date -d @$last_sec +'%a %m-%d %H:%M')
     fi
+    # usec = unix seconds
+    pr <<EOF
+mailtest_check_last_usec{folder="$folder",from="$from"} $last_sec
+EOF
   done
 done
+if $slow; then
+  pr <<EOF
+mailtest_check_unexpected_spamd_results $unexpected
+EOF
+fi
+mv /var/lib/prometheus/node-exporter/mailtest-check.prom.$$ /var/lib/prometheus/node-exporter/mailtest-check.prom