Page 1 of 2

Nagios Notificatin by mail

Posted: Wed Aug 29, 2018 9:51 am
by michaelpn
Hi Nagios,

I have an issue by my mail notification. I do get any mails at the moment still it has worked. I use Nagios Core vers. 4.2.3 on an Linux Ubuntu 14.04. LTS.
I get this from Nagios log when shut down a Server: =>

[1535542909] HOST ALERT: W2012_Tmp;DOWN;SOFT;2;CRITICAL - Host Unreachable (172.31.1.82)
[1535542972] HOST ALERT: W2012_Tmp;DOWN;SOFT;3;CRITICAL - Host Unreachable (172.31.1.82)
[1535543035] HOST ALERT: W2012_Tmp;DOWN;SOFT;4;CRITICAL - Host Unreachable (172.31.1.82)
[1535543098] HOST ALERT: W2012_Tmp;DOWN;SOFT;5;CRITICAL - Host Unreachable (172.31.1.82)
[1535543161] HOST ALERT: W2012_Tmp;DOWN;SOFT;6;CRITICAL - Host Unreachable (172.31.1.82)
[1535543224] HOST ALERT: W2012_Tmp;DOWN;SOFT;7;CRITICAL - Host Unreachable (172.31.1.82)
[1535543287] HOST ALERT: W2012_Tmp;DOWN;SOFT;8;CRITICAL - Host Unreachable (172.31.1.82)
[1535543350] HOST ALERT: W2012_Tmp;DOWN;SOFT;9;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST ALERT: W2012_Tmp;DOWN;HARD;10;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: mpn;W2012_Tmp;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: mpn;W2012_Tmp;DOWN;notify-host-by-sms;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: stn;W2012_Tmp;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: stn;W2012_Tmp;DOWN;notify-host-by-sms;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: mnl;W2012_Tmp;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: mnl;W2012_Tmp;DOWN;notify-host-by-sms;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: jj;W2012_Tmp;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: jj;W2012_Tmp;DOWN;notify-host-by-sms;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: pmk;W2012_Tmp;DOWN;notify-host-by-email;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] HOST NOTIFICATION: pmk;W2012_Tmp;DOWN;notify-host-by-sms;CRITICAL - Host Unreachable (172.31.1.82)
[1535543413] wproc: NOTIFY job 82 from worker Core Worker 4159 is a non-check helper but exited with return code 255
[1535543413] wproc: host=W2012_Tmp; service=(none); contact=stn
[1535543413] wproc: early_timeout=0; exited_ok=1; wait_status=65280; error_code=0;
[1535543413] wproc: stderr line 01: ERROR: No message given as ARGV[1] at /usr/local/bin/sendsms.pl line 27.


Her is my Contacts and Commands: =>

###############################################################################
# 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 SMS NOTIFICATIONS
#
###############################################################################
###############################################################################

# 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 xxx ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Mxxxxx Pxxxxx ; Full name of
pager 05xxxxxx
email [email protected]
host_notification_period 24x7
host_notification_options d,u,r
host_notification_commands notify-host-by-sms,notify-host-by-email
}



define contact{
contact_name xxx ; Short name of user
use generic-contact ; Iherit degault valuses from generic-contact template (defined above)
alias
pager Mxxxxx Nxxxxxx ; Full name of
email [email protected]
host_notification_period 24x7
host_notification_options d,u,r
host_notification_commands notify-host-by-sms,notify-host-by-email
}


define contact{
contact_name xxx ; Short name of user
use generic-contact ; Iherit degault valuses from generic-contact template (defined above)
alias Pxxxx Kxxxx ; Full name of
pager 0045xxxxxx
email [email protected]
host_notification_period 24x7
host_notification_options d,u,r
host_notification_commands notify-host-by-sms,notify-host-by-email
}


define contact{
contact_name xxx ; Short name of user
use generic-contact ; Iherit degault valuses from generic-contact template (defined above)
alias Sxxxx Nxxxxx ; Full name of
pager
email [email protected]
host_notification_period 24x7
host_notification_options d,u,r
host_notification_commands notify-host-by-sms,notify-host-by-email
}


define contact{
contact_name xx ; Short name of user
use generic-contact ; Iherit degault valuses from generic-contact template (defined above)
alias Jxx Jxxxxxx ; Full name of
pager 0045xxxxxx
email [email protected]
host_notification_period 24x7
host_notification_options d,u,r
host_notification_commands notify-host-by-sms,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 xxx, xxx, xxx, xx, xxx
}





