Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have configured nagios email notification and followed following steps:

sSMTP configuration:

#apt-get install ssmtp  #vi /etc/ssmtp/ssmtp.conf
root=sender.email@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=mycomputerName
UseTLS=YES
UseSTARTTLS=YES
AuthMethod=LOGIN
AuthUser=sender.email@gmail.com
AuthPass=sender.email.password
FromLineOverride=YES
#chmod 640 /etc/ssmtp/ssmtp.conf

Nagios Configuration:

#vi /etc/nagios3/conf.d/localhost_nagios2.cfg
define host{
          use                     generic-host            ; Name of host template to use
          host_name               localhost
          alias                   localhost
          address                 x.x.x.187
          check_command           check-host-alive
          max_check_attempts      10
          notification_interval   120
         notification_period     24x7
          notification_options    d,r
          contact_groups  admins
  }


 #vi /etc/nagios3/conf.d/timeperiods_nagios2.cfg
 define timeperiod{
         timeperiod_name 24x7
         alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
         monday          00:00-24:00
         tuesday         00:00-24:00
         wednesday       00:00-24:00
         thursday        00:00-24:00
         friday          00:00-24:00
         saturday        00:00-24:00
 }

 #vi /etc/nagios3/conf.d/contacts_nagios2.cfg
 define contact{
         contact_name                    localhost
         alias                           localhost 
         service_notification_period     24x7
         host_notification_period        24x7
         service_notification_options    w,u,c,r
         host_notification_options       d,r
         service_notification_commands   notify-by-email
         host_notification_commands      host-notify-by-email
         email                           receive.mail@gmail.com
 }
 define contactgroup{
         contactgroup_name       admins
         alias                   Nagios Administrators
         members                 localhost
 }

 #vi /etc/nagios3/conf.d/services_nagios2.cfg
 define service{
         use                             generic-service         
         host_name                       localhost
         service_description             SSH
         is_volatile                     0
         check_period                    24x7
         max_check_attempts              4
         normal_check_interval           5
         retry_check_interval            1
         contact_groups                  admins
         notification_interval           960
         notification_period             24x7
         check_command                   check_ssh
  }

notify-by-email command:

define command{
        command_name    notify-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios @VERSION@ *****\n \nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$OUTPUT$" | @MAIL_PROG@ -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

After configuring nagios I have restarted SSH but it does not send email notification.

New

'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" | /usr/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" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
share|improve this question
    
What does notify-by-email definition look like? How do you test the email notification? –  quanta Aug 7 '12 at 7:21
    
define command{ command_name notify-by-email command_line /usr/bin/printf "%b" "***** Nagios @VERSION@ ***\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$OUTPUT$" | @MAIL_PROG@ -s " $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } –  Jerry Aug 7 '12 at 7:44
    
Maybe sshd restart too fast. Go to Web UI -> Services -> SSH -> Send custom service notification to see what happens. –  quanta Aug 7 '12 at 8:12
    
@quanta-> it shows "Sorry, but Nagios is currently not checking for external commands, so your command will not be committed!" –  Jerry Aug 7 '12 at 8:23
    
Edit nagios.cfg and change check_external_commands=0 to check_external_commands=1, restart Nagios and try again. –  quanta Aug 7 '12 at 8:30
show 14 more comments

1 Answer

up vote 2 down vote accepted

Since you see the below line in the /var/log/maillog:

sSMTP[5532]: /etc/ssmtp/ssmtp.conf not found

although it exists:

-rw-r----- 1 root mail 682 Aug 9 11:23 /etc/ssmtp/ssmtp.conf

I suspect that you haven't add the nagios user to the mail group. Do it by following command:

# usermod -a -G mail nagios

and try again.

share|improve this answer
    
It works now. Thank you quanta....thank you very very much... –  Jerry Aug 10 '12 at 5:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.