Add more info to your Nagios notifications
I finally got tired of getting Nagios notifications that didn’t have all the info I wanted in them. Specifically, I was guessing if the problem had been acknowledged based on the notification interval (how long since I received the last notification), or logging in to Nagios to check.
I decided to customize the Nagios email notifications by editing the
# 'host-notify-by-email' command definition, which is the notification type that I’ve been using.
# 'host-notify-by-email' command definition looked like this:
command[host-notify-by-email]=/bin/echo -e "***** Nagios *****nnHost "$HOSTALIAS$" is $HOSTSTATE$!nn$HOSTADDRESS$nnDate/Time: $DATETIME$n" | /bin/mail -s 'Host $HOSTNAME$ is $HOSTSTATE$!' $CONTACTEMAIL$
which produced a notification that simply included the hostname, the state, and the date/time. I hopped on over to the Nagios Macros page at Sourceforge and grabbed what I wanted, then edited the
# 'host-notify-by-email' command definition as follows:
# 'host-notify-by-email' command definition
command_line /bin/echo -e "***** Nagios *****nnThis is a $NOTIFICATIONTYPE$ notice that "$HOSTALIAS$" is $HOSTSTATE$!nnHost IP is $HOSTADDRESS$nnDuration is $HOSTDURATION$nnDate/Time: $LONGDATETIME$nnhttp://nagios.mydomain.com/nagios/nnnNagios SummarynTotal Unhandled Host Problems:$TOTALHOSTPROBLEMSUNHANDLED$nTotal Unhandled Service Problems:$TOTALSERVICEPROBLEMSUNHANDLED$" | /bin/mail -s 'Host $HOSTNAME$ is $HOSTSTATE$!' $CONTACTEMAIL$
Now my Nagios email notifications look like this:
***** Nagios *****
This is a PROBLEM notice that DevServer is DOWN!
Host IP is 192.168.1.100
Duration is 0d 0h 0m 0s
Date/Time: Tue Aug 3 13:19:25 PDT 2010
Total Unhandled Host Problems:1
Total Unhandled Service Problems:0
The “This is a PROBLEM notice” part is created by the
$NOTIFICATIONTYPE$ macro. This is nice because it tells you what kind of notification it is (“PROBLEM”, “RECOVERY”, “ACKNOWLEDGEMENT”, “FLAPPINGSTART”, “FLAPPINGSTOP”, “FLAPPINGDISABLED”, “DOWNTIMESTART”, “DOWNTIMEEND”, or “DOWNTIMECANCELLED”), which is much more useful than just getting another DOWN notice when a problem is acknowledged.
Check out my other Nagios posts, and please leave a comment if you have another tip or trick on customizing your Nagios notifications.