###############################################################################
# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS 4.3.2
#
#
# NOTES: This config file provides you with some example command definitions
# that you can reference in host, service, and contact definitions.
#
# You don't need to keep commands in a separate file from your other
# object definitions. This has been done just to make things easier to
# understand.
#
###############################################################################


################################################################################
#
# SAMPLE NOTIFICATION COMMANDS
#
# These are some example notification commands. They may or may not work on
# your system without modification. As an example, some systems will require
# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below.
#
################################################################################


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


# Braintower 'notify-host-by-sms' command definition

define command{
command_name notify-host-by-sms
command_line /usr/local/bin/sendsms.pl $CONTACTPAGER$ "Nagios: $NOTIFICATIONTYPE$ - Host $HOSTALIAS$ is $HOSTSTATE$ since $SHORTDATETIME$ info: $HOSTOUTPUT$"
}


# Braintower 'notify-service-by-sms' command definition


If I use "wich mail" I do get this => nguser@Nagios:~$ which mail
/usr/bin/mail

1: Could anybody tell me how I'm able to check why it doesn't work ?

2: Is there anybody who could tell me if I missing something in my contacts or commands definitions

3: My send sms do work it is only my mail notification which is not working

As I wrote it did work and I did get the mail notifications from the mail users at Nagios in my Inbox Outlook

Best Regards
Michael Pierre Nielsen

Re: Nagios Notificatin by mail

Posted: Wed Aug 29, 2018 11:16 am
by scottwilkerson
I noticed on several of your notification commands you have this

Code: Select all

usr/bin/mail
instead of this

Code: Select all

/usr/bin/mail

Re: Nagios Notificatin by mail

Posted: Wed Aug 29, 2018 11:21 am
by scottwilkerson
Once that is fixed, you would want to chech the maillog on the server

Code: Select all

tail -50 /var/log/maillog

Re: Nagios Notificatin by mail

Posted: Thu Aug 30, 2018 11:09 am
by michaelpn
Hi Scottwikerson,

thanks for your answer. You wrote to me that I have "serveral" notification commands with this "usr/bin/mail" I found one in my:

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

I do only use this cammans right now:

=>

# '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/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

I have used this shell:

=> tail -50 /var/log/mail.log and got this:

=>
###########################################################################################################################
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 707655602BF: from=<[email protected]>, size=707, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 79F395602D9: from=<[email protected]>, size=714, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 7CEA95602C3: from=<[email protected]>, size=708, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 565215602DE: from=<[email protected]>, size=714, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 5FF4B5602BD: from=<[email protected]>, size=623, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 5834B5602C4: from=<[email protected]>, size=708, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 517875602C0: from=<[email protected]>, size=623, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 8B6585602AA: from=<[email protected]>, size=708, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 844DA5602CA: from=<[email protected]>, size=714, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 803A65602BA: from=<[email protected]>, size=623, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 41BDF5602C1: from=<[email protected]>, size=622, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 6FBD75602BE: from=<[email protected]>, size=623, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 6D9005602CD: from=<[email protected]>, size=713, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 60AF75602CC: from=<[email protected]>, size=714, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/qmgr[2172]: 637845602B6: from=<[email protected]>, size=708, nrcpt=1 (queue active)
Aug 30 10:54:10 Nagios postfix/smtp[1486]: 7CEA95602C3: to=<[email protected]>, relay=none, delay=1029, delays=1029/0.02/0/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/smtp[1488]: 565215602DE: to=<[email protected]>, relay=none, delay=1004, delays=1004/0.02/0/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/smtp[1484]: 79F395602D9: to=<[email protected]>, relay=none, delay=1004, delays=1004/0.01/0/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/smtp[1483]: 707655602BF: to=<[email protected]>, relay=none, delay=1029, delays=1029/0.01/0/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/smtp[1490]: 5FF4B5602BD: to=<[email protected]>, relay=none, delay=72003, delays=72003/0.03/0/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/error[1495]: 517875602C0: to=<[email protected]>, relay=none, delay=72003, delays=72003/0.11/0/0.07, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/error[1493]: 5834B5602C4: to=<[email protected]>, relay=none, delay=1029, delays=1029/0.11/0/0.07, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/error[1496]: 8B6585602AA: to=<[email protected]>, relay=none, delay=1029, delays=1029/0.12/0/0.07, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/error[1497]: 844DA5602CA: to=<[email protected]>, relay=none, delay=1004, delays=1004/0.12/0/0.06, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:10 Nagios postfix/error[1500]: 803A65602BA: to=<[email protected]>, relay=none, delay=72003, delays=72003/0.12/0/0.06, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
###########################################################################################################################


I really don't understand because I haven't touched my relay parameter on my Exchange Server:

