Nagios, Mailgraph, check_logfile

zur Statistischen Erfassung war auf dem alten Mailserver “mailgraph” installiert. Das Problem für mich war, das ich die Daten nicht brauchbar ins Nagios bekommen habe (check_rrd etc).
Die Lösung: Das Maillog mit check_logfile parsen und das Ergebniss als Performance Daten für Nagios ausgeben.

Aufruf von check_logfile in der nrpe.cfg:

1
command[check_mailflow]=sudo /usr/lib/nagios/plugins/check_logfiles -f /etc/nagios-plugins/config/logfile.cfg

In der logfile.cfg sind die Parser für

  • recive – Mail an den Exchange weitergeleitet
  • bounce – allgemeine Bounces
  • block – durch RBL geblocke Mails
  • block-nouser – wegen ungültiger Benutzer geblockte Mail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
our $sendcount = 0;
our $bouncecount = 0;
our $blockcount = 0;
our $nousercount = 0;


@searches = ({
        tag => 'postfix',
        logfile => '/var/log/mail.log',
        rotation => 'loglogdate8gz',
        options => 'supersmartscript,noprotocol,supersmartpostscript',
        criticalpatterns => '.*',
        script => sub {

                if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\bstatus=sent\b/){
                        if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} !~ /\brelay=[^\s\[]*\[127\.0\.0\.1\]/  ){
                                $sendcount++;
                        }
                }


                if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\bstatus=bounced\b/) {
                        $bouncecount++;

                }


                if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\b.*NOQUEUE: .*reject: .*: 554.* blocked using\b/) {
                        $blockcount++;

                }

                if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\b.*NOQUEUE: .*reject: .*: 550.* Recipient address rejected\b/) {
                        $nousercount++;

                }

        },

});
$options = 'supersmartpostscript';

$postscript = sub {
        my $tic = $CHECK_LOGFILES_PRIVATESTATE->{postfix}->{lastruntime} || 0;
        my $tac = time;
        my $runtime = ($tac - $tic);


        my $sendrate = 60 * ( $sendcount / $runtime );

        printf "OK - recive: %.1f bounce: %.1f block: %.1f block-nouser: %.1f | recive=%.1f;bounce=%.1f;block=%.1f;block-nouser=%.1f\n", $sendra
te, $bouncecount, $blockcount, $nousercount, $sendrate, $bouncecount, $blockcount, $nousercount;

        return 0;
Dieser Artikel wurde in der Kategorie Linux, Nagios veröffentlicht. Den Permalink als Lesezeichen speichern.