Skip to content
Snippets Groups Projects
Commit f3283ce6 authored by dario's avatar dario
Browse files

plugins: add check_mailman_qrunner_answers

sends an email to the ${listname}-request@${listsrv} address, and checks
if a sensible reply is sent back. requires mail server to deliver mail
to the given checker email address, one file per message, into a
directory (which is inotify-watched)
parent 5e84761e
Branches
No related tags found
No related merge requests found
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use Linux::Inotify2;
use Mail::Sendmail;
use Monitoring::Plugin;
use String::Random;
use Data::Dumper;
my $np = Monitoring::Plugin->new;
my %opts = ();
getopts('s:n:r:d:t:', \%opts);
defined $opts{'s'} and
defined $opts{'n'} and
defined $opts{'r'} and
defined $opts{'d'} and
defined $opts{'t'} or
$np->plugin_exit(UNKNOWN, "must give all parameters");
# random string to identify the reply by
my $r = String::Random->new;
my $ident = $r->randpattern("s" x 16);
my %mail = (
From => $opts{'r'},
To => "$opts{'n'}-request" . "@" . "$opts{'s'}",
Subject => $ident,
Body => "info",
);
sendmail(%mail) or $np->plugin_exit(UNKNOWN, "cannot send mail: $!");
# eval for sigalarm handling to implement timeout
eval {
# note: http://perldoc.perl.org/functions/alarm.html says the '\n'
# is required!
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $opts{'t'};
my $inotify = Linux::Inotify2->new or
$np->plugin_exit(UNKNOWN, "cannot create inotify watch");
$inotify->watch("$opts{'d'}", IN_CREATE | IN_CLOSE_WRITE | IN_MOVED_TO, sub {
my $e = shift;
my $p = MIME::Parser->new;
my $msg = $p->parse_open($e->fullname);
# make sure we haven't hit a bounce or something
unless (defined $msg->head->get('X-Mailman-Version') and
defined $msg->head->get('X-List-Administrivia')) {
$np->plugin_exit(WARNING, "answer not from mailman: " . $msg->head->get('Subject'));
}
# the original message is a MIME part of the response, so dig for it
for my $part ($msg->parts) {
my $b = $part->as_string;
if (index($b, "Subject: $ident") > -1) {
# found it, this is our reply
$np->plugin_exit(OK, "got reply");
}
}
}
);
while () {
$inotify->poll;
}
};
if ($@) {
die unless $@ eq "alarm\n"; # propagate different errors
# timeout
$np->plugin_exit(CRITICAL, "timeout receiving answer mail");
} else {
# no timeout (or other error), everything fine
# do i need to do anything here?
# just default exit cannot hurt i guess
$np->plugin_exit($np->check_messages);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment