Nagios Email Notification Setup

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.
scheema31
Posts: 90
Joined: Wed Jun 06, 2012 1:11 pm

Nagios Email Notification Setup

Post by scheema31 »

I have installed a fresh copy of Nagios 4.0.8, got my services and host and all other needed configs migrated (nagios 4.0.8 was running on rhel 5, now i have installed rhel 7, installed fresh nagios and migrate configs from rhel 5)
I can browse the webpage and see my services being checked.
i have installed postfix as the mail solution, i have edited the postfix config to include a relay address, i can also successfully send a message from the server using command "echo "test message" | mail -s "some subject" user1@domain1.com
HOWEVER i am still not able to get nagios to send emails...
any ideas?

Thanks
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios Email Notification Setup

Post by rkennedy »

Could you post your command definitions for notify-host-by-email and notify-service-by-email, and also a host / service definition that should be sending a notification?

Then, post the output of which mail as this will be the directory we want to reference in those notify commands.
Former Nagios Employee
scheema31
Posts: 90
Joined: Wed Jun 06, 2012 1:11 pm

Re: Nagios Email Notification Setup

Post by scheema31 »

define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "* Nagios Host *\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$ -- -f PRODNAGIOS@mydomain.net
}

# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "* Nagios Services *\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -- -f PRODNAGIOS@mydomain.net
}

# which mail
/usr/bin/mail

Thanks,
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Nagios Email Notification Setup

Post by mcapra »

Have you assigned contacts to any hosts/services that you would like to be notified?

It also looks like your command definitions are missing a / in their call to /usr/bin/mail. Fixing that should be helpful.
Former Nagios employee
https://www.mcapra.com/
scheema31
Posts: 90
Joined: Wed Jun 06, 2012 1:11 pm

Re: Nagios Email Notification Setup

Post by scheema31 »

Yes I have assigned contacts.
Here is my command:
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias System Admin ; Full name of user
email prodbay@mydomain.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

define contactgroup{
contactgroup_name admins
alias Systems Administrators
members nagiosadmin
}
And i also made the change to /usr/bin/mail, but did not help.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios Email Notification Setup

Post by lmiltchev »

Run the following commands, and show the output in code wraps:

Code: Select all

grep NOTIFICATION /usr/local/nagios/var/nagios.log
tail -100 /var/log/maillog
ps -ef | grep postfix | grep -v grep
man mail | head -2
BTW, with sendmail, you can use "-f <from address>" in your command. With mailx, however you use "-r <from address>". You may need to modify your command if you are using mailx.
Be sure to check out our Knowledgebase for helpful articles and solutions!
scheema31
Posts: 90
Joined: Wed Jun 06, 2012 1:11 pm

Re: Nagios Email Notification Setup

Post by scheema31 »

hey thanks for the update,
so i have updates coming in but seems like random, i sent a custom email but not receiving that one.
here is the output from commands:

Code: Select all

[root@myserver01 ~]# grep NOTIFICATION /usr/local/nagios/var/nagios.log
[1475779819] EXTERNAL COMMAND: ENABLE_NOTIFICATIONS;1475779819
[1475779840] SERVICE NOTIFICATION: Urgent;SV-VMHOST-01.local;Datastore OfficeSAN02_1_FAST;CRITICAL;notify-service-by-email;CRITICAL - /usr/local/nagios/libexec/check_vmfs.sh: line 161: --username: command not found
[1475779902] SERVICE NOTIFICATION: Urgent;server.local ;Datastore VM-10GDATASTORE-3;CRITICAL;notify-service-by-email;CRITICAL -
[1475779902] SERVICE NOTIFICATION: Urgent;server.local;Datastore VM-10GDATASTORE-3;CRITICAL;notify-service-by-email;CRITICAL - /usr/local/nagios/libexec/check_vmfs.sh: line 161: --username: command not found
[1475779967] SERVICE NOTIFICATION: Urgent;server.local;Datastore VM-10GDATASTORE-3;CRITICAL;notify-service-by-email;CRITICAL -
[1475779967] SERVICE NOTIFICATION: Urgent;server.local;Datastore VM-10GDATASTORE-1;CRITICAL;notify-service-by-email;CRITICAL - /usr/local/nagios/libexec/check_vmfs.sh: line 161: --username: command not found

