root / plugins / mail / postgrey-new @ 430d68ff
Historique | Voir | Annoter | Télécharger (4,48 ko)
| 1 |
#! /usr/bin/perl |
|---|---|
| 2 |
################################################################### |
| 3 |
# Munins Plugin to monitor actions of postgrey greylisting daemon # |
| 4 |
# Version 0.1 # |
| 5 |
################################################################### |
| 6 |
|
| 7 |
######################### Configuration ########################### |
| 8 |
# Usually this plugin will look in /var/log/mail.log for the # |
| 9 |
# output of postgrey. You can change that by setting env.logfile # |
| 10 |
# The state file is /var/lib/munin/plugin-state/postgrey-new.state# |
| 11 |
# This can be changed by setting env.statefile # |
| 12 |
# Keep in mind to grant enough rigths in order to open the # |
| 13 |
# logfiles etc. # |
| 14 |
# Parameters understood by this plugin # |
| 15 |
# # |
| 16 |
# config (required) # |
| 17 |
# autoconf (optional) # |
| 18 |
# # |
| 19 |
################################################################### |
| 20 |
# This plgin works with postgrey 1.31 but should also do with 1.32# |
| 21 |
# Tested under Debian lenny # |
| 22 |
################################################################### |
| 23 |
|
| 24 |
|
| 25 |
### Author Rico Sagner hellriegel@sund-xplosion.de |
| 26 |
### Please send bug reports to this address |
| 27 |
|
| 28 |
use strict; |
| 29 |
use warnings; |
| 30 |
|
| 31 |
my $maillog= $ENV{'logfile'} || "/var/log/mail.log";
|
| 32 |
my $statefile= $ENV{'statefile'} || "/var/lib/munin/plugin-state/postgrey-new.state";
|
| 33 |
|
| 34 |
my $greylisted=0; |
| 35 |
my $greylisted_old=0; |
| 36 |
my $passes=0; |
| 37 |
my $passes_old=0; |
| 38 |
my $passes_white=0; |
| 39 |
my $passes_white_old=0; |
| 40 |
my $retry=0; |
| 41 |
my $retry_old=0; |
| 42 |
my $grey_new=0; |
| 43 |
my $pass_new=0; |
| 44 |
my $retry_new=0; |
| 45 |
my $passes_white_new=0; |
| 46 |
|
| 47 |
if(defined $ARGV[0] and $ARGV[0] eq "autoconf") {
|
| 48 |
if ( -f $maillog) {
|
| 49 |
print "yes\n"; |
| 50 |
exit 0; |
| 51 |
} |
| 52 |
else {
|
| 53 |
print "no\n"; |
| 54 |
exit 1 |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
if(defined $ARGV[0] and $ARGV[0] eq "config") {
|
| 60 |
print "graph_title Postgrey Actions\n"; |
| 61 |
print "graph_order greylisted retry_early passed passed_w\n"; |
| 62 |
print "graph_category mail\n"; |
| 63 |
print "graph_vlabel Count\n"; |
| 64 |
print "graph_scale no\n"; |
| 65 |
|
| 66 |
print "greylisted.label greylisted_reason_new\n"; |
| 67 |
print "greylisted.type GAUGE\n"; |
| 68 |
print "greylisted.draw AREA\n"; |
| 69 |
print "greylisted.min 0\n"; |
| 70 |
print "retry_early.label greylisted_retry_early\n"; |
| 71 |
print "retry_early.type GAUGE\n"; |
| 72 |
print "retry_early.draw AREA\n"; |
| 73 |
print "retry_early.min 0\n"; |
| 74 |
print "passed.label passed_found\n"; |
| 75 |
print "passed.type GAUGE\n"; |
| 76 |
print "passed.draw AREA\n"; |
| 77 |
print "passed.min 0\n"; |
| 78 |
print "passed_w.label passed_whitelisted\n"; |
| 79 |
print "passed_w.type GAUGE\n"; |
| 80 |
print "passed_w.draw AREA\n"; |
| 81 |
print "passed_w.min 0\n"; |
| 82 |
exit 0; |
| 83 |
} |
| 84 |
|
| 85 |
if( -f $statefile) {
|
| 86 |
open ( STATE ,"<$statefile"); |
| 87 |
defined($greylisted_old=<STATE>) or $greylisted_old=0; |
| 88 |
defined($passes_old=<STATE>) or $passes_old=0; |
| 89 |
defined($retry_old=<STATE>) or $retry_old=0; |
| 90 |
defined($passes_white_old=<STATE>) or $passes_white_old=0; |
| 91 |
chomp($greylisted_old); |
| 92 |
chomp($passes_old); |
| 93 |
chomp($retry_old); |
| 94 |
chomp($passes_white_old); |
| 95 |
close STATE; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
open (LOG ,"<$maillog") or die "Cannot open Maillog"; |
| 101 |
while(my $line = <LOG>) |
| 102 |
{
|
| 103 |
if($line=~m/postgrey\[/) |
| 104 |
{
|
| 105 |
if($line=~m/action=greylist/) {
|
| 106 |
if($line=~m/reason=new/) |
| 107 |
{
|
| 108 |
$greylisted++; |
| 109 |
} |
| 110 |
elsif($line=~m/reason=early-retry/) |
| 111 |
{
|
| 112 |
$retry++; |
| 113 |
} |
| 114 |
} |
| 115 |
elsif($line=~m/action=pass/) {
|
| 116 |
if($line=~m/reason=triplet/) |
| 117 |
{
|
| 118 |
$passes++; |
| 119 |
} |
| 120 |
elsif($line=~m/reason=client/) |
| 121 |
{
|
| 122 |
$passes_white++; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
} |
| 128 |
} |
| 129 |
close(LOG); |
| 130 |
|
| 131 |
|
| 132 |
open (STATE2,">$statefile"); |
| 133 |
print STATE2 "$greylisted\n"; |
| 134 |
print STATE2 "$passes\n"; |
| 135 |
print STATE2 "$retry\n"; |
| 136 |
print STATE2 "$passes_white\n"; |
| 137 |
close STATE2; |
| 138 |
|
| 139 |
if($greylisted_old>$greylisted) { $grey_new=$greylisted; }
|
| 140 |
elsif($greylisted_old eq $greylisted) { $grey_new=0;}
|
| 141 |
else { $grey_new=$greylisted-$greylisted_old; }
|
| 142 |
|
| 143 |
if($passes_old>$passes) { $pass_new=$passes;}
|
| 144 |
elsif( $passes_old eq $passes) { $pass_new=0; }
|
| 145 |
else { $pass_new=$passes-$passes_old; }
|
| 146 |
|
| 147 |
if($retry_old>$retry) { $retry_new=$retry;}
|
| 148 |
elsif($retry_old eq $retry) { $retry_new=0;}
|
| 149 |
else { $retry_new=$retry-$retry_old; }
|
| 150 |
|
| 151 |
if($passes_white_old>$passes_white) { $passes_white_new=$passes_white;}
|
| 152 |
elsif($passes_white_old eq $passes_white) { $passes_white_new=0;}
|
| 153 |
else { $passes_white_new=$passes_white-$passes_white_old; }
|
| 154 |
|
| 155 |
print "greylisted.value $grey_new\n"; |
| 156 |
print "retry_early.value $retry_new\n"; |
| 157 |
print "passed.value $pass_new\n"; |
| 158 |
print "passed_w.value $passes_white_new\n"; |
| 159 |
|
| 160 |
exit 0; |
