Am 10.07.2013 10:59, schrieb lluis:
Hello,
I'm using a nagios check to monitor dovecot status, since dovecot v2 I
see those syslog messages on every nagios check:

pop3-login: Aborted login (no auth attempts in 0 secs)
imap-login: Aborted login (no auth attempts in 0 secs)

I tried to avoid those messages sending a logout string:

check_imap -H localhost -e 'OK' -s 'a logout'
check_pop -H localhost -e 'OK' -s 'quit'

but now I get

imap-login: Disconnected (no auth attempts in 0 secs)
pop3-login: Disconnected (no auth attempts in 0 secs)

what can I do to avoid a log message on every nagios check?

Just do a complete login/logout sequence.
I have developed some perl scripts to do so.

This is fine for the nagios checks, but we are facing similar
problems with our loadbalancer, which is just doing TCP Healthchecks
on the IMAP/POP3/SIEVE ports, so being able to disable the warning
for trusted networks would be really helpful.

Regards
Daniel
--
Dipl.-Inf. Daniel Parthey
System Engineer
Metaways Infosystems GmbH
Pickhuben 2, D-20457 Hamburg

E-Mail: [email protected]
Web:    http://www.metaways.de
Tel:    +49 (0)40 317031-537
Fax:    +49 (0)40 317031-937

Metaways Infosystems GmbH - Sitz: D-22967 Tremsbüttel
Handelsregister: Amtsgericht Lübeck HRB 4508 AH
Geschäftsführung: Hermann Thaele, Lüder-H.Thaele
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Net::IMAP::Simple;
use Time::HiRes;

my $PROGNAME = "check_imap_login";
my $TIMEOUT  = 120;

my ($imap,$output,$status,$return);

my $options = {
    'globaltimeout' => 180,
    'port'          => '143',
    'timeout'       => 30,
    'warning'       => 30,
    'critical'      => 30
};

my $ERRORS = {
    'OK'        => 0,
    'WARNING'   => 1,
    'CRITICAL'  => 2,
    'UNKNOWN'   => 3,
    'DEPENDENT' => 4
};

my $state = 'UNKNOWN';

# close IMAP connection, print result and exit
sub nsexit {
    $imap->quit() if ($imap);
    my ($msg,$code) = @_;
    $code=$state if (!defined $code);
    print "IMAP $code: $msg\n" if (defined $msg);
    exit $ERRORS->{$code};
}

# Show verbose help screen
sub print_help() {
    print "$PROGNAME - (c) 2008-2011 Daniel Parthey <d.parthey\@metaways.de>\n";
    print "This program is licensed under the terms of the GNU GPLv2\n";
    print "\n";
    print "Checks login to an IMAP email account\n";
    print "\n";
    print "Usage: \n";
    print " $PROGNAME -h host -u user -p password [-P port] [-t secs]\n";
    print " $PROGNAME [-h | --help]\n";
    print "\n";
    print "    --help                 This help text\n";
    print " -h|--hostname <hostname>  Hostname or IP address of POP3 server\n";
    print " -P|--port     <port>      Port number of POP3 server (optional)\n";
    print " -u|--username <username>  Username of POP3 mailbox account\n";
    print " -p|--password <password>  Password of POP3 mailbox account\n";
    print " -t|--timeout  <timeout>   Number of seconds until login attempt 
times out\n";
    print " -w|--warning  <seconds>   Warn if login lasts more than number of 
seconds\n";
    print " -c|--critical <seconds>   Critical if login lasts more than number 
of seconds\n";
    exit $ERRORS->{'UNKNOWN'};
};

# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
     print ("ERROR: $0 Time-Out $TIMEOUT s \n");
     exit $ERRORS->{'UNKNOWN'};
};
alarm($TIMEOUT);

