Nagios Email Notifications not sending emails

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
polo
Posts: 2
Joined: Tue Jan 21, 2020 2:58 pm

Nagios Email Notifications not sending emails

Post by polo »

Hello guys,
I would like to ask you for help with sending e-mail notification from Nagios. I tried to do my best, but I am not able to fix the problem. Nagios doesnt want to send the e-mail notification. I went through this topic: https://support.nagios.com/forum/viewto ... =7&t=39208, but it also didnt fix the issue. Here is my configuration:


Nagios Core: 4.4.5
OS: CentOS 8
kernel: 4.18.0-80.11.2.el8_0.x86_64
SELinux: disabled





cat /usr/local/nagios/etc/nagios.cfg | grep enable_notifications
enable_notifications=1


Configuration files:
/usr/local/nagios/etc/servers/osvobozeni.cfg

Code: Select all

###
define host {
        use                             linux-server
        host_name                       osvobozeni
        alias                           osvobozeni_RB_Pi
        address                         SERVER_IP_ADDRESS
        max_check_attempts              5
        check_period                    24x7
        notification_interval           30
        notification_period             24x7
        contacts                        Pavel
}


define service {
        use                             generic-service
        host_name                       osvobozeni
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
}


define service{
   use                      generic-service
   host_name      osvobozeni
   service_description   Monitoring web test
   check_command   check_tcp!8081
   contact_groups          admins
   }
###


/usr/local/nagios/etc/objects/contacts.cfg

Code: Select all

###
#### MINE DEFINITION
define contact {
        contact_name                            Pavel
        alias                                   polo
        email                                   [email protected]
        service_notification_period             24x7
        service_notification_options            w,u,c,r,f,s
        service_notification_commands           notify-service-by-email
        host_notification_period                24x7
        host_notification_options               d,u,r,f,s
        host_notification_commands              notify-host-by-email

}




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

/usr/local/nagios/etc/objects/commands.cfg

Code: Select all

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

journalctl log:
### In Nagios web interface: service -> Send custom service notification -> commit
journal -f

Code: Select all

Jan 24 17:17:20 monitor nagios[892]: EXTERNAL COMMAND: SEND_CUSTOM_SVC_NOTIFICATION;osvobozeni;Monitoring web test;0;Nagios Admin;test mailu
Jan 24 17:17:20 monitor nagios[892]: SERVICE NOTIFICATION: nagiosadmin;osvobozeni;Monitoring web test;CUSTOM (CRITICAL);notify-service-by-email;CRITICAL - Socket timeout;Nagios Admin;test mailu
Jan 24 17:17:20 monitor nagios[892]: SERVICE NOTIFICATION: Pavel;osvobozeni;Monitoring web test;CUSTOM (CRITICAL);notify-service-by-email;CRITICAL - Socket timeout;Nagios Admin;test mailu
Jan 24 17:17:20 monitor nagios[897]: job 1 (pid=1989): read() returned error 11
Jan 24 17:17:20 monitor nagios[895]: job 2 (pid=1990): read() returned error 11
Jan 24 17:17:20 monitor postfix/postdrop[1997]: warning: unable to look up public/pickup: No such file or directory
Jan 24 17:17:20 monitor postfix/postdrop[1998]: warning: unable to look up public/pickup: No such file or directory


### THIS WORKS(from CLI):

Code: Select all

/usr/bin/printf "%b" "test" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" [email protected]
Maybe, overlooked something ... but I really can not find out, where I did the mistake. I would appreciate any help.
Thank you very much in advance.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Email Notifications not sending emails

Post by scottwilkerson »

lets try this

Code: Select all

mkfifo /var/spool/postfix/public/pickup
chown postfix.postfix /var/spool/postfix/public/pickup
chmod +w /var/spool/postfix/public/pickup
service postfix restart
Re: https://www.itechlounge.net/2011/11/pos ... licpickup/
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
polo
Posts: 2
Joined: Tue Jan 21, 2020 2:58 pm

Re: Nagios Email Notifications not sending emails

Post by polo »

Hi,
thank you very much, it helped, but the problem with delivering e-mails still persist. Firstly, I want to say, that I use mailx utility for e-mail sending (it works from CLI). Here is my config file for the utility:


cat /root/.mailrc

Code: Select all

set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set [email protected]
set smtp-auth-password=********
set [email protected]


Here is log output after sending custom mail from Nagios web page. I am not able to google the solution.

Code: Select all