=>






Aug 30 10:54:11 Nagios postfix/error[1495]: 41BDF5602C1: to=<[email protected]>, relay=none, delay=72003, delays=72003/0.18/0/0.06, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:11 Nagios postfix/error[1500]: 637845602B6: to=<[email protected]>, relay=none, delay=1029, delays=1029/0.18/0/0.06, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:11 Nagios postfix/error[1493]: 6D9005602CD: to=<[email protected]>, relay=none, delay=1004, delays=1004/0.18/0/0.06, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:11 Nagios postfix/error[1496]: 6FBD75602BE: to=<[email protected]>, relay=none, delay=72003, delays=72003/0.18/0/0.06, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)
Aug 30 10:54:11 Nagios postfix/error[1497]: 60AF75602CC: to=<[email protected]>, relay=none, delay=1004, delays=1004/0.18/0/0.06, dsn=4.4.3, status=deferred (delivery temporarily suspended: Host or domain name not found. Name service error for name=fgmail3.fg.dk type=MX: Host not found, try again)



As you see from mail.log it has something to do with Nagios postfix error. What do you propose ?

Do I have to look at some conf files ? and if where ?


Bedst Regards
Michael Pierre Nielsen

Re: Nagios Notificatin by mail

Posted: Thu Aug 30, 2018 12:53 pm
by scottwilkerson
It looks like it is failing to resolve the MX record for the email ending in fgmail3.fg.dk

Does this host exist?

Also, your from address is [email protected] and you should be aware that some mail providers will reject mail if the from address cannot be resolved as well.

Re: Nagios Notificatin by mail

Posted: Thu Aug 30, 2018 1:33 pm
by michaelpn
Hi,
fgmail3.fg.dk is our mail server.

Re: Nagios Notificatin by mail

Posted: Thu Aug 30, 2018 1:42 pm
by scottwilkerson
michaelpn wrote:Hi,
fgmail3.fg.dk is our mail server.
Your nagios server doesn't know how to resolve the MX

do you have the right DNS server

Code: Select all

cat /etc/resolv.conf

Re: Nagios Notificatin by mail

Posted: Fri Aug 31, 2018 7:09 am
by michaelpn
Hi scottwilkerson,

if use that shell I get this:

=>

nguser@Nagios:~$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search fg.dk

That is a localhost address and our nameserver (NS) has this address ad1.fg.dk.

If I use this shell:
=>

cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search fg.dk



And my main.cf looks like this:
=>

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

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = Nagios
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = Nagios.notify, Nagios, localhost.localdomain, localhost
relayhost = fgmail3.fg.dk
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =



I have a strong filing that have to change the nameserver IP 127.0.1.1 to ad1.fg.dk

Please look below:
>>

C:\Users\mpn.FG>nslookup -type=mx domain.com
Server: ad1.fg.dk
Address: 172.31.1.221

Ikke-autoritativt svar:
domain.com MX preference = 10, mail exchanger = mx.domain.com

mx.domain.com internet address = 66.96.140.73
mx.domain.com internet address = 66.96.140.72

C:\Users\mpn.FG>nslookup -type=mx fgmail3.fg.dk
Server: ad1.fg.dk
Address: 172.31.1.221

fg.dk
primary name server = ad1.fg.dk
responsible mail addr = itafd
serial = 34121
refresh = 900 (15 mins)
retry = 600 (10 mins)
expire = 86400 (1 day)
default TTL = 3600 (1 hour)



What do you think ?

How do I change ?

Do you have another pyoposel ?


Bedst Regards

Michael Pierre Nielsen

Re: Nagios Notificatin by mail

Posted: Fri Aug 31, 2018 7:15 am
by scottwilkerson
You need to know the IP address of ad1.fg.dk, and replace XXX.XXX.XXX.XXX with that address

Edit /etc/resolvconf/resolv.conf.d/base

Code: Select all

nameserver XXX.XXX.XXX.XXX
Then run

Code: Select all

sudo resolvconf -u

Re: Nagios Notificatin by mail

Posted: Mon Sep 03, 2018 7:59 am
by michaelpn
Hi scottwilkersson,

thanks :)

If I have to edit the file "base"

I have to use root command to change the file base:

I use vi command => vi /etc/resolvconf/resolv.conf.d/base

If look into the base file I see it is emty!! I think as you wrote to me I have to edit this file so:

put the ip-adrress into the as below written:
=>
nameserver xxx.xxx.x.xx

save the base file and run the command:
=>
sudo resolvconf -u

Is that correct ?

Best Regards

Michael Pierre Nielsen