Page 1 of 2

Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 7:25 am
by nathanplatt
Hi Everyone,

I've had to rebuild my Nagios on a new physical server, I'm using Ubuntu Server 14.04.3 LTS with the latest build of Nagios. I've managed to port all the relevant .cfg files from the old server to the new server but the emails aren't working.

I'm using Postfix and have tested this, email are received. So i can only see it as a Nagios Problem, I also use a script from http://nagios.fm4dd.com/howto/nagios-fl ... ations.htm

The commands.cfg looks like this;

Code: Select all

# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below.
#
################################################################################

# 'service-email-html-int-en' command definition
# sends HTML e-mails in English and includes Nagios URL for Intranet access
define command{
        command_name    service-email-html-int-en
        command_line    /usr/local/nagios/libexec/nagios_send_service_mail.pl \
-p "Ramsdens Financial" \
-f multi -u
}

# 'host-email-html-int-en' command definition
# sends HTML e-mails in English and includes Nagios URL for Intranet access
define command{
        command_name    host-email-html-int-en
        command_line    /usr/local/nagios/libexec/nagios_send_host_mail.pl \
-p "Ramsdens Financial" \
-f multi -u
}

I ran 'which mail'

Code: Select all

nagios@nagios:/usr/local/nagios/etc/objects$ which mail
/usr/bin/mail
I can email straight from POSTFIX to myself, Mailserver is ping able and the script itself works;

Code: Select all

nagios@nagios:/usr/local/nagios/libexec$ ./nagios_send_host_mail.pl
Error: no recipients have been provided
Usage: ./nagios_send_host_mail.pl [-v] [-V] [-h] [-t] [-H <SMTP host>] [-p <customername>]
       [-r <to_recipients>] or -g <to_group>] [-c <cc_recipients>] [-b <bcc_recipients>]
       [-f <text|html|multi|graph>] [-u] [-l <en|jp|fr|de|(or other languages if added)>]
nagios@nagios:/usr/local/nagios/libexec$ ./nagios_send_service_mail.pl
Error: no recipients have been provided
Usage: ./nagios_send_service_mail.pl [-v] [-V] [-h] [-t] [-H <SMTP host>] [-p <customername>]
       [-r <to_recipients> or -g <to_group>] [-c <cc_recipients>] [-b <bcc_recipients>]
       [-f <text|html|multi|graph>] [-u] [-l <en|jp|fr|de|(or other languages if added)>]
nagios@nagios:/usr/local/nagios/libexec$
The contacts.cfg

Code: Select all

define contact{
        contact_name                    itsupport
        alias                           IT Support
        service_notification_period     workhours
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   service-email-html-int-en
        host_notification_commands      host-email-html-int-en
        email                           [email protected]
        }

define contact{
        contact_name                    marketing
        alias                           Marketing Department
        service_notification_period     workhours
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   service-email-html-int-en
        host_notification_commands      host-email-html-int-en
        email                           [email protected]
        }
Any ideas?

Nathan

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 11:04 am
by hsmith
How were emails configured on your old server?

Can you verify that the contact/contact group is defined inside of the service definition?

For verification, you can receive an email from the script, but Nagios isn't alerting when you have a state that should warrant an alert? I've seen a lot of issues where sendmail gets rejected. I ask this since the output you posted only shows you running the script without arguments, it's not really an indication of whether or not it is successful.

The website you linked is obviously third party, but it looks like it should work pretty well. The steps were followed exactly? I don't see anything in your command definition with the -c flag.

If I were in your shoes, I would verify everything from start to finish with that article, the -c flag inconsistency is what I'm concerned with specifically.

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 11:28 am
by nathanplatt
Hi,

I can't remember how they were configured on the previous server, but all the cfg files where copied from the old server to the new one. I still have access to the old server as a VM, so if you can give me any hints I can try and look them up. I was certain I was using postfix, but my memory seems to think i moved away from that.

I'm not certain Nagios is sending alerts out without the script, is there away for me to test it.

I didn't try normal emails when i configured this, just went straight for the script.

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 11:52 am
by hsmith
Can you verify the script is capable of sending an email?

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 12:00 pm
by nathanplatt

Code: Select all

nagios@nagios:/usr/local/nagios/libexec$ ./nagios_send_host_mail.pl -r [email protected] -t
Server said: 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in local recipient table
Bad recipient <[email protected]>: 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in local recipient table
No valid recipient
Server said: 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in local recipient table
nagios@nagios:/usr/local/nagios/libexec$
Funny, if i send to my personal, it worked, but internal it failed?

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 12:05 pm
by nathanplatt
I checked the mail.log

Code: Select all

