LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Nagios is not generating any email alerts (https://www.linuxquestions.org/questions/linux-general-1/nagios-is-not-generating-any-email-alerts-918137/)

mail4vijay 12-11-2011 02:48 AM

Nagios is not generating any email alerts
 
Hi,

I have CentOS 5 with nagios installed as instructed by nagios.org , i have an issue related to email alerts , i have added one linux host for testing ping server and getting alerts in the nagios.log file , but not receiving email for that even though sendmail is running fine in the system. Here is the details as below:-

# tail -f /usr/local/nagios/var/nagios.log

1323592672] HOST ALERT: master;DOWN;SOFT;7;CRITICAL - Host Unreachable (192.168.202.137)
[1323592695] Caught SIGTERM, shutting down...
[1323592695] Successfully shutdown... (PID=4577)
[1323592695] Nagios 3.2.3 starting... (PID=5208)
[1323592695] Local time is Sun Dec 11 14:08:15 IST 2011
[1323592695] LOG VERSION: 2.0
[1323592695] Finished daemonizing... (New PID=5209)
[1323592735] HOST ALERT: master;DOWN;SOFT;2;CRITICAL - Host Unreachable (192.168.202.137)
[1323592805] HOST ALERT: master;DOWN;SOFT;3;CRITICAL - Host Unreachable (192.168.202.137)
[1323592875] HOST ALERT: master;UP;SOFT;4;PING OK - Packet loss = 0%, RTA = 0.34 ms
[1323592905] SERVICE ALERT: master;PING;OK;SOFT;4;PING OK - Packet loss = 0%, RTA = 0.56 ms

root@monitorserver objects]# pwd
/usr/local/nagios/etc/objects
[root@monitorserver objects]# grep vijay contacts.cfg
email vijay@localhost


When i tested email for user vijay i got email like

# mail -v vijay@localhost

, but when my testing host ping up / down i did not receive any email alert,

Please anyone help on this issue and let me know what else i have to check into nagios for this.

Thanks in Advance.
Vijay

angel115 12-12-2011 03:05 AM

Hi mail4vijay,

The ping check test that you are doing need to contain this line:
Code:

notification_options    d,r
d = Down
r = Recovery

If this is already the case
Here is a lead to help you understand how Nagios works: (if you follow the Nagios quickstart guide for your installation)
Schema:
Code:

1) Pingcheck.cfg-|
                |-> 2)template.cfg-|
                                    |->3)contact.cfg-|
                                                    |->4)command.cfg

1) The file where your ping check is define. It MUST have a live like this "use What_ever_template"

2) In that file is where your template are defined. Here you MUST find the What_ever_template used in your check file. This is where I put my notification_options d,r, you must have as well the "contact_groups eMail-Admin"

3) In that file you MUST find the eMail-Admin group that you specify in your template.cfg file
And here is an example of contact.cfg
Code:

define contact{
        name                            eMail-Admin            ; The name of this contact template
        service_notification_period    24x7                    ; service notifications can be sent anytime
        host_notification_period        24x7                    ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s            ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options      d,u,r,f,s              ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands  notify-service-by-email,notify-service-by-sms ; send service notifications via email
        host_notification_commands      notify-host-by-sms    ; send host notifications via email
        register                        0                      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }

define contact{
        contact_name                    eMail_SMS_JMcCarthy
        use                            eMail-Admin
        alias                          eMail & SMS John McCarthy
        email                          John.McCarthy@Company.com
        pager                          00353872917972
        }

4) In the command.cfg you MUST have the command define in your contact.cfg
(for instance: notify-service-by-email and notify-service-by-sms if you want SMS notification)
command.cfg:
Code:

define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: http://nagios/nagios/cgi-bin/status.cgi?host=$HOSTNAME$&style=detail\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n$LONGSERVICEOUTPUT$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

define command{
        command_name    notify-service-by-sms
        command_line    /usr/local/nagios/libexec/eventhandlers/sendsms $CONTACTPAGER$ "NAGIOS $NOTIFICATIONTYPE$ $DATE$ $TIME$ $HOSTNAME$ Service: $SERVICEOUTPUT$"
        }

I hope I've been precise enough,
if not please let me know.

Best regards,
Angel.

mail4vijay 12-12-2011 04:52 AM

Thanks for the reply , i will check and come to to LQ if i face any issue.

mail4vijay 12-13-2011 11:09 PM

Thanks it is working now but i did some changes below in the default settings

vi contacts.cfg

Quote:

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email vijay@localhost
}
# CONTACT GROUPS
#
###############################################################################
###############################################################################

# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.

define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
I created one dir and uder it i created one file 192.168.202.137.cfg

Quote:


# Define a host for the local machine

define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name master
alias Master Server
address 192.168.202.137
notifications_enabled 1
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options d,r
notification_interval 960
notification_period 24x7
flap_detection_enabled 0
# flap_detection_options o,w,c,u
}

# Define a service to "ping" the local machine

define service{
use local-service ; Name of service template to use
host_name master
service_description PING
check_command check_ping!100.0,20%!500.0,60%
notifications_enabled 1
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 960
notification_period 24x7
flap_detection_enabled 0
flap_detection_options o,w,c,u

}



All times are GMT -5. The time now is 10:19 AM.