Code: Select all

[root@myserver01 ~]# tail -100 /var/log/maillog
Oct  6 12:01:22 myserver01 postfix/bounce[9226]: CE6518023C: sender non-delivery notification: 7F8F88023E
Oct  6 12:01:22 myserver01 postfix/qmgr[2905]: 7F8F88023E: from=<>, size=3087, nrcpt=1 (queue active)
Oct  6 12:01:22 myserver01 postfix/smtp[9225]: D030C8022D: to=<myserver@fp.bay.net>, relay=smtp [10.10.#.#]:25, delay=4.7, delays=0.05/0/4.6/0.04, dsn=2.0.0, status=sent (250 Ok, message saved <Message-ID: <20161006190117.D030C8022D@myserver01.localdomain>>)
Oct  6 12:01:22 myserver01 postfix/smtp[9225]: D030C8022D: to=<prod.bay@local>, relay=smtp.[10.10.#.#]:25, delay=4.7, delays=0.05/0/4.6/0.04, dsn=2.0.0, status=sent (250 Ok, message saved <Message-ID: <20161006190117.D030C8022D@myserver01.localdomain>>)
Oct  6 12:01:22 myserver01 postfix/qmgr[2905]: CE6518023C: removed
Oct  6 12:01:22 myserver01 postfix/cleanup[9223]: 808F28023C: message-id=<20161006190122.808F28023C@myserver01.localdomain>
Oct  6 12:01:22 myserver01 postfix/local[9786]: 7F8F88023E: to=<nagios@myserver01.localdomain>, relay=local, delay=0.02, delays=0/0/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
Oct  6 12:01:22 myserver01 postfix/bounce[9784]: D030C8022D: sender non-delivery notification: 808F28023C
Oct  6 12:01:22 myserver01 postfix/qmgr[2905]: D030C8022D: removed
Oct  6 12:01:22 myserver01 postfix/qmgr[2905]: 7F8F88023E: removed
Oct  6 12:01:22 myserver01 postfix/qmgr[2905]: 808F28023C: from=<>, size=3074, nrcpt=1 (queue active)
Oct  6 12:01:22 myserver01 postfix/local[9240]: 808F28023C: to=<nagios@myserver01.localdomain>, relay=local, delay=0.02, delays=0.01/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Oct  6 12:01:22 myserver01 postfix/qmgr[2905]: 808F28023C: removed

Code: Select all

[root@myserver01~]# ps -ef | grep postfix | grep -v grep
root      2873     1  0 11:25 ?        00:00:00 /usr/libexec/postfix/master -w
postfix   2903  2873  0 11:25 ?        00:00:00 pickup -l -t unix -u
postfix   2905  2873  0 11:25 ?        00:00:00 qmgr -l -t unix -u

Code: Select all

[root@svprodmon01 ~]# man mail | head -2
MAILX(1)                            User Commands                            MAILX(1) 


Thanks,
Last edited by avandemore on Thu Oct 06, 2016 3:47 pm, edited 1 time in total.
Reason: Added code blocks
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios Email Notification Setup

Post by Box293 »

scheema31 wrote:so i have updates coming in but seems like random, i sent a custom email but not receiving that one.
How did you send a custom email?

Does "Send custom service notification" from the services page work?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios Email Notification Setup

Post by lmiltchev »

Have you changed the "-f PRODNAGIOS@mydomain.net" to "-r PRODNAGIOS@mydomain.net" in the "notify-host-by-email" and "notify-service-by-email" commands?

Can you try again testing it from the command line?

Code: Select all

echo "test message" | mail -s "some subject" -r PRODNAGIOS@mydomain.net user1@domain1.com
Check to see if you got the email. If not, show the maillog.
Be sure to check out our Knowledgebase for helpful articles and solutions!
scheema31
Posts: 90
Joined: Wed Jun 06, 2012 1:11 pm

Re: Nagios Email Notification Setup

Post by scheema31 »

yes i have added the -r option, here is my command
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "* Nagios Host *\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$ -- -r PRODNAGIOS@domain.com
}
and YES i can send the email from command line and email gets sent with correct from address,
#echo "test message" | mail -s "some subject" -r PRODNAGIOS@mydomain.net scheema@bayleaf.com

but my checks are still emailing with the localhost from address of the server
Locked