nagios@nagios:/var/log$ tail mail.log
Jan  7 16:58:17 nagios postfix/local[1713]: 593387610AF: to=<nagiosadmin@ramsden                                          sfinancial.co.uk>, relay=local, delay=0.09, delays=0.03/0.01/0/0.05, dsn=5.1.1,                                           status=bounced (unknown user: "nagiosadmin")
Jan  7 16:58:17 nagios postfix/qmgr[1271]: 593387610AF: removed
Jan  7 16:58:27 nagios postfix/smtpd[1701]: connect from localhost[127.0.0.1]
Jan  7 16:58:27 nagios postfix/smtpd[1701]: NOQUEUE: reject: RCPT from localhost                                          [127.0.0.1]: 550 5.1.1 <[email protected]>: Recipient address                                           rejected: User unknown in local recipient table; from=<nagiosadmin@ramsdensfina                                          ncial.co.uk> to=<[email protected]> proto=ESMTP helo=<nagios>
Jan  7 16:58:27 nagios postfix/smtpd[1701]: lost connection after RCPT from loca                                          lhost[127.0.0.1]
Jan  7 16:58:27 nagios postfix/smtpd[1701]: disconnect from localhost[127.0.0.1]
Jan  7 16:58:53 nagios postfix/smtpd[1701]: connect from localhost[127.0.0.1]
Jan  7 16:58:53 nagios postfix/smtpd[1701]: NOQUEUE: reject: RCPT from localhost                                          [127.0.0.1]: 550 5.1.1 <[email protected]>: Recipient address re                                          jected: User unknown in local recipient table; from=<nagiosadmin@ramsdensfinanci                                          al.co.uk> to=<[email protected]> proto=ESMTP helo=<nagios>
Jan  7 16:58:53 nagios postfix/smtpd[1701]: lost connection after RCPT from loca                                          lhost[127.0.0.1]
Jan  7 16:58:53 nagios postfix/smtpd[1701]: disconnect from localhost[127.0.0.1]
nagios@nagios:/var/log$
Doesn't seem to be connecting to the server correctly... i can ping it from Nagios and have setup the smtp it should be...

Code: Select all

nagios@nagios:/var/log$ /usr/bin/mail
"/var/mail/nagios": 6 messages 6 new
>N   1 Mail Delivery Syst Thu Jan  7 10:02  66/2049  Undelivered Mail Returned to Sender
 N   2 Mail Delivery Syst Thu Jan  7 10:04  66/2049  Undelivered Mail Returned to Sender
 N   3 Mail Delivery Syst Thu Jan  7 10:39  66/2049  Undelivered Mail Returned to Sender
 N   4 Mail Delivery Syst Thu Jan  7 10:42  66/2034  Undelivered Mail Returned to Sender
 N   5 Mail Delivery Syst Thu Jan  7 11:13  66/2032  Undelivered Mail Returned to Sender
 N   6 Mail Delivery Syst Thu Jan  7 11:18  66/2017  Undelivered Mail Returned to Sender
?
Right so it looks like the mailserver isn't accepting the connection...

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 12:16 pm
by rkennedy
The error logs are connecting to localhost, and attempting to send to [email protected]. It looks like the script you're using for email alerts is not sending to an external SMTP server, I think you may need to use the -H flag to specify your SMTP server.

You may need to specify a host, see this page - http://nagios.fm4dd.com/howto/manual/na ... e_mail.htm
nagios_send_service_mail.pl [-v] [-V] [-h] [-t] [-H <SMTP host>] [-p <company-name>] [-r <to_recipients>] [-c <cc_recipients>] [-b <bcc_recipients>] [-f <text|html|multi|graph>] [-u] [-l <en|jp|fr|de>]
Can you attempt to run the nagios_send_service_mail.pl script over the CLI and post the result?

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 12:25 pm
by nathanplatt
Yes it looks like you're right!

If i use ./nagios_send_host_mail.pl -H 192.168.87.114 -t -r myemail@address I did indeed get the email

So I could put this in the command, but i'll prefer it if postfix just knew where to send it?

Nathan

Re: Emails not recieved from Nagios

Posted: Thu Jan 07, 2016 1:38 pm
by rkennedy
Yes, you will need to modify your commands to include the -H -

Code: Select all

service-email-html-int-en
host-email-html-int-en


You should be able to modify your postfix configuration to pass all emails to your SMTP server. Perhaps compare the main.cf between your old server -> new server, and make the change as needed that you see different between the two. IIRC it's the relayhost that needs to be set.

Re: Emails not recieved from Nagios

Posted: Fri Jan 08, 2016 4:09 am
by nathanplatt
I've tried copying from the old VM but i still can't get this to work;

Code: Select all

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = nagios
mydomain = nagios.local
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = 192.168.87.114,$mydomain,$myhostname
relayhost = 192.168.87.114
smtp_sasl_auth_enable = no
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

i've had the relayhost as [ipaddress]:25, i've checked and the smtp doesn't require authorisation, if we run the script manually it works. Doesn't make any sense to me? any other ideas?