X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_imap_connection;fp=modules%2Fprivate%2Fmonitoring%2Fplugins%2Fcheck_imap_connection;h=304eae6ea9b4f2efaf37456e150c2c6561bf9f02;hb=e820134d38c3b7470ea5112f40a6dc967f039878;hp=0000000000000000000000000000000000000000;hpb=b22ce4895ef1e9723a02061f7293e528cfbf9754;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/monitoring/plugins/check_imap_connection b/modules/private/monitoring/plugins/check_imap_connection new file mode 100755 index 0000000..304eae6 --- /dev/null +++ b/modules/private/monitoring/plugins/check_imap_connection @@ -0,0 +1,52 @@ +#!/usr/bin/env perl + +use strict; +use Getopt::Std; +$| = 1; + +my %opts; +getopts('h:u:p:H:', \%opts); + +my $STATE_OK = 0; +my $STATE_WARNING = 1; +my $STATE_CRITICAL = 2; +my $STATE_UNKNOWN = 3; + +if ($opts{'h'} || !$opts{'u'} || !$opts{'p'} || !$opts{'H'}) { + &print_help(); + exit($STATE_UNKNOWN); +} + +my $user = $opts{'u'}; +my $password = $opts{'p'}; +my $host = $opts{'H'}; + +my $cmd_result = `(echo "a login $user $password"; echo "b logout") | openssl s_client -quiet -ign_eof -connect $host -starttls imap 2>&1`; +my $expected_result = "a OK Logged in"; + +chomp($cmd_result); +if ($cmd_result !~ /$expected_result/) { + print "IMAP CRITICAL - Unable to connect via imaps\n"; + exit($STATE_CRITICAL); +} else { + print "IMAP OK - imaps connected successfully\n"; + exit($STATE_OK); +} + +sub print_help() { + print << "EOF"; +Check whether imap works via ssl and is able to connect its database. + +Options: +-h + Print detailed help screen +-u + User to log in as +-p + Password to log in +-H + Host to log in to + +EOF +} +