Page 4 of 4

Re: set up email alerts using mailx

PostPosted: Fri Jan 25, 2019 12:32 pm
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

Re: set up email alerts using mailx

PostPosted: Fri Jan 25, 2019 1:41 pm
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.

Re: set up email alerts using mailx

PostPosted: Fri Jan 25, 2019 4:51 pm
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!

Re: set up email alerts using mailx

PostPosted: Mon Jan 28, 2019 10:23 am
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.