How to Install

  1. copy the 3 scripts from the download package into your Nagios libexec folder
  2. configure your email service checks

Complete Reference

Usage Notes

Users with ePN should use the ePN versions of the scripts. Look for check_smtp_send_epn, check_imap_receive_epn, and check_email_delivery_epn in the download package. Substitute these epn versions wherever you see the regular script names in the examples. No other change is needed.

check_email_delivery runs other plugins to create the email loop. If any of those exits with a CRITICAL status, then check_email_delivery will also exit with CRITICAL. If all return OK or WARNING, then check_email_delivery continues the check and uses threshold options to decide whether to return OK or WARNING.

As of version 0.5, any plugins can be used to create the loop by using the --plugin option. The possibilities are pretty exciting. For example, you can check the function of an email-to-ftp gateway: use check_smtp_send to send the email, and then use an ftp plugin to check that the file is accessible by ftp. You can also use other plugins.

The new --token option automatically creates random numbers or strings to be passed to all specified plugins in order to link their operation, so that you can send an email with a random string like "aardvark 23429" using check_smtp_send and then look for this specific string to be found in the mailbox using check_imap_receive.

As of version 0.6, there is an --alert option that you can use in conjunction with the --plugin option. This new --alert option is useful if your delivery loop involves more than one server and you happen to only be interested in the status of just one of the servers.

How do you send attachments or other special messages? Currently there is no built-in way but you can use the --stdin option to send a prepared message (with attachments). So send yourself the message you want to use for testing, then use your mail client's "view raw message" feature, copy & paste the raw message body to a text file on your nagios server. Configure check_smtp_send like this: cat saved_message.txt | check_smtp_send --stdin [other options here].

Troubleshooting

EMAIL DELIVERY UNKNOWN - imap unknown: Missing perl modules: Mail::IMAPClient
This might happen to you even if you have Mail::IMAPClient installed on your system. Check the file permissions on your Mail::IMAPClient files in @INC to make sure nagios can access them. The user who had this problem said he solved it by changing the permissions ... so it wasn't really a problem with this plugin.
The plugin fails with UNKNOWN status code and I don't see a message in the Nagios website, or I see "no output!"
Try running the plugin from the command line to see if there is an error message that you're not seeing in the Nagios web interface. If anyone knows how to get status messages to show up on the web interface when using UNKNOWN status code, please let me know. This issue may be fixed in newer versions of Nagios.
Argument " " isn't numeric in numeric eq (==) at /Library/Perl/5.8.8/Net/SMTP/TLS.pm line 396, <GEN0> line 9.
Use of uninitialized value in concatenation (.) or string at /Library/Perl/5.8.8/Net/SMTP/TLS.pm line 397, <GEN0> line 9.
On my system, Net::SMTP::TLS (/Library/Perl/5.8.8/Net/SMTP/TLS.pm) needs a patch around line 396 to avoid these errors.
# politely disconnect from the SMTP server.
sub quit {
        my $me  = shift;
        $me->_command("QUIT");
        my ($num, $txt) = $me->_response();
        if(not $num == 221){
                croak "An error occurred disconnecting from the mail server: $num $txt\n";
        }
}
Should be:
# politely disconnect from the SMTP server.
sub quit {
        my $me  = shift;
        $me->_command("QUIT");
        my ($num, $txt) = $me->_response();
        my $numnum = $num + 0; # force it to be numeric -jb
        $txt = "" unless $txt;
        if(not $numnum == 221){
                croak "An error occurred disconnecting from the mail server: $num $txt\n";
        }
}
error using check_smtp_send to send a mail through Gmail with ssl

Problem: The email, at last, is sent, but the plugin returns an UNKNOW STATE to Nagios. Shell execution returns that:

./check_smtp_send -H smtp.gmail.com --mailfrom mymail@gmail.com --mailto mymail@test.com -U myuser@gmail.com -P mypassword --header "Subject: Nagios Test" -w 5 -c 120 --tls --ssl
Use of uninitialized value in pattern match (m//) at /usr/lib/perl5/site_perl/5.8.8/Net/SMTP/TLS.pm line 140, line 7.
Use of uninitialized value in numeric eq (==) at /usr/lib/perl5/site_perl/5.8.8/Net/SMTP/TLS.pm line 396, line 7.
Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/site_perl/5.8.8/Net/SMTP/TLS.pm line 397, line 7.
Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/site_perl/5.8.8/Net/SMTP/TLS.pm line 397, line 7.
An error occurred disconnecting from the mail server:
at ./check_smtp_send line 203

I've got all needed Perl modules well installed and the plugin works well through other smtp servers without ssl. Solution: This appears to be a malfunction of the gmail servers. Apparently once the smtp client sends the "quit" command, gmail disconnects immediately instead of sending a successful quit response (don't ask me why that's part of the protocol in the first place). The Net::SMTP::TLS module then has a problem because it's looking for this response and it's not there, which is what causes those warnings you see on the console. On my system I fixed it by editing /usr/lib/perl5/site_perl/5.8.8/Net/SMTP/TLS.pm Line 139: add || "" to the end of the line immediately before the semicolon. So the revised line looks like this:

my $line = $me->{sock}->getline() || "";
Line 395: add || (221,"") to the end of the line immediately before the semicolon. So the revised line looks like this:
my ($num, $txt) = $me->_response() || (221,"");

After doing that, the script runs ok.

I’m trying to use my Exchange server to send me the notifications from nagios
If you're using Nagios to monitor your Exchange server, you're better off installing sendmail, because when your Exchange server fails you'll want something reliable to deliver the alerts to you.
I'm getting "Service check did not exit properly" from Nagios but it's working from the command line!

Your Nagios is probably compiled with an embedded Perl interpreter.

Try using the embedded Perl versions of the plugins; they are included in the archive you downloaded from the check_email_delivery website and are drop-in replacements for the regular Perl versions.

Regular PerlEmbedded Perl
check_email_deliverycheck_email_delivery_epn
check_smtp_sendcheck_smtp_send_epn
check_imap_receivecheck_imap_receive_epn

If that doesn't solve your problem, try calling Perl with the script instead of the script directly. So change $LIBEXEC$/check_email_delivery to perl $LIBEXEC$/check_email_delivery.

If that doesn't solve your problem, you can try recompiling your Nagios without the embedded Perl interpreter. You can then use the regular versions of the plugins.

Need help configuring the plugin? Send your question by email: jonathan@buhacoff.net