Page 1 of 3

Nagios email alerts

Posted: Mon Dec 26, 2016 1:02 pm
by spyder13337
Hello Everybody,

i am running Centos 7.2 with nagios but i cant send any email alerts am i missing something

i ran this command

Code: Select all

# which sendmail
/usr/sbin/sendmail

Command.cfg

Code: Select all

# '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/sbin/sendmail -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/sbin/sendmail -s “** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
	}
contact.cfg

Code: Select all

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_notifications_enabled           1
	service_notification_period             workhours
        service_notification_options            u,c,r,s
        service_notification_commands           notify-service-by-email
	host_notifications_enabled              1
        host_notification_period                workhours
        host_notification_options               d,u,r,s
        host_notification_commands              notify-host-by-email        
	email                                   xxx@xxxx.com

Re: Nagios email alerts

Posted: Tue Dec 27, 2016 12:46 pm
by dwhitfield
Could you post your entire contact.cfg? If not, could you are least post the part pertinent to
Inherit default values from generic-contact template (defined above)
If the contact.cfg is too large to manually scrub, you can PM the file to me. If you choose to do that, please make sure you update this thread. Updating the thread is the only way it shows back up on our support dashboard. Thanks!

Re: Nagios email alerts

Posted: Tue Dec 27, 2016 2:14 pm
by rkennedy
When a notification should fire in your mind, tail the /usr/local/nagios/var/nagios.log file - do you see any indication of it trying to send here?

If you do, then check out the related error for the notification and look at your /var/log/maillog
If you don't, then the issue more than likely relies in your nagios configuration. It could be in your template as @dwhitfield mentioned, or possibly somewhere else.

Re: Nagios email alerts

Posted: Tue Jan 03, 2017 5:47 pm
by spyder13337
this is the error msg i received

i also update my command file to replace sendmail with this "/usr/bin/mail -a" not sure if this is correct or not

Code: Select all

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

SERVICE NOTIFICATION: nagiosadmin;FS250;Load Balance;CRITICAL;notify-service-by-email;CRITICAL - load average: 237.98, 217.25, 204.86
[1483482402] wproc: NOTIFY job 78 from worker Core Worker 25305 is a non-check helper but exited with return code 2
[1483482402] wproc:   host=FS250; service=Load Balance; contact=nagiosadmin
[1483482402] wproc:   early_timeout=0; exited_ok=1; wait_status=512; error_code=0;
[1483482402] wproc:   stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string

Code: Select all

/var/log/mail.log
Jan  3 17:16:22 Nagios postfix/qmgr[1401]: 747FD140787: from=<>, size=2807, nrcpt=1 (queue active)
Jan  3 17:16:22 Nagios postfix/bounce[18478]: C758D140789: sender non-delivery notification: 747FD140787
Jan  3 17:16:22 Nagios postfix/qmgr[1401]: C758D140789: removed
Jan  3 17:16:22 Nagios postfix/local[18483]: 747FD140787: to=<test@Nagios.celeritytelecom.com>, orig_to=<root@Nagios.celeritytelecom.com>, relay=local, delay=0.06, delays=0.03/0/0/0.03, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION")
Jan  3 17:16:22 Nagios postfix/qmgr[1401]: 747FD140787: removed
Jan  3 17:20:01 Nagios postfix/pickup[32322]: CDA7B140789: uid=116 from=<smmsp>
Jan  3 17:20:01 Nagios postfix/cleanup[21741]: CDA7B140789: message-id=<20170103222001.CDA7B140789@Nagios.celeritytelecom.com>
Jan  3 17:20:01 Nagios postfix/qmgr[1401]: CDA7B140789: from=<smmsp@Nagios.celeritytelecom.com>, size=780, nrcpt=1 (queue active)
Jan  3 17:20:01 Nagios postfix/local[21743]: CDA7B140789: to=<test@Nagios.celeritytelecom.com>, orig_to=<root>, relay=local, delay=0.1, delays=0.08/0/0/0.02, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION")
Jan  3 17:20:01 Nagios postfix/qmgr[1401]: CDA7B140789: removed
Here is my contact.cfg

