# We run this cronjob along with sending the test email every 5 minutes,
# so give it 1 minute to arrive, then if the latest email is older than
# 7 minutes, the last 2 haven't arrived in a reasonable amount of time.
-min_limit=7
+# However, when machines reboot things can get delayed, so add 10 mins,
+# not sure if that is a good number or not.
+min_limit=17
# spamassassin checking takes about 8 seconds. only do that every
#Nov 8 08:16:05.439 [6080] warn: plugin: failed to parse plugin (from @INC): Can't locate Mail/SpamAssassin/Plugin/VBounce.pm: lib/Mail/SpamAssassin/Plugin/VBounce.pm: Permission denied at (eval 60) line 1.
# i dont know why, i just found the solution online
cd /m/md
+# TODO, get je to deliver the local mailbox: /m/md/INBOX
+# dovecot appears to setup, i can t be sure.
case $HOSTNAME in
bk)
getspamdpid() {
if [[ ! $spamdpid || ! -d /proc/$spamdpid ]]; then
- spamdpid=$(systemctl show --property MainPID --value spamassassin | sed 's/^1$//' ||:)
+ # try twice in case we are restarting, it happens.
+ for i in 1 2; do
+ spamdpid=$(systemctl show --property MainPID --value spamassassin | sed 's/^[10]$//' ||:)
+ if [[ $spamdpid ]]; then
+ break
+ fi
+ sleep 30
+ done
fi
}
getspamdpid
pr() {
- cat >>/var/lib/prometheus/node-exporter/mailtest-check.prom.$$
+ if [[ -e /var/lib/prometheus/node-exporter ]]; then
+ cat >>/var/lib/prometheus/node-exporter/mailtest-check.prom.$$
+ fi
}
-pr <<EOF
+# first time we write, overwrite anything existing
+if [[ -e /var/lib/prometheus/node-exporter ]]; then
+ cat >/var/lib/prometheus/node-exporter/mailtest-check.prom.$$ <<EOF
mailtest_check_found_spamd_pid_bool $(( ${spamdpid:-0} > 0 ))
EOF
+fi
e spamdpid: $spamdpid
if [[ ! $spamdpid ]]; then
echo $HOSTNAME mailtest spamd pid not found. systemctl status spamassassin:
# servers.
# example line that sed is parsing:
# (-0.1 / 5.0 requ) DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,SPF_HELO_PASS=-0.001,SPF_PASS=-0.001,TVD_SPACE_RATIO=0.001 autolearn=_AUTOLEARN
- for r in $($spamcpre sudo -u Debian-exim spamassassin -t --cf='score PYZOR_CHECK 0' <"$latest" | tail -n2 | head -n1 | sed -r 's/^\([^)]*\) *//;s/=[^, ]*([, ]|$)/ /g'); do
+ raw_results="$($spamcpre sudo -u Debian-exim spamassassin -t --cf='score PYZOR_CHECK 0' <"$latest" | tail -n2 | head -n1 | sed -r 's/^\([^)]*\) *//;s/=[^, ]*([, ]|$)/ /g')"
+ for r in $raw_results; do
case $r in
# got this in an update 2022-01. dun care
T_SCC_BODY_TEXT_LINE|SCC_BODY_SINGLE_WORD) : ;;
fi # if $slow
fi # if [[ $latest ]]
- now=$(date +%s)
+ now=$EPOCHSECONDS
limit=$(( now - 60 * min_limit ))
age_sec=$(( now - last_sec ))
e $((age_sec / 60)):$(( age_sec % 60 )) ago. to:$to from:$from $latest
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
+
+dir=/var/lib/prometheus/node-exporter
+if [[ -e $dir ]]; then
+ mv $dir/mailtest-check.prom.$$ $dir/mailtest-check.prom
+fi