Jan 25 09:29:57 monitor nagios[10052]: EXTERNAL COMMAND: SEND_CUSTOM_SVC_NOTIFICATION;osvobozeni;Monitoring web test;0;Nagios Admin;test mailu
Jan 25 09:29:57 monitor nagios[10052]: SERVICE NOTIFICATION: nagiosadmin;osvobozeni;Monitoring web test;CUSTOM (CRITICAL);notify-service-by-email;CRITICAL - Socket timeout;Nagios Admin;test mailu
Jan 25 09:29:57 monitor nagios[10052]: SERVICE NOTIFICATION: Pavel;osvobozeni;Monitoring web test;CUSTOM (CRITICAL);notify-service-by-email;CRITICAL - Socket timeout;Nagios Admin;test mailu
Jan 25 09:29:57 monitor nagios[10054]: job 0 (pid=10080): read() returned error 11
Jan 25 09:29:57 monitor nagios[10055]: job 1 (pid=10081): read() returned error 11
Jan 25 09:29:58 monitor postfix/pickup[9687]: 08282DCAF3: uid=1001 from=<nagios>
Jan 25 09:29:58 monitor postfix/cleanup[10090]: 08282DCAF3: message-id=<[email protected]>
Jan 25 09:29:58 monitor postfix/qmgr[9688]: 08282DCAF3: from=<[email protected]>, size=733, nrcpt=1 (queue active)
Jan 25 09:29:58 monitor postfix/pickup[9687]: 091EBDCAC7: uid=1001 from=<nagios>
Jan 25 09:29:58 monitor postfix/cleanup[10090]: 091EBDCAC7: message-id=<[email protected]>
Jan 25 09:29:58 monitor postfix/qmgr[9688]: 091EBDCAC7: from=<[email protected]>, size=739, nrcpt=1 (queue active)
Jan 25 09:29:58 monitor postfix/smtp[10067]: connect to mx1.seznam.cz[2a02:598:a::78:42]:25: Network is unreachable
Jan 25 09:29:58 monitor postfix/smtp[10069]: connect to gmail-smtp-in.l.google.com[2a00:1450:400c:c00::1a]:25: Network is unreachable
Jan 25 09:29:58 monitor postfix/smtp[10069]: 091EBDCAC7: to=<[email protected]>, relay=gmail-smtp-in.l.google.com[108.177.15.27]:25, delay=0.8, delays=0.02/0/0.59/0.19, dsn=5.7.26, status=bounced (host gmail-smtp-in.l.google.com[108.177.15.27] said: 550-5.7.26 This message does not have authentication information or fails to 550-5.7.26 pass authentication checks. To best protect our users from spam, the 550-5.7.26 message has been blocked. Please visit 550-5.7.26  https://support.google.com/mail/answer/81126#authentication for more 550 5.7.26 information. d25si1966555wmb.20 - gsmtp (in reply to end of DATA command))
Jan 25 09:29:58 monitor postfix/cleanup[10090]: CABB1DCAF2: message-id=<[email protected]>
Jan 25 09:29:58 monitor postfix/qmgr[9688]: CABB1DCAF2: from=<>, size=3468, nrcpt=1 (queue active)
Jan 25 09:29:58 monitor postfix/bounce[10091]: 091EBDCAC7: sender non-delivery notification: CABB1DCAF2
Jan 25 09:29:58 monitor postfix/qmgr[9688]: 091EBDCAC7: removed
Jan 25 09:29:58 monitor postfix/local[10092]: CABB1DCAF2: to=<[email protected]>, relay=local, delay=0.02, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jan 25 09:29:58 monitor postfix/qmgr[9688]: CABB1DCAF2: removed
Jan 25 09:29:59 monitor postfix/smtp[10067]: 08282DCAF3: host mx1.seznam.cz[77.75.76.42] said: 451 4.4.8 Unroutable email address. (in reply to MAIL FROM command)
Jan 25 09:29:59 monitor postfix/smtp[10067]: connect to mx1.seznam.cz[2a02:598:2::42]:25: Network is unreachable
Jan 25 09:30:00 monitor postfix/smtp[10067]: 08282DCAF3: to=<[email protected]>, relay=mx1.seznam.cz[77.75.78.42]:25, delay=2.3, delays=0.02/0/2.3/0.01, dsn=4.4.8, status=deferred (host mx1.seznam.cz[77.75.78.42] said: 451 4.4.8 Unroutable email address. (in reply to MAIL FROM command))
... and the last thing. Is necessary to use Postfix for e-mail sending? I am asking, because mailx utility worked without Postfix, I just had to configure /root/.mailrc file.

If Nagios can not send e-mails without Postfix, so I thing, there is necessity to configure Postfix, right? But I dont have any experience with that :(
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios Email Notifications not sending emails

Post by Box293 »

It really sounds like this is an issue out of Nagios and with your mail / network configuration. My advice is:

* Enable debug logging in Nagios XI
* Force a notification to be sent
* Check debug log to find the complete command Nagios is executing to send the mail notification
* At the command line, as the "nagios" user execute that command and determine what errors are being generated from it

You really need to isolate Nagios from the command being used to send the email. If that is working OK then it must be something Nagios related, but first you should identify the command Nagios is executing to send the email (hence the debug logging).

This sets the debug level on and then restarts Nagios.

Code: Select all

sed -i 's/.*debug_level=.*/debug_level=-1/g' /usr/local/nagios/etc/nagios.cfg
service nagios restart
The debug file is /usr/local/nagios/var/nagios.debug

When you are finished this turns debugging off:

Code: Select all

sed -i 's/.*debug_level=.*/debug_level=0/g' /usr/local/nagios/etc/nagios.cfg
service nagios restart
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked