Add script to monitor spamassassin's bayes database stats

tags/zabbix-agent-addons-0.2.22-1
Daniel Berteaud 6 years ago
parent 7b6c8bd1d5
commit 98c9297292
  1. 13
      zabbix_conf/sa_learn.conf
  2. 46
      zabbix_scripts/check_sa_learn_sudo

@ -0,0 +1,13 @@
# Description: SA Learn statistics
# Type: Agent or Agent (active)
# Key: mail.bayes
# Type of information: Text
# Units: N/A
# Custom multiplier: Do not use
# Store Value: As is
# This is a master item which must then be splited with preprocessing (Zabbix >= 3.4.0)
UserParameter=mail.bayes.all,/usr/bin/sudo /var/lib/zabbix/bin/check_sa_learn_sudo
# Or you can use individual items. Valid arg are ham, spam and token
UserParameter=mail.bayes[*],/usr/bin/sudo /var/lib/zabbix/bin/check_sa_learn_sudo --what=$1

@ -0,0 +1,46 @@
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
use Getopt::Long;
use File::Spec;
open STDERR, '>', File::Spec->devnull() or die "could not open STDERR: $!\n";
my $what = 'all';
GetOptions(
"what=s" => \$what
);
my @salearn = qx(sa-learn --dump magic);
my $data = {
spam => 0,
ham => 0,
token => 0
};
foreach my $line (@salearn){
if ($line =~ m/(\d+)\s*0\s*non-token\sdata:\snspam$/){
$data->{spam} = $1;
}
elsif ($line =~ m/(\d+)\s*0\s*non-token\sdata:\snham$/){
$data->{ham} = $1;
}
elsif ($line =~ m/(\d+)\s*0\s*non-token\sdata:\sntokens$/){
$data->{token} = $1;
}
}
if ($what eq 'spam'){
print $data->{spam} . "\n";
}
elsif ($what eq 'ham'){
print $data->{ham} . "\n";
}
elsif ($what eq 'token'){
print $data->{token} . "\n";
}
else{
print to_json($data);
}
exit(0);
Loading…
Cancel
Save