1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-12-24 07:37:04 +00:00

munin: patch and enable spamstats plugin,

patch and add sa-learn plugin
This commit is contained in:
glaszig 2018-10-15 06:01:22 +02:00
parent 6eb9055275
commit 95ecc22922
6 changed files with 120 additions and 0 deletions

View File

@ -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<darac+munin@darac.org.uk>
=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

3
conf/munin/sa-learn.conf Normal file
View File

@ -0,0 +1,3 @@
[sa-learn]
env.BayesDir ##BAYES_DIR##
user spampd

11
conf/munin/sa-learn.patch Normal file
View File

@ -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

View File

@ -0,0 +1,3 @@
[spamstats]
group adm
env.logfile mail.log

View File

@ -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";

View File

@ -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
# 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