Nogios not sending email notification

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
idavoudi
Posts: 3
Joined: Thu Dec 26, 2019 4:01 pm

Nogios not sending email notification

Post by idavoudi »

I've installed Nagios® Core™ 4.4.5 - on Centos 7.6

Nagios doesn't send any email notification automatically when service fails but if I use "Send custom service notification" I'll receive email !

[root@nagios ]# cat /usr/local/nagios/etc/nagios.cfg | grep enable_notifications
enable_notifications=1


Host/Service cfg file:
define host {
use storage-host
host_name X7
alias X7
display_name X7
address 10.180.96.7
hostgroups storage-device
}

define service {

use storage-service ; Name of service template to use
host_name X7
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}


define service {

use storage-service ; Name of service template to use
host_name X7
service_description Disk
check_command Promise_Vtrak_Disk!public!E830!!!!!!
servicegroups storage-device
}


template cfg file :
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
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 ; DON'T REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}

# Storage Device definition template
# This is NOT a real host, just a template!

define host {

name storage-host ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template
check_period 24x7 ; By default, Linux hosts are checked round the clock
check_interval 2 ; Actively check the host every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 2 ; Check each Linux host 10 times (max)
notifications_enabled 1
# event_handler notify-host-by-email
check_command check-host-alive ; Default command to check Linux hosts
notification_interval 2 ; Resend notifications every 30 mins
notification_options d,u,r,f,s ; Only send notifications for specific host states
contacts nagiosadmin
# contact_groups admins ; Notifications get sent to the admins by default
flap_detection_enabled 0 ; Flap detection is enabled
register 0 ; DON'T REGISTER THIS DEFINITION - ITS NOT A REAL HOST, 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
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
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
check_interval 10 ; Check the service every 10 minutes under normal conditions
retry_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DON'T REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}


# Storage disk service definition template
# This is NOT a real service, just a template!

define service {

name storage-service ; The name of this service template
use generic-service ; Inherit default values from the generic-service definition
check_interval 2
retry_interval 1
max_check_attempts 2
check_freshness 1
flap_detection_enabled 0
process_perf_data 0 ; Process performance data
notifications_enabled 1
# event_handler notify-service-by-email
notification_options w,u,r,f,s ; Send notifications about warning, unknown, critical, and recovery even$
contacts nagiosadmin
notification_interval 2
first_notification_delay 0
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLAT$
}

contact cfg file :
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
email idavoudi@hydraulx.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
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
}



command cfg file:

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



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$
}
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nogios not sending email notification

Post by ssax »

What does the final calculated host, contact, and service definition show in your objects.cache file?

Based on these settings:

Code: Select all

check_interval 2
retry_interval 1
max_check_attempts 2 
It will check every two minutes (check_interval), once an problem is detected it will check every minute (retry_interval), up to two times (max_check_attempts) before it will fire a notification.

Do you see the notification listed in Home > Notifications? If so, send a screenshot.

Do you see any errors in /var/log/maillog?

Was it in a problem state long enough for it to fire? You'll need to submit passive results or leave it in the problem state over the course of the check_intervals all the way through retry_intervals to max_check_attempts so that it goes into a HARD state. If it's not in a HARD PROBLEM sate it will not notify.

Did it ever reach the HARD WARNING/CRITICAL state?
idavoudi
Posts: 3
Joined: Thu Dec 26, 2019 4:01 pm

Re: Nogios not sending email notification

Post by idavoudi »

sorry for late reply.

I've waited for at least 20 min.

there is no notification listed =>
No notifications have been recorded in the current log file.

/var/log/mailog doesn't have any new log since service failed.

service is in the HARD state

Screen Capture : https://ibb.co/vhm5KVp

if I use send costume service notification then It will record a notification in home > notification and will send email but it wont send email or record notification automatically. also as you can see in the above screen capture it said Last Notification: N/A (notification 0)

Screen Capture : https://ibb.co/F5YQz1f

Please advise.
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: Nogios not sending email notification

Post by mbellerue »

Can you PM me your /usr/local/nagios/var/objects.cache file?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: Nogios not sending email notification

Post by mbellerue »

Has that service recovered since you posted the screenshot? It looks like you're not monitoring for when the service goes down, but you are monitoring for everything else. This would explain why you didn't get a down email for the service, but if it came back up, you should get a recovery email.

Code: Select all

define service {
	host_name	X7
	service_description	Controller
	...
	notification_options	r,w,u,f,s
	...
	}
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
idavoudi
Posts: 3
Joined: Thu Dec 26, 2019 4:01 pm

Re: Nogios not sending email notification

Post by idavoudi »

rookie mistake :(

Thanks a lot for the help
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nogios not sending email notification

Post by scottwilkerson »

idavoudi wrote:rookie mistake :(

Thanks a lot for the help
Locking thread
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked