set up email alerts using mailx

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.
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

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 197 times
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

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 212 times
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

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 205 times
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked