define command{ command_name check_email_delivery command_line $USER1$/check_email_delivery -H $HOSTADDRESS$ --mailfrom $ARG3$ --mailto $ARG4$ --username $ARG5$ --password $ARG6$ --libexec $USER1$ -w $ARG1$ -c $ARG2$ } define service{ use generic-service host_name mail.your.net service_description EMAIL DELIVERY check_command check_email_delivery!5!120!sender@your.net!recipient@your.net!recipient@your.net!password }
A new usage example equivalent to the old one but using the new --plugins and --token options:
define command{ command_name check_email_delivery command_line $USER1$/check_email_delivery -p '$USER1$/check_smtp_send -H $HOSTADDRESS$ --mailfrom $ARG3$ --mailto $ARG4$ -U $ARG5$ -P $ARG6$ --header "Subject: Nagios %TOKEN1%" -w $ARG1$ -c $ARG2$' -p '$USER1$/check_imap_receive -H $HOSTADDRESS$ -U $ARG5$ -P $ARG6$ -s SUBJECT -s "Nagios %TOKEN1%" -w $ARG1$ -c $ARG2$' -w $ARG1$,$ARG1$ -c $ARG2$,$ARG2$ } define service{ use generic-service host_name mail.your.net service_description EMAIL DELIVERY check_command check_email_delivery!5!120!sender@your.net!recipient@your.net!recipient@your.net!password }
If you are using Nagios with embedded perl (ePN), you must use the epn versions of the plugin (included in the distribution). If you don't, you are likely to get an error saying "ePN failed to compile /usr/lib/nagios/plugins/check_email_delivery: Missing right curly or square bracket". Your epn-compatible command line might look like this (note the plugin commands have _epn appended):
define command{ command_name check_email_delivery command_line $USER1$/check_email_delivery_epn -p '$USER1$/check_smtp_send_epn -H $HOSTADDRESS$ --mailfrom $ARG3$ --mailto $ARG4$ -U $ARG5$ -P $ARG6$ --header "Subject: Nagios %TOKEN1%" -w $ARG1$ -c $ARG2$' -p '$USER1$/check_imap_receive_epn -H $HOSTADDRESS$ -U $ARG5$ -P $ARG6$ -s SUBJECT -s "Nagios %TOKEN1%" -w $ARG1$ -c $ARG2$' -w $ARG1$,$ARG1$ -c $ARG2$,$ARG2$ }
check_smtp_send -H server.your.net --tls -U sender@your.net -P password --mailfrom sender@your.net --mailto recipient@your.net --body 'hello, world!' --header 'Subject: test message'
check_smtp_send -H server.your.net --ssl -U sender@your.net -P password --mailfrom sender@your.net --mailto recipient@your.net --body 'hello, world!' --header 'Subject: test message'
check_smtp_send -H server.your.net --auth CRAM-MD5 -U sender@your.net -P password --mailto recipient@your.net --mailfrom sender@your.net --body 'hello, world!' --header 'Subject: test message'
check_imap_receive -H server.your.net --ssl -U sender@your.net -P password -s SUBJECT -s 'test message'
check_smtp_send --mailto recipient@your.net --mailfrom sender@your.net --body 'hello, world!' --header 'Subject: test message'
You can use multiple --mailto options:
check_smtp_send -H server.your.net -U sender@your.net -P password --mailto recipient@your.net --mailto recipient@other.net --mailfrom sender@your.net --body 'hello, world!' --header 'Subject: test message'
Or separate email addresses with a comma:
check_smtp_send -H server.your.net -U sender@your.net -P password --mailto recipient@your.net,recipient@other.net --mailfrom sender@your.net --body 'hello, world!' --header 'Subject: test message'
hostname | check_smtp_send -H server.your.net -U sender@your.net -P password --mailto recipient@your.net --mailfrom sender@your.net --stdin --header 'Subject: test message'
You can create your own script to generate any output to be included in the message and pipe it to check_smtp_send!
The --stdin option limits you to including the output of other programs in the message body. Using the --template option you can include the output of other programs in the message body or in the headers.
check_smtp_send -H server.your.net -U sender@your.net -P password --mailto recipient@your.net --mailfrom sender@your.net --template --body 'Hostname: {`hostname`} Username: {`whoami`}' --header 'Subject: test message'
If you want the output of another program to be in the message headers you should trim it of newlines (the trim function is provided by check_smtp_send):
check_smtp_send -H server.your.net -U sender@your.net -P password --mailto recipient@your.net --mailfrom sender@your.net --template --body 'hello, world!' --header 'X-Hostname: {trim(`hostname`)}' --header 'X-Username: {trim(`whoami`)}' --header 'Subject: test message'
You can actually use any valid Perl expression in between the curly braces. See Text::Template for more information. The following example removes newlines from a file listing so it can be used as the subject of an email:
check_smtp_send -H server.your.net -U sender@your.net -P password --mailto recipient@your.net --mailfrom sender@your.net --template --body 'hello, world!' --header 'Subject: {$_=`ls -1`; s/[\r\n]+/ /g; $_}'
If your server is receiving messages quickly but is really slow to index them and they don't show up in IMAP SEARCH results for a while, try the --download option. It supports a subset of the IMAP SEARCH options. Use the optional --download-max to limit how many messages you download to search (this may impact your results in certain situations!)
check_imap_receive -H server.your.net --ssl -U sender@your.net -P password --download --download-max 50 -s SUBJECT -s 'test message'
Suppose you have a program that is supposed to check a mailbox for messages, then process and remove them. And suppose that it doesn't keep up with peak volume but eventually catches up. And suppose you want to know if it's getting really backlogged:
check_imap_receive -H server.your.net --ssl -U sender@your.net -P password --download --template -s SUBJECT -s 'test message' -s SENTSINCE -s '{date("%B %e, %Y %i:%M:%S %p %Z","now","-4 hours")}' --nodelete --search-warning-min=0 --search-critical-min=0 --search-warning-max=10 --search-critical-max=100
Need help configuring the plugin? Send your question by email: jonathan@buhacoff.net
Thousands of users worldwide. Listed in Nagios Exchange. If you find this software useful, please donate.