Page 1 of 1

Host Notifications wont trigger email.

Posted: Mon Nov 04, 2013 7:02 am
by jensaberg
Hi, I'm hoping someone can help me with this.

I have a problem with notification on our Nagios core installation. I noticed that it triggers and sends service notifications without any problem. But Host notifications does not trigger an email notification, for example when a host goes offline.

I'm thinking its something with the 'notify-host-by-email' command? Becasue the service-by-email works...
I will paste the config for that:

# '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$
}

Thanks in advance!

EDIT: I use postfix with nagios on an Ubuntu server.

Re: Host Notifications wont trigger email.

Posted: Mon Nov 04, 2013 10:35 am
by slansing
That command definition looks perfect. Does your contact have the correct host notification options defined on it so that if an alert is triggered it will receive the notification? Does the host itself have the correct notification options defined? It may be easier if you posted both of the above "blocking out sensitive information," so that we can see them.

Re: Host Notifications wont trigger email.

Posted: Tue Nov 05, 2013 2:26 am
by jensaberg
I define a host like this, nothing special, I have tried to define here "contact groups admins", but nothing. admins are the group where my contact is in:
define host{
use windows-server
host_name wsus
address x.x.x.x
}
And the template windows server looks like this, where the notification options are pointed out:
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 5 ; Actively check the server every 5 minutes
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_options d,r ; 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
}

My contact looks like this, I've used the default, and just changed it, where nagiosadmin is a menber of the group admins:
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact temp$
alias Nagios Admin ; Full name of user

email [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRES$
}
And generic contact looks like this:
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, flapp$
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping$
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 C$
}

Anything out of the ordinary? Something I've missed, or do you need some more information. Its send notifications just fine when a service goes down, but not when a host goes down.
Thanks in advance!

Re: Host Notifications wont trigger email.

Posted: Tue Nov 05, 2013 4:57 pm
by tmcdonald
Can you please check your /var/log/mail.log file?

Code: Select all

egrep '(warning|error|fatal|panic):' /var/log/mail.log | tail -100
Of course please remove any sensitive information.

Re: Host Notifications wont trigger email.

Posted: Wed Nov 06, 2013 2:16 am
by jensaberg
There are no errors in that log. I can see in that and the nagios.log, that and e-mail i being sent when a service goes down. but when a node goes down, the log dosent register any attemt to send an email, therefore no errors either.

The nagios.log just says, Host Unreachable when node is down. But I can see no mail attempts in the mail log.


EDIT: Strange thing, it seems to work some of the time. I'll post a log from nagios.log
[1383742652] HOST ALERT: wsus;DOWN;HARD;1;CRITICAL - Host Unreachable (x.x.x.x)
[1383742652] HOST NOTIFICATION: nagiosadmin;wsus;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (x.x.x.x)
[1383742972] HOST ALERT: wsus;UP;HARD;1;PING OK - Packet loss = 0%, RTA = 0.41 ms
[1383742972] HOST NOTIFICATION: nagiosadmin;wsus;UP;notify-host-by-email;PING OK - Packet loss = 0%, RTA = 0.41 ms
[1383746242] Auto-save of retention data completed successfully.
[1383749842] Auto-save of retention data completed successfully.
[1383750722] HOST ALERT: wsus;DOWN;SOFT;1;CRITICAL - Host Unreachable (x.x.x.x))
[1383750792] HOST ALERT: wsus;DOWN;SOFT;2;CRITICAL - Host Unreachable (x.x.x.x))
[1383750862] HOST ALERT: wsus;DOWN;SOFT;3;CRITICAL - Host Unreachable (x.x.x.x))


Regards
Jens

Re: Host Notifications wont trigger email.

Posted: Wed Nov 06, 2013 10:52 am
by tmcdonald
Ahh, I think I see the problem.

Nagios by default does not send an alert on SOFT down states, which is when a host is down but has not been checked, in your case, 10 times as defined by max_check_attempts. Once it is checked as being down 10 times, it enters into a HARD down state and sends an email.

Take a look at the following doc for more:

http://nagios.sourceforge.net/docs/3_0/statetypes.html

Re: Host Notifications wont trigger email.

Posted: Thu Nov 07, 2013 4:37 am
by jensaberg
That was the issue here. The mac_check_attemt was set to 10.
Thanks for your post!