Xymon Mailing List Archive search

Monitoring Exchange

list Christoph Berg
Thu, 15 Oct 2009 12:12:42 +0200
Message-Id: <user-3c66f8c38def@xymon.invalid>

Re: Jacobs, Eric 2009-10-14 <user-02d1732f9915@xymon.invalid>
Apparently, last night our Exchange server stopped receiving email until
it was rebooted this morning. Everyone is up in arms. Hobbit showed
nothing unusual. Does anyone have any way to monitor Exchange? 
We've got some cronjob that sends mail to an Exchange account every 5
minutes and a simple perl script using Net::IMAP checking if the last
mail received is not older than some timeout. (Using Hobbit.pm from
the Debian package.)


#!/usr/bin/perl -w

use strict;
use Net::IMAP::Simple::SSL;
use Date::Parse;
use Hobbit;

my $bb = new Hobbit ({ hostname => 'smtp.xx.com', test => 'mailping'});

sub check_imap ($$$)
{
        my ($servername, $username, $password) = @_;
        my $server = new Net::IMAP::Simple::SSL ($servername);

        unless ($server->login ($username, $password)) {
                $bb->color_line ('red', "IMAP error: $servername: ". $server->errstr . "\n");
                return;
        }

        my $now = time ();
        my $max = 0;
        my $number_of_messages = $server->select ('INBOX');

        foreach my $msg ( 1..$number_of_messages ) {
                my $lines = join '', @{$server->get ($msg)};
                next unless $lines =~ /^Subject: ping (.*)/m;
                my $time = str2time ($1);
                $max = $time if $time > $max;
                if ($time < $now - 7200) {
                        $server-> delete ($msg);
                }
        }

        $server->quit();

        my $color;
        if ($max > $now - 400) {
                $color = 'green';
        } elsif ($max > $now - 700) {
                $color = 'yellow';
        } else {
                $color = 'red';
        }

        $bb->color_line ($color, "Last ping mail at $servername was received at ".scalar (localtime ($max)) ."\n");
}

check_imap ('imap.xx.com', 'hobbit', 'passwd');

$bb->send;


Christoph
-- 
user-92157dbc91bf@xymon.invalid | http://www.df7cb.de/