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 manish@xxx.com
    }

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
Manish Devraj
  • 121
  • 1
  • 1
  • 3

3 Answers3

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

dmourati
  • 25,540
  • 2
  • 42
  • 72
  • 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 – Manish Devraj Mar 18 '13 at 07: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                           alerts@domainname.com   }

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

Gryu
  • 499
  • 1
  • 6
  • 14
  • 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. – Manish Devraj Mar 18 '13 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.

Gryu
  • 499
  • 1
  • 6
  • 14
Manish Devraj
  • 121
  • 1
  • 1
  • 3