diff --git a/conf/munin/sa-learn-plugin b/conf/munin/sa-learn-plugin new file mode 100644 index 00000000..2b9c3437 --- /dev/null +++ b/conf/munin/sa-learn-plugin @@ -0,0 +1,76 @@ +#!/bin/bash +# https://github.com/munin-monitoring/contrib/blob/889e47197562485cf7e45eb30af160b697bbb95e/plugins/spamassasin/sa-learn + +: <<=cut +=head1 NAME + +sa-learn - Munin plugin to monitor spamassasin bayes database size + +=head1 APPLICABLE SYSTEMS + +Any server running spamassassin + +=head1 CONFIGURATION + +This plugin assumes your Spamassassin database is in /var/lib/MailScanner. +If it's elsewhere (or you want to use a different database) you will need +a configuration such as: + + [sa-learn] + env.BayesDir /path/to/bayes/directory/ + user mail + +(where 'user mail' refers to a user that can read the database). + +=head1 MAGIC MARKERS + +#%# family=contrib + +=head1 VERSION + +2 + +=head1 AUTHOR + +Paul Saunders L + +=cut +#' + +case $1 in + config) + cat <<'EOM' +graph_title SA-Learn Magic +graph_vlabel Count +graph_args --base 1000 -l 0 +graph_category Mail +spam.label Num Spam +spam.type GAUGE +ham.label Num Ham +ham.type GAUGE +tokens.label Num Tokens +tokens.type GAUGE +EOM + exit 0;; +esac + +## Print values +BayesDir=${BayesDir:-/var/lib/MailScanner} + +sa-learn --dbpath $BayesDir/ --dump magic 2>/dev/null | while read line +do + case "$line" in + *nspam*) + echo -n "spam.value " + echo $line | awk '{print $3}' + ;; + *nham*) + echo -n "ham.value " + echo $line | awk '{print $3}' + ;; + *ntokens*) + echo -n "tokens.value " + echo $line | awk '{print $3}' + ;; + esac +done diff --git a/conf/munin/sa-learn.conf b/conf/munin/sa-learn.conf new file mode 100644 index 00000000..7785087b --- /dev/null +++ b/conf/munin/sa-learn.conf @@ -0,0 +1,3 @@ +[sa-learn] +env.BayesDir ##BAYES_DIR## +user spampd diff --git a/conf/munin/sa-learn.patch b/conf/munin/sa-learn.patch new file mode 100644 index 00000000..6fc4c130 --- /dev/null +++ b/conf/munin/sa-learn.patch @@ -0,0 +1,11 @@ +--- sa-learn ++++ sa-learn +@@ -43,7 +43,7 @@ case $1 in + graph_title SA-Learn Magic + graph_vlabel Count + graph_args --base 1000 -l 0 +-graph_category Mail ++graph_category spamfilter + spam.label Num Spam + spam.type GAUGE + ham.label Num Ham \ No newline at end of file diff --git a/conf/munin/spamstats.conf b/conf/munin/spamstats.conf new file mode 100644 index 00000000..684d1a2f --- /dev/null +++ b/conf/munin/spamstats.conf @@ -0,0 +1,3 @@ +[spamstats] +group adm +env.logfile mail.log diff --git a/conf/munin/spamstats.patch b/conf/munin/spamstats.patch new file mode 100644 index 00000000..26e88ebc --- /dev/null +++ b/conf/munin/spamstats.patch @@ -0,0 +1,11 @@ +see https://github.com/munin-monitoring/munin/commit/7d163251667016cd7e4d6b4d188553312b8190c9#diff-052b0a943b0e9e24ce557d557ce2f318 +--- spamstats ++++ spamstats +@@ -55,6 +55,7 @@ + print "graph_title SpamAssassin throughput\n"; + print "graph_args --base 1000 -l 0\n"; + print "graph_vlabel mails/\${graph_period}\n"; ++ print "graph_category spamfilter\n"; + print "graph_order ham spam\n"; + print "ham.label ham\n"; + print "ham.type DERIVE\n"; \ No newline at end of file diff --git a/setup/munin.sh b/setup/munin.sh index 017862de..e1d0fc01 100755 --- a/setup/munin.sh +++ b/setup/munin.sh @@ -46,6 +46,22 @@ tools/editconf.py /etc/munin/munin-node.conf -s \ # Update the activated plugins through munin's autoconfiguration. munin-node-configure --shell --remove-also 2>/dev/null | sh || /bin/true +# Patch and enable spamstats plugin as it does not support autoconf +plugin_file=/usr/share/munin/plugins/spamstats +if ! grep -q "graph_category" "$plugin_file"; then + patch "$plugin_file" conf/munin/spamstats.patch +fi +cp conf/munin/spamstats.conf /etc/munin/plugin-conf.d/spamstats +ln -sf $plugin_file /etc/munin/plugins/spamstats + +# Add sa-learn plugin from munin contrib +BAYES_DIR="$STORAGE_ROOT/mail/spamassassin" +cp conf/munin/sa-learn-plugin /usr/share/munin/plugins/sa-learn +chmod +x /usr/share/munin/plugins/sa-learn +patch /usr/share/munin/plugins/sa-learn conf/munin/sa-learn.patch +sed -e "s|##BAYES_DIR##|$BAYES_DIR|g" conf/munin/sa-learn.conf > /etc/munin/plugin-conf.d/sa-learn +ln -sf /usr/share/munin/plugins/sa-learn /etc/munin/plugins/sa-learn + # Deactivate monitoring of NTP peers. Not sure why anyone would want to monitor a NTP peer. The addresses seem to change # (which is taken care of my munin-node-configure, but only when we re-run it.) find /etc/munin/plugins/ -lname /usr/share/munin/plugins/ntp_ -print0 | xargs -0 /bin/rm -f