# Evaluate Command Line Parameters
Getopt::Long::Configure('no_ignore_case');
my $getopt = GetOptions(
    'help' => \$options->{'help'},
    "h=s"  => \$options->{'hostname'}, "hostname=s" => \$options->{'hostname'},
    "u=s"  => \$options->{'username'}, "username=s" => \$options->{'username'},
    "p=s"  => \$options->{'password'}, "password=s" => \$options->{'password'},
    "P=s"  => \$options->{'port'},     "port=s"     => \$options->{'port'},
    "t=i"  => \$options->{'timeout'},  "timeout=i"  => \$options->{'timeout'},
    "w=i"  => \$options->{'warning'},  "warning=i"  => \$options->{'warning'},
    "c=i"  => \$options->{'critical'}, "critical=i" => \$options->{'critical'}
);

if (!$getopt)                { print_help() };
if (!$options->{'hostname'}) { print "hostname missing\n"; print_help(); };
if (!$options->{'username'}) { print "username missing\n"; print_help(); };
if (!defined($options->{'password'}))
{
    print "password missing\n";
    print_help();
}

my $starttime = Time::HiRes::time();
$imap = Net::IMAP::Simple->new(
    $options->{'hostname'},
    port    => $options->{'port'},
    timeout => $options->{'timeout'}
);

if (!defined($imap))
{
    nsexit(
        "No IMAP banner found on $options->{'hostname'}:$options->{'port'}", 
'CRITICAL'
    );
}

my $login_success = $imap->login(
    $options->{'username'},
    $options->{'password'}
);
if (!defined($login_success))
{
    nsexit("Login failed for user $options->{'username'}",'CRITICAL');
}

my $msgcount = $imap->select();

if (!defined($msgcount))
{
    nsexit("Could not select INBOX: ".$imap->errstr(),'CRITICAL');
}

my $endtime = Time::HiRes::time();
my $duration = $endtime-$starttime;
my $rounded_duration = sprintf("%.1f", $duration);