Code: Select all

###############################################################################
# CONTACTS.CFG - SAMPLE CONTACT/CONTACTGROUP DEFINITIONS
#
#
# NOTES: This config file provides you with some example contact and contact
#        group definitions that you can reference in host and service
#        definitions.
#       
#        You don't need to keep these definitions in a separate file from your
#        other object definitions.  This has been done just to make things
#        easier to understand.
#
###############################################################################



###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################

# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact' 
# template which is defined elsewhere.

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_notifications_enabled           1
	service_notification_period             24x7
        service_notification_options            u,c,r,s
        service_notification_commands           notify-service-by-email
	host_notifications_enabled              1
        host_notification_period                24x7
        host_notification_options               d,u,r,s
        host_notification_commands              notify-host-by-email        
	email                                   support@getcelerity.com 
}


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

Re: Nagios email alerts

Posted: Wed Jan 04, 2017 11:28 am
by dwhitfield
Can you post your objects.cache file so that we can start piecing the puzzle together. Thanks!

Re: Nagios email alerts

Posted: Wed Jan 04, 2017 12:53 pm
by spyder13337
define timeperiod {
timeperiod_name workhours
alias Normal Work Hours
monday 07:01-23:59
tuesday 07:01-23:59
wednesday 07:01-23:59
thursday 07:01-23:59
friday 07:01-23:59
saturday 07:01-23:59
}

define contact {
contact_name nagiosadmin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options r,u,c,s
host_notification_options r,d,u,s
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email support@getcelerity.com
minimum_importance 0
host_notifications_enabled 1
service_notifications_enabled 1
can_submit_commands 1
retain_status_information 1
retain_nonstatus_information 1
}

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 -a “** $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\Additional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -a “** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}


will this due or do you need more

Re: Nagios email alerts

Posted: Wed Jan 04, 2017 4:10 pm
by tgriep
The argument for the mail command should be a -s and not a -a for both of the commands.
If you edit both of those commands and fix that, it should fix that error and start sending emails.

Re: Nagios email alerts

Posted: Fri Jan 06, 2017 1:11 pm
by spyder13337
i am still receiving this error msg

[1483726180] wproc: NOTIFY job 190211 from worker Core Worker 24216 is a non-check helper but exited with return code 2
[1483726180] wproc: host=Lyft Capitol; service=Local Bandwidth; contact=nagiosadmin
[1483726180] wproc: early_timeout=0; exited_ok=1; wait_status=512; error_code=0;
[1483726180] wproc: stderr line 01: /bin/sh: 1: Syntax error: Unterminated quoted string

Re: Nagios email alerts

Posted: Fri Jan 06, 2017 1:24 pm
by dwhitfield
Can you post the output of the following:

Code: Select all

ls -l /usr/sbin/sendmail
ls -l /var/spool
Also, what version of Core are you using? Was it compiled from source or installed from distro repos?

Re: Nagios email alerts

Posted: Fri Jan 06, 2017 4:06 pm
by spyder13337
Damm sorry about that it

Nagios Core 4.2.4
Nagios-Plugins 2.1.4
NRPE 2.15

Debian 8


ls -l /usr/sbin/sendmail

-rwxr-xr-x 1 root root 26680 Nov 4 2014 /usr/sbin/sendmail


ls -l /var/spool

drwxr-xr-x 5 root root 4096 Dec 26 15:35 cron
drwx--x--- 3 root lp 4096 Dec 26 15:32 cups
drwxr-x--- 5 Debian-exim Debian-exim 4096 Dec 26 15:41 exim4
lrwxrwxrwx 1 root root 7 Dec 26 15:05 mail -> ../mail
drwxr-xr-x 20 root root 4096 Jan 2 16:53 postfix
drwx------ 2 root root 4096 Dec 19 2015 rsyslog