Page 1 of 1
Nagios email alert notification differentiation
Posted: Thu Oct 10, 2013 7:28 pm
by rellegib
Hi,
I've setup another Nagios server and now and I want to be able differentiate between them in the email alerts I see. The email alerts I see now are nagios[
[email protected]]. I would like them to read something like nagios1[
[email protected]] and nagios2[
[email protected]] so I can quickly look at my email and determine which server the alerts came from.
Where would I modify this and how do I do it please?
Thanks for any help you can offer.
Re: Nagios email alert notification differentiation
Posted: Fri Oct 11, 2013 11:59 am
by abrist
In the nagios object file, commands.cfg, you will find 2 notify commands - these are the commands that nagios uses to send email:
Code: Select all
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
You can alter the email by adjusting the body and message of each command. For example:
Code: Select all
define command {
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios Server 1 *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** Nagios Server 1 ** ** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command {
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios Server 1 *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** Nagios Server 1 ** ** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Your commands may be a little bit different than those above, but you should be able to understand the necessary changes.
Re: Nagios email alert notification differentiation
Posted: Fri Oct 11, 2013 12:00 pm
by tmcdonald
Check out your commands.cfg file. You should be able to define a custom command to send out emails, like so:
Code: Select all
/usr/bin/printf "%b" "***** Nagios1 *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mailx -s "** Nagios1 - $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
You can just change "Nagios1" to "Nagios2" or whatever else, and your subject will be:
** Nagios1 - $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **
of course with the macros being filled with their relevant values.
Re: Nagios email alert notification differentiation
Posted: Mon Oct 14, 2013 8:35 pm
by rellegib
Perfect! Thanks Guys!
Re: Nagios email alert notification differentiation
Posted: Tue Oct 15, 2013 11:50 am
by slansing
Keep us apprised!