Cant send Email Notification for host or service down


#1

I am using Nagios-3.0b1 i am not able to send email for host down or for services down. Below are my configuration details.

command.cfg

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" | /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$" | /bin/mail -s " $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

contact.cfg

define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
contactgroups admins
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,n
host_notification_options d,u,r,f,n
service_notification_commands notify-by-email
host_notification_commands notify-host-by-email
email baadshah@gmail.com
}

define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}

testing.cfg (host file)

define host{
name linux-box1 ; Name of this template
use generic-host ; Inherit default values
check_period 24x7
check_interval 1
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0
}

define host{
use linux-box1 ; Inherit default values from a template
check_command notify-host-by-email
host_name testing ; The name we’re giving to this server
alias testing ; A longer name for the server
contact_groups admins
address 192.168.1.33 ; IP address of the server
}

nagios.log

[1216278444] HOST NOTIFICATION: nagiosadmin;testing;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (192.168.1.33)

cat /var/log/maillog.log

here sun.abc.net is the host name where nagios is install.

                                                                                   Jul 17 15:31:23 sun sendmail[15230]: m6HA1Mc5015229: to=<nagios@sun.abc.net>, ctladdr=<nagios@sun.abc.net> (502/503),

delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30808, dsn=2.0.0, stat=Sent Jul 17 15:32:12 sun sendmail[15266]: m6HA2CTb015266: from=nagios, size=353, class=0, nrcpts=1, msgid=<200807171002.m6HA2CTb01
5266@sun.abc.net>, relay=nagios@localhost Jul 17 15:32:12 sun sendmail[15269]: m6HA2CKQ015269: from=nagios@sun.abc.net, size=634, class=0, nrcpts=1, msgid=<20080
7171002.m6HA2CTb015266@sun.abc.net>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1] (may be forged) Jul 17 15:32:12 sun sendmail[15266]: m6HA2CTb015266: to=nagios@localhost, ctladdr=nagios (502/503), delay=00:00:00, xdelay=00
:00:00, mailer=relay, pri=30353, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (m6HA2CKQ015269 Message accepted for delivery)

cat /var/log/messages

Jul 17 13:07:24 sun nagios: HOST NOTIFICATION: nagiosadmin;testing;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (192.168.1.33)
Jul 17 13:10:18 sun nagios: SERVICE NOTIFICATION: nagiosadmin;rencsc;MG Service check;CRITICAL;notify-service-by-email;(Return code of 127 is out of bounds - plugin may be missing)

nagios.cfg

enable_notifications=1
admin_email=baadshah@gmail.com
admin_pager=pagenagios@localhost

If i am firing the below command of command_line manually on linux command prompt than i am getting the mail on my specified email address.

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$ **” baadshah@gmail.com

Please help me i am new to nagios.

Thanks


#2

Hi!

in your contact.cfg:

define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
contactgroups admins
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,n
host_notification_options d,u,r,f,n
service_notification_commands notify-by-email
host_notification_commands notify-host-by-email
email -email-
}

you should remove the “n”, which means “none”, as “no notifications will be sent” (because it overrides all the other options, which is a bit weird, I know :))

hope this helps and that it was the only mistake (cause I didn’t study all your configs ^^)


#3

Thanks for your reply.

After removing n from the notification options than also i am not able to send mails.

nagios.log

[1216358641] SERVICE NOTIFICATION: nagiosadmin;testing;Total Processes;CRITICAL;notify-service-by-email;Connection refused or timed out

[1216359155] SERVICE ALERT: testing;Root Partion Information Free Space;CRITICAL;SOFT;1;Connection refused or timed out
[1216359205] SERVICE ALERT: testing;Current Users;CRITICAL;SOFT;2;Connection refused or timed out

[1216359225] SERVICE ALERT: testing;SSH Service availaibility;CRITICAL;SOFT;1;No route to host
[1216359265] SERVICE ALERT: testing;CPU Load;CRITICAL;HARD;3;Connection refused or timed out
[1216359265] SERVICE NOTIFICATION: nagiosadmin;testing;CPU Load;CRITICAL;notify-service-by-email;Connection refused or timed out
[1216359275] SERVICE ALERT: testing;Root Partion Information Free Space;CRITICAL;SOFT;2;Connection refused or timed out
[1216359295] SERVICE ALERT: testing;Total Processes;CRITICAL;SOFT;1;Connection refused or timed out


#4

If i am putting following thing in my command.cfg than also it is not creating sample.log file which host is down.

define command{
command_name notify-host-by-email
command_line whoami >> ./sample.log

I think problem is this command is not able to call only. Please guide me thanks…


#5

Anybody there please help…


#6

just checking, you did restart nagios after taking the 'n’s out of the notification options ?


#7

It`s alread restart…Even with this command it is not generating files also.

commands.cfg

define command{
command_name notify-host-by-email
command_line whoami >> ./sample.log

define command{
command_name notify-service-by-email
command_line date >> ./date.log


#8

[blockquote]
contact.cfg

define contact{

service_notification_commands notify-by-email
host_notification_commands notify-host-by-email

[/blockquote]

Is that bit a typo in your first post, or your config? Should be notify-service-by-email…


#9

After putting notify-service-by-email than also i am not able to send mails. For this it has to fire command from command.cfg even that is not able fire that command.

Please help me…
Thanks


#10

In your host template notification_options are set to d,r, which means down, recovered. You should add the u option for the unreachable hosts, as I see all of your host are unreachable in log file.

Maybe it’s the same for service templates. Check that out.


#11

Still after putting u also it`s not sending any emails. Thanks…

Please help me.


#12

hmmm… here’s my commands.cfg

‘host-notify-by-email’ command definition

define command{
command_name host-notify-by-email
command_line /usr/bin/printf “%b” “***** Nagios 2.12 *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /bin/mail -s “Host $HOSTSTATE$ alert for $HOSTNAME$!” $CONTACTEMAIL$
}

‘notify-by-email’ command definition

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


#13

nagios.cfg

enable_notifications=1
"admin_email=baadshah@gmail.com" - no need to add this… it must be on the contacts
"admin_pager=pagenagios@localhost" - also this…

hope it will help…