Nagios Notifications Configuration


Hi folks

I’m new to using Nagios and am just toying around with it at the moment. One of the features that is very useful for me is the Nagios’ ability to send me an e-mail when a ping check to a router fails. I successfully installed Nagios and set up a ping check on a remote IP by configuring nagios/etc/objects/switch.cfg. Here is my definition of the ping check service (the default definition with notifications explicitly enabled).

define service{
        use                     generic-service ; Inherit values from a template
        host_name               bogus           ; The name of the host the service is associated with
        service_description     PING            ; The service description
        contact_groups          admins          ;Send notifications to admins
        notifications_enabled   1               ;Yes notifications
        notification_interval   120             ;
        notification_period     24x7            ;
        notification_options    w,u,c,r         ;
        check_command           check_ping!200.0,20%!600.0,60%  ; The command used to monitor the service
        normal_check_interval   1               ; Check the service every 5 minutes under normal conditions
        retry_check_interval    1               ; Re-check the service every minute until its final/hard state is determined

I have postfix running (I have sent test mails and they work fine), and contacts.cfg seems correctly configure.

When I turn the switch off, the web based GUI shows that the ping check has failed, but no notification is sent out. I checked the syslog and the Nagios log to verify this. Is there anything I can do to fix the situation?

Thanks in advance


is anything in the notifications page of nagios?

do you have a user defined with notifications enabled?
are notifications enabled for the host AND for the service in the switch.cfg ?


Hey IHouse,

Look at a couple of things. Logs are your friend here. The Nagios log is in /usr/local/nagios/var. The Event Viewer in the MUI is also a great help for you. Look to see if Nagios is sending the alert by opening that Event Viewer. It will be shown with a small megaphone at the start of the entry if it is sending the alert. (I am assuming you have succesfully accessed the MUI - the Nagios web page that is the admin interface for managing Nagios. If you haven’t got this working then you need to back up a bit…).

One of the problems I had when I first implemented Nagios is that the canned path that Nagios has in its default configs is not correct for the Postfix mail client. This is set in the coomands.cfg file in the …/objects directory for Nagios. Open that commands.cfg file and look at the path for the mail client contained in the first default “Notify-Host-By-Email” statement - it is the very first command in that file if you are using the default file. This is the default line:

‘notify-host-by-email’ command definition

define command{
command_name notify-host-by-email
command_line /usr/bin/printf “%b” “***** NagiosServerName ***\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s " $NOTIFICATIONTYPE$ -DEV ONLY Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” $CONTACTEMAIL$

The issue for me was the location of the “mail” file - it isn’t /usr/bin/mail as indicated in that file.

Here is my working Nagios notify-host-by-email command that is set up for Postfix:

‘notify-host-by-email’ command definition

define command{
command_name notify-host-by-email
command_line /usr/bin/printf “%b” “***** NagiosServerName ***\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | mail -s " $NOTIFICATIONTYPE$ -PROD Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” $CONTACTEMAIL$

The best that I can tell you without going back and digging through my set up notes is that this was a revelation - I remember seeing a hint to the path somewhere and saying "Wait - the mail executable is not in /usr/bin/mail but is local, or something similar. I don’t remember the logic, I am sorry, but it does make sense if you dig. There is either an alias or some other path issue that makes this so. Just try it - it immediately worked when I made the change. The change I am talking about is changing the part after the pipe from “/usr/bin/mail” in the top statement to just “mail” as in the second statement.

I hope this works. Nagios is very slick when you get it working.