diff --git a/plugins/check_mailman_qrunner_answers b/plugins/check_mailman_qrunner_answers new file mode 100755 index 0000000000000000000000000000000000000000..f78eb854052513fbd27882ffff7de2d70bc31c03 --- /dev/null +++ b/plugins/check_mailman_qrunner_answers @@ -0,0 +1,80 @@ +#!/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); +}