Page 1 of 2
Nagios Email Notification Setup
Posted: Thu Sep 29, 2016 2:12 pm
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"
[email protected]
HOWEVER i am still not able to get nagios to send emails...
any ideas?
Thanks
Re: Nagios Email Notification Setup
Posted: Thu Sep 29, 2016 4:24 pm
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.
Re: Nagios Email Notification Setup
Posted: Fri Sep 30, 2016 1:25 pm
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
[email protected]
}
# '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
[email protected]
}
# which mail
/usr/bin/mail
Thanks,
Re: Nagios Email Notification Setup
Posted: Fri Sep 30, 2016 2:10 pm
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.
Re: Nagios Email Notification Setup
Posted: Fri Sep 30, 2016 3:01 pm
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
[email protected] ; <<***** 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.
Re: Nagios Email Notification Setup
Posted: Mon Oct 03, 2016 12:01 pm
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.
Re: Nagios Email Notification Setup
Posted: Thu Oct 06, 2016 2:17 pm
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=<[email protected]>, 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: <[email protected]>>)
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: <[email protected]>>)
Oct 6 12:01:22 myserver01 postfix/qmgr[2905]: CE6518023C: removed
Oct 6 12:01:22 myserver01 postfix/cleanup[9223]: 808F28023C: message-id=<[email protected]>
Oct 6 12:01:22 myserver01 postfix/local[9786]: 7F8F88023E: to=<[email protected]>, 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=<[email protected]>, 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,
Re: Nagios Email Notification Setup
Posted: Thu Oct 06, 2016 4:42 pm
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?
Re: Nagios Email Notification Setup
Posted: Thu Oct 06, 2016 4:54 pm
by lmiltchev
Have you changed the "-f
[email protected]" to "-r
[email protected]" in the "notify-host-by-email" and "notify-service-by-email" commands?
Can you try again testing it from the command line?
Check to see if you got the email. If not, show the maillog.
Re: Nagios Email Notification Setup
Posted: Fri Oct 07, 2016 12:32 pm
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
[email protected]
}
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
[email protected] [email protected]
but my checks are still emailing with the localhost from address of the server