if ($rounded_duration > $options->{'critical'})
{
    nsexit("Login time of ${rounded_duration}s exceeds critical limit of 
$options->{'critical'} seconds",'CRITICAL'); 
}

if ($rounded_duration > $options->{'warning'})
{
    nsexit("Login time of ${rounded_duration}s exceeds warning limit of 
$options->{'warning'} seconds",'WARNING'); 
}

$state = 'OK';
nsexit(int($msgcount)." mails after $rounded_duration seconds", $state);
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Net::POP3;
use Time::HiRes;

my $PROGNAME = "check_pop3_login";
my $TIMEOUT  = 120;

my ($pop,$output,$status,$return);

my $options = {
    'globaltimeout' => 180,
    'port'          => '110',
    'timeout'       => 30,
    'warning'       => 30,
    'critical'      => 30
};

my $ERRORS = {
    'OK'        => 0,
    'WARNING'   => 1,
    'CRITICAL'  => 2,
    'UNKNOWN'   => 3,
    'DEPENDENT' => 4
};

my $state = 'UNKNOWN';

# close POP3 connection, print result and exit
sub nsexit {
    $pop->quit() if ($pop);
    my ($msg,$code) = @_;
    $code=$state if (!defined $code);
    print "POP3 $code: $msg\n" if (defined $msg);
    exit $ERRORS->{$code};
}

# Show verbose help screen
sub print_help() {
    print "$PROGNAME - (c) 2008-2011 Daniel Parthey <d.parthey\@metaways.de>\n";
    print "This program is licensed under the terms of the GNU GPLv2\n";
    print "\n";
    print "Checks login to a POP3 email account\n";
    print "\n";
    print "Usage: \n";
    print " $PROGNAME -h host -u user -p password [-P port] [-t secs]\n";
    print " $PROGNAME [-h | --help]\n";
    print "\n";
    print "    --help                 This help text\n";
    print " -h|--hostname <hostname>  Hostname or IP address of POP3 server\n";
    print " -P|--port     <port>      Port number of POP3 server (optional)\n";
    print " -u|--username <username>  Username of POP3 mailbox account\n";
    print " -p|--password <password>  Password of POP3 mailbox account\n";
    print " -t|--timeout  <timeout>   Number of seconds until login attempt 
times out\n";
    print " -w|--warning  <seconds>   Warn if login lasts more than number of 
seconds\n";
    print " -c|--critical <seconds>   Critical if login lasts more than number 
of seconds\n";
    exit $ERRORS->{'UNKNOWN'};
};

# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
     print ("ERROR: $0 Time-Out $TIMEOUT s \n");
     exit $ERRORS->{'UNKNOWN'};
};
alarm($TIMEOUT);

# Evaluate Command Line Parameters
Getopt::Long::Configure('no_ignore_case');
my $getopt = GetOptions(
    'help' => \$options->{'help'},
    "h=s"  => \$options->{'hostname'}, "hostname=s" => \$options->{'hostname'},
    "u=s"  => \$options->{'username'}, "username=s" => \$options->{'username'},
    "p=s"  => \$options->{'password'}, "password=s" => \$options->{'password'},
    "P=s"  => \$options->{'port'},     "port=s"     => \$options->{'port'},
    "t=i"  => \$options->{'timeout'},  "timeout=i"  => \$options->{'timeout'},
    "w=i"  => \$options->{'warning'},  "warning=i"  => \$options->{'warning'},
    "c=i"  => \$options->{'critical'}, "critical=i" => \$options->{'critical'}
);

if (!$getopt)                { print_help() };
if (!$options->{'hostname'}) { print "hostname missing\n"; print_help(); };
if (!$options->{'username'}) { print "username missing\n"; print_help(); };
if (!defined($options->{'password'}))
{
    print "password missing\n";
    print_help();
}

my $starttime = Time::HiRes::time();
$pop = Net::POP3->new(
    Host    => "$options->{'hostname'}:$options->{'port'}",
    Timeout => $options->{'timeout'}
);

if (!defined($pop))
{
    nsexit(
        "No POP3 banner found on $options->{'hostname'}:$options->{'port'}", 
'CRITICAL'
    );
}

my $msgcount = $pop->login(
    $options->{'username'},
    $options->{'password'}
);
if (!defined($msgcount))
{
    nsexit("Login failed for user $options->{'username'}",'CRITICAL');
}

my $endtime = Time::HiRes::time();
my $duration = $endtime-$starttime;
my $rounded_duration = sprintf("%.1f", $duration);

if ($rounded_duration > $options->{'critical'})
{
    nsexit("Login time of ${rounded_duration}s exceeds critical limit of 
$options->{'critical'} seconds",'CRITICAL'); 
}

if ($rounded_duration > $options->{'warning'})
{
    nsexit("Login time of ${rounded_duration}s exceeds warning limit of 
$options->{'warning'} seconds",'WARNING'); 
}

$state = 'OK';
nsexit(int($msgcount)." mails after $rounded_duration seconds", $state);
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Net::ManageSieve;
use Time::HiRes;

my $PROGNAME = "check_sieve_login";
my $TIMEOUT  = 120;

my ($sieve,$output,$status,$return);

my $options = {
    'globaltimeout' => 180,
    'port'          => '4190',
    'timeout'       => 30,
    'warning'       => 30,
    'critical'      => 30
};

my $ERRORS = {
    'OK'        => 0,
    'WARNING'   => 1,
    'CRITICAL'  => 2,
    'UNKNOWN'   => 3,
    'DEPENDENT' => 4
};

my $state = 'UNKNOWN';

# close MANAGESIEVE connection, print result and exit
sub nsexit {
    $sieve->logout() if ($sieve);
    my ($msg,$code) = @_;
    $code=$state if (!defined $code);
    print "SIEVE $code: $msg\n" if (defined $msg);
    exit $ERRORS->{$code};
}

# Show verbose help screen
sub print_help() {
    print "$PROGNAME - (c) 2012-2012 Daniel Parthey <d.parthey\@metaways.de>\n";
    print "This program is licensed under the terms of the GNU GPLv2\n";
    print "\n";
    print "Checks login to a MANAGESIEVE account\n";
    print "\n";
    print "Usage: \n";
    print " $PROGNAME -h host -u user -p password [-P port] [-t secs]\n";
    print " $PROGNAME [-h | --help]\n";
    print "\n";
    print "    --help                 This help text\n";
    print " -h|--hostname <hostname>  Hostname or IP address of POP3 server\n";
    print " -P|--port     <port>      Port number of POP3 server (optional)\n";
    print " -u|--username <username>  Username of POP3 mailbox account\n";
    print " -p|--password <password>  Password of POP3 mailbox account\n";
    print " -t|--timeout  <timeout>   Number of seconds until login attempt 
times out\n";
    print " -w|--warning  <seconds>   Warn if login lasts more than number of 
seconds\n";
    print " -c|--critical <seconds>   Critical if login lasts more than number 
of seconds\n";
    exit $ERRORS->{'UNKNOWN'};
};

# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
     print ("ERROR: $0 Time-Out $TIMEOUT s \n");
     exit $ERRORS->{'UNKNOWN'};
};
alarm($TIMEOUT);

# Evaluate Command Line Parameters
Getopt::Long::Configure('no_ignore_case');
my $getopt = GetOptions(
    'help' => \$options->{'help'},
    "h=s"  => \$options->{'hostname'}, "hostname=s" => \$options->{'hostname'},
    "u=s"  => \$options->{'username'}, "username=s" => \$options->{'username'},
    "p=s"  => \$options->{'password'}, "password=s" => \$options->{'password'},
    "P=s"  => \$options->{'port'},     "port=s"     => \$options->{'port'},
    "t=i"  => \$options->{'timeout'},  "timeout=i"  => \$options->{'timeout'},
    "w=i"  => \$options->{'warning'},  "warning=i"  => \$options->{'warning'},
    "c=i"  => \$options->{'critical'}, "critical=i" => \$options->{'critical'}
);

if (!$getopt)                { print_help() };
if (!$options->{'hostname'}) { print "hostname missing\n"; print_help(); };
if (!$options->{'username'}) { print "username missing\n"; print_help(); };
if (!defined($options->{'password'}))
{
    print "password missing\n";
    print_help();
}

my $starttime = Time::HiRes::time();
$sieve = Net::ManageSieve->new(
    Debug   => 0,
    Host    => $options->{'hostname'},
    Port    => $options->{'port'},
    Timeout => $options->{'timeout'}
);

if (!defined($sieve))
{
    nsexit(
        "No MANAGESIEVE banner found on 
$options->{'hostname'}:$options->{'port'}", 'CRITICAL'
    );
}

my $login_success = $sieve->login(
    $options->{'username'},
    $options->{'password'}
);
if (!defined($login_success))
{
    nsexit("Login failed for user $options->{'username'}",'CRITICAL');
}

my $scripts;
$scripts = $sieve->listscripts();

if (!$scripts)
{
    nsexit("Could not list sieve scripts",'CRITICAL');
}

my $endtime = Time::HiRes::time();
my $duration = $endtime-$starttime;
my $rounded_duration = sprintf("%.1f", $duration);

if ($rounded_duration > $options->{'critical'})
{
    nsexit("Login time of ${rounded_duration}s exceeds critical limit of 
$options->{'critical'} seconds",'CRITICAL'); 
}

if ($rounded_duration > $options->{'warning'})
{
    nsexit("Login time of ${rounded_duration}s exceeds warning limit of 
$options->{'warning'} seconds",'WARNING'); 
}

$state = 'OK';
nsexit(scalar(@$scripts)." scripts listed after $rounded_duration seconds", 
$state);

Reply via email to