2

I have configured Nagios 3.4.4 on CentOS 6.3 Final. I have also configured Postfix with SMTP email server. I have verified from console that I am able to send email notifications and recieved them on designated address.

Nagios is configured to send notify-host-by-email and notify-service-by-email. I can see from Nagios logs that service notification alerts and customer notification being sent from Nagios. But nothing is seen on /vag/log/maillog. There are no errors either.

I even fired 'command_line' from below commands from console and they are able to send emails to address mentioned.

Commands.cfg

# 'notify-host-by-email' command definition

define command{

command_name    notify-host-by-email

command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | sudo /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

# 'notify-service-by-email' command definition
define command{

command_name    notify-service-by-email

command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | sudo /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

Contact.cfg

define contact{
    contact_name manish
    service_notification_period 24x7
    host_notification_period 24x7
    service_notification_options w,u,c,r,f
    host_notification_options d,u,r,f
    service_notification_commands notify-service-by-email
    host_notification_commands notify-host-by-email
    email [email protected]
    }

define contactgroup {
    contactgroup_name   email
    alias Email Group
    members manish
    }

Nagios Groups

cat /etc/group |grep nagios
nagios:x:502:nagios,apache
nagcmd:x:503:nagios,apache
4
  • Similar configuration is present on Ubuntu and it works without different modification to Nagios or Postfix. Mar 18, 2013 at 6:50
  • 1
    I don't think you need sudo for /bin/mail. And if you use it it should be configured not to ask for password. Mar 18, 2013 at 7:10
  • Yes sudo is configured to NOT ask any passwords, so I think we are good there. Mar 18, 2013 at 7:16
  • You should not be using sudo to run mail, though.
    – Keith
    Mar 25, 2013 at 20:12

3 Answers 3

1

You need to configure contacts or contact_groups in the host/service definition. I normally create a template host and service and then override using inheritance.

http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#host http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#service http://nagios.sourceforge.net/docs/3_0/objectinheritance.html

1
  • I do have service created for notification that can send out emails as below, but not sure what it is which is blocking emails. contact_groups emails notification_options w,u,c,r notification_interval 30 notification_period 24x7 Mar 18, 2013 at 7:10
0

in contacts.cfg file:

define contact{ 

        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values
        alias                           Nagios Admin            ; Full name of user
        email                           [email protected]   }

In nagios.cfg:

# ADMINISTRATOR EMAIL/PAGER ADDRESSES

admin_email=nagios@localhost

(or)

You can check the url:
4 Steps to Define Nagios Contacts With Email and Pager Notification

1
  • Thank you, I am using contactgroup as 'emails' which I have also defined in 'Host' and 'Service' I would like to have notification for. I think Nagios went all well triggering notification, but nothing seems to trigger Postfix to get that request and process. Also there is no hit in logs that can show any detailed inforamtion. Mar 18, 2013 at 12:40
0

All configurations were correct and no errors were found on either Nagios or Postfix side. It turns out that Nagios was unable to trigger 'mail' command to actually send email notification.

I changed behavior of command to run a .php to draft an HTML email template and then .php to send out email using mail command.

This approach worked for me for above mentioned scenario. Please use http://exchange.nagios.org/directory/Addons/Notifications/Send-HTML-Alert-Email-v2/details guide in case if anyone is struggling with a similar problem.

2
  • I believe you will need to install the mailx package to be able to use the mail command on CentOS
    – Epaphus
    Mar 19, 2013 at 13:20
  • Agreed, it was installed when I reported this problem. Mar 20, 2013 at 5:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .