Solved

Nagios notify-by-host-email won't work

Posted on 2011-02-17
12
2,695 Views
Last Modified: 2012-05-11

For some reason my nagios notify host by email is not sending emails when servers or switch is down... Can someone help me check the command.cfg below:

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/sbin/sendmail "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

# command_line /usr/bin/printf "%b" "Subject:** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/sbin/sendmail $CONTACTEMAIL$

# command_line  /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nHost notes: $HOSTNOTES$\nHost Info: http://server/nagios/$HOSTNOTESURL$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/sbin/sendmail $CONTACTEMAIL$

command_line /usr/bin/printf "%b" "Subject:** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$/ $HOSTALIAS$/ $HOSTALIAS$ is $HOSTSTATE$ **\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nHost_Alias: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $HOSTSTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$HOSTSTATE$\n\n http://server/nagios\n" | /usr/sbin/sendmail $CONTACTEMAIL$

        }

I created 4 different version and I can't figure out why all of them won't work. I am using postfix to send emails by the way...
0
Comment
Question by:SuperRoot
  • 7
  • 5
12 Comments
 
LVL 8

Expert Comment

by:thetmanvn
ID: 34923629
Did you verify the /var/log/maillog to see what actually happenned, and see the sendmail error output if there was, then we can go further
0
 
LVL 1

Author Comment

by:SuperRoot
ID: 34923671
Thanks for responding! :) Yeah I went to the var->logs->mail and found nothing for any down event for any host... The notify service by email works though... The last command from the notify my host email is identical with notify service by email... Hope that helps...
0
 
LVL 8

Expert Comment

by:thetmanvn
ID: 34923728
Can you post the contacts.cfg to see the contact and service_notification_options host_notification_options set in each one.
0
 
LVL 1

Author Comment

by:SuperRoot
ID: 34925200
Hi thetmanvn, thanks again for responding! I post all the config below.. It would be easier for you to see and check :)

Contacts.cfg
define contact{
        contact_name                    admin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           NagiosAdmin_NetworkAdmin        ; 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                           administrator@omega.com     ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

define contactgroup{
        contactgroup_name       admins
        alias                   NagiosAdministrators
        members                admin
        }


<><><>><>><<>Template.cfg<<><><><><><

define contact{
        name                            generic-contact         ; 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 ; send service notifications via email
        host_notification_commands      notify-host-by-email    ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }

define host{
        name                            generic-host    ; The name of this host template
        notifications_enabled           1               ; Host notifications are enabled
        event_handler_enabled           1               ; Host event handler is enabled
        flap_detection_enabled          1               ; Flap detection is enabled
        failure_prediction_enabled      1               ; Failure prediction is enabled
        process_perf_data               1               ; Process performance data
        retain_status_information       1               ; Retain status information across program restarts
        retain_nonstatus_information    1               ; Retain non-status information across program restarts
        notification_period             24x7            ; Send host notifications at any time
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

define host{
        name                    windows-server  ; The name of this host template
        use                     generic-host    ; Inherit default values from the generic-host template
        check_period            24x7            ; By default, Windows servers are monitored round the clock
        check_interval          2               ; Actively check the server every 5 minutes
        normal_check_interval   2
        retry_interval          1               ; Schedule host check retries at 1 minute intervals
        max_check_attempts      10              ; Check each server 10 times (max)
        check_command           check-host-alive        ; Default command to check if servers are "alive"
        notification_period     24x7            ; Send notification out at any time - day or night
#       notification_interval   30              ; Resend notifications every 30 minutes
        notification_interval   0
        notification_options    d,r,u           ; Only send notifications for specific host states
        contact_groups          admins          ; Notifications get sent to the admins by default
        hostgroups              windows-servers ; Host groups that Windows servers should be a member of
        register                0               ; DONT REGISTER THIS - ITS JUST A TEMPLATE
        }


define host{
        name                    generic-switch  ; The name of this host template
        use                     generic-host    ; Inherit default values from the generic-host template
        check_period            24x7            ; By default, switches are monitored round the clock
#       check_interval          5               ; Switches are checked every 5 minutes
        check_interval          2
        normal_check_interval   2
        retry_interval          1               ; Schedule host check retries at 1 minute intervals
        max_check_attempts      10              ; Check each switch 10 times (max)
        check_command           check-host-alive        ; Default command to check if routers are "alive"
        notification_period     24x7            ; Send notifications at any time
#       notification_interval   30              ; Resend notifications every 30 minutes
        notification_interval   0
        notification_options    d,r             ; Only send notifications for specific host states
        contact_groups          admins          ; Notifications get sent to the admins by default
        register                0               ; DONT REGISTER THIS - ITS JUST A TEMPLATE
        }

define service{
        name                            generic-service         ; The 'name' of this service template
        active_checks_enabled           1                       ; Active service checks are enabled
        passive_checks_enabled          1                       ; Passive service checks are enabled/accepted
        parallelize_check               1                       ; Active service checks should be parallelized (disabling this can lead to major performance problems)
        obsess_over_service             1                       ; We should obsess over this service (if necessary)
        check_freshness                 0                       ; Default is to NOT check service 'freshness'
        notifications_enabled           1                       ; Service notifications are enabled
        event_handler_enabled           1                       ; Service event handler is enabled
        flap_detection_enabled          1                       ; Flap detection is enabled
        failure_prediction_enabled      1                       ; Failure prediction is enabled
        process_perf_data               1                       ; Process performance data
        retain_status_information       1                       ; Retain status information across program restarts
        retain_nonstatus_information    1                       ; Retain non-status information across program restarts
        is_volatile                     0                       ; The service is not volatile
        check_period                    24x7                    ; The service can be checked at any time of the day


define service{
        name                            local-service           ; The name of this service template
        use                             generic-service         ; Inherit default values from the generic-service definition
        max_check_attempts              4                       ; Re-check the service up to 4 times in order to determine its final (hard) state
#        normal_check_interval           5                      ; Check the service every 5 minutes under normal conditions
        normal_check_interval           2
        retry_check_interval            1                       ; Re-check the service every minute until a hard state can be determined
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }

0
 
LVL 1

Author Comment

by:SuperRoot
ID: 34925252
I don't get is notify services by email works but not notify host by email.. Its really weird.. Thanks for helping Sir!
0
 
LVL 8

Expert Comment

by:thetmanvn
ID: 34925707
In your contacts.cfg it seems right, your host_notification_options contains d,u,r that hanle the up, down state of your servers, switches. And also the notify services by email works, and the notify-service-by-email command also use sendmail for sending the notifications?, and in the log you got nothing with this? Can you isolate the test for only up and down host to see the mail log and the nagios log?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Author Comment

by:SuperRoot
ID: 34926535
Hey sir, thanks for replying again... Yes, I use the sendmail command as postfix uses that command. I did cat maillog | grep down command and linux return nothing. I also did mailq command but nothing is on the queue for postfix. Its only the notify-host-by-email is not working and the notify service by email is working.. below is what my notify-service-by-email config:

define command{
        command_name    notify-service-by-email

command_line /usr/bin/printf "%b" "Subject:** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/ $HOSTALIAS$/ $SERVICEDESC$ is $SERVICESTATE$ **\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTNAME$\nHost_Alias: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\n http://server/nagios\n" | /usr/sbin/sendmail $CONTACTEMAIL$

        }


0
 
LVL 8

Accepted Solution

by:
thetmanvn earned 500 total points
ID: 34931263
It's weird, because if you use postfix for delivery mail, so it's info must be saved in /var/log/mail.log, mail.info, mail.err whether it was sent successfully or not. So instead of using postfix can you test with other MTA like sendmail with mail command.
0
 
LVL 1

Author Comment

by:SuperRoot
ID: 34933012

Thanks again for replying  and helping :) I truly appreicate it! I don't know other mail options besides postfix. Do you recommend anything that is easy and reliable?

I also make it work using the command below for 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" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

THe problem is, postfix sends the notification email after 20 minutes. I also see all the logs in the postfix queue. In case you wonder how I got the time, I timed the whole thing yesterday while I was testing it...:)

0
 
LVL 1

Author Comment

by:SuperRoot
ID: 34933062
hi again! hmm I also shut down postfix and I still receive emails.. I think it goes to mailx.. This is a dumb question and I apologize for it but do you know how to find the queues for mailx?
0
 
LVL 8

Expert Comment

by:thetmanvn
ID: 34935889
Did you successfully shutdown postfix? or you have another mail system running on?

Let find up with this command when you shutdown postfix and attemps sending notification with mailx:

#netstat -natp | grep LISTEN | grep ":25"  to see any entry or not?
0
 
LVL 1

Author Comment

by:SuperRoot
ID: 34936026
I find out from /var/log/maillog and /var/mail/mqueue that nagios is using 2 way of email service. Postfix and mailx. After I started postfix and sendmail service, the email are being sent instantanous. I tested it multiple times with different servers and I am getting the process email notification I want. Thank you thetmanvn for helping! I'll give you full credit for everything :)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
David Varnum recently wrote up his impressions of PRTG, based on a presentation by my colleague Christian at Tech Field Day at VMworld in Barcelona. Thanks David, for your detailed and honest evaluation!
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now