set up email alerts using mailx

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Re: set up email alerts using mailx

Postby nib01 » Fri Jan 25, 2019 12:32 pm

I checked the nagios.cfg config file and confirmed that it's set to "enable_notifications=1 "

The commands and services it seem to be working as shown in nagios.log, except the email Notification alerts.

See attached nagios.log
Attachments
nagios.log
(525.81 KiB) Downloaded 45 times
nib01
 
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Postby tgriep » Fri Jan 25, 2019 1:41 pm

Both of the email commands that you have defined have errors in them and that is causing them to fail
Edit this command
Code: Select all
notify-service-by-email


Change the command line from

Code: Select all
/usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\n\Notification Type: $NOTIFICATIONTYPE$\n\nHost: $HOSTNAME$\n\nState: $HOSTSTATE$\n\nAddress: $HOSTADDRESS$\n\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -S smtp=mailrelay.int.company.com -S from=alerts.gainspeed@company.com $CONTACTEMAIL$

to
Code: Select all
/usr/bin/printf "%b" "***** Nagios Monitor Core Alert*****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nHost: $HOSTNAME$\n\nState: $HOSTSTATE$\n\nAddress: $HOSTADDRESS$\n\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -S smtp=mailrelay.int.company.com -S from=alerts.gainspeed@company.com $CONTACTEMAIL$

Edit this command
Code: Select all
notify-host-by-email

Change the command line from

Code: Select all
/usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\n\Notification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n\nHost: $HOSTALIAS$\n\nAddress: $HOSTADDRESS$\n\State: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nnAdditional Info:\n\n$SERVICEOUTPUT$\" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -S smtp=mailrelay.int.company.com -S from=alerts.gainspeed@company.com $CONTACTEMAIL$

to
Code: Select all
/usr/bin/printf "%b" "***** Nagios Monitor Core Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n\nHost: $HOSTALIAS$\n\nAddress: $HOSTADDRESS$\n\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -S smtp=mailrelay.int.company.com -S from=alerts.gainspeed@company.com $CONTACTEMAIL$


Save it and restart nagios and test the sending of notifications.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 8212
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Postby nib01 » Fri Jan 25, 2019 4:51 pm

If you look at the previous commands.cfg file in this thread, already contains the following commands . Please see attached commands.cfg file.

"notify-service-by-email"

"notify-host-by-email"


Could you explain to me more what do you mean by "Edit this command" and "Change the command line from"?

Thanks!
Attachments
commands.cfg
(7.42 KiB) Downloaded 47 times
nib01
 
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Postby tgriep » Mon Jan 28, 2019 10:23 am

Your commands that send the emails have errors in then so they need to be edited.
What I mean by Change it from , to us to edit the command line and change it from the wrong command to the corrected.
I edited the commands for you so if you replace your commands.cfg file with the one that is attached to the post, it should fix the errors.
Attachments
commands.cfg
(7.16 KiB) Downloaded 58 times
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 8212
Joined: Thu Oct 30, 2014 9:02 am

Previous

Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 13 guests