Nagios Email Notification Setup
Nagios Email Notification Setup
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
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
Re: Nagios Email Notification Setup
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.
Then, post the output of which mail as this will be the directory we want to reference in those notify commands.
Former Nagios Employee
Re: Nagios Email Notification Setup
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,
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,
Re: Nagios Email Notification Setup
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.
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/
https://www.mcapra.com/
Re: Nagios Email Notification Setup
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.
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.
Re: Nagios Email Notification Setup
Run the following commands, and show the output in code wraps:
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.
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
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Nagios Email Notification Setup
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:
Thanks,
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
Reason: Added code blocks
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Nagios Email Notification Setup
How did you send a custom email?scheema31 wrote:so i have updates coming in but seems like random, i sent a custom email but not receiving that one.
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.
Re: Nagios Email Notification Setup
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?
Check to see if you got the email. If not, show the maillog.
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
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Nagios Email Notification Setup
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
# '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