z

Commercial Support Clients: Clients with support contracts can get escalated support assistance by visiting Nagios Answer Hub. These forums are for community support services. Although we at Nagios try our best to help out on the forums here, we always give priority support to our support clients.

Modifying/Editing Notifications E-mail Body

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.

Modifying/Editing Notifications E-mail Body

Postby dcharles » Tue Oct 21, 2014 1:33 pm

Hello

I was wondering if it was possible to modify the notification emails that Nagios sends out. What we'd like to do specifically, is add a "Location" line in addition to the standard information that Nagios sends out with its notification.

Here is an example:

***** Nagios *****

Notification Type: RECOVERY

Service: rdp
Host: <hostname>
Address: 192.168.105.124
State: OK
Location: NYC Datacenter

Date/Time: Tue Oct 21 08:10:07 EDT 2014

Additional Info:

TCP OK - 0.002 second response time on port 3389

The line in bold is something we'd like to add. I'm aware that involves editing the /usr/local/nagios/etc/objects/commands,cfg file, however I am not sure what the exact syntax would be, or if this is even possible.

Thanks to anyone that can help!

It is greatly appreciated.
dcharles
 
Posts: 10
Joined: Mon Jul 01, 2013 11:39 am

Re: Modifying/Editing Notifications E-mail Body

Postby abrist » Tue Oct 21, 2014 2:22 pm

Edit the notification handler commands to include the location:
Code: Select all
define command {
       command_name                             notify-host-by-email
       command_line                             /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n\nLocation: NYC Datacenter\n\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

Code: Select all
define command {
       command_name                             notify-service-by-email
       command_line                             /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nLocation: NYC Datacenter\n\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
abrist
Red Shirt
 
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Modifying/Editing Notifications E-mail Body

Postby dcharles » Tue Oct 21, 2014 3:37 pm

Thank You so much for the quick response. I think I have a better understanding of the syntax based on my reading of macros and the code in your response.

The problem, however, which I forgot to mention in my original post, is that our hosts are spread across several different locations. So I'd need to add in a variable for the Location name, possibly using the $HOSTGROUPNAME$ macro. I will probably need to perform this by creating new host groups and adding each desired host to its respective group.

So the part I'd need to add would look something like this, I'm guessing:

$\n\nLocation: $HOSTGROUPNAME$

Please correct me if I'm wrong.

Also, if a host is a member of multiple host groups, this raises another question, though: which host group does Nagios display when using the $HOSTGROUPNAME$ macro? I'm assuming it's the very first one listed in the host definition?

Thanks again for your help.
dcharles
 
Posts: 10
Joined: Mon Jul 01, 2013 11:39 am

Re: Modifying/Editing Notifications E-mail Body

Postby abrist » Wed Oct 22, 2014 3:15 pm

dcharles wrote:which host group does Nagios display when using the $HOSTGROUPNAME$ macro?

The first defined in the directive. You could also use free variable macros to do this:
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
abrist
Red Shirt
 
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Modifying/Editing Notifications E-mail Body

Postby dcharles » Thu Oct 23, 2014 11:25 am

Thanks sooo much for your help! This worked perfectly!

Since we are using Check_MK in conjunction with Nagios, I had to add a custom config in order for the parameter to show up for our hosts:

extra_host_conf["_location"] = [
( "NYC-Datacenter", ["loc-nyc-datacent"], ALL_HOSTS),
( "Toronto", ["loc-toronto"], ALL_HOSTS),
]

With this, I can add variables for any region we have our hosts located. Hopefully this can help anyone else who would like to add custom content to the body of their Nagios email alerts.

Thanks again for your help, it is much much appreciated!
dcharles
 
Posts: 10
Joined: Mon Jul 01, 2013 11:39 am

Re: Modifying/Editing Notifications E-mail Body

Postby eloyd » Thu Oct 23, 2014 11:32 am

Custom macros/variables are the best thing since Nagios itself. You can use them to specify anything host or service specific (or contact, for that matter) that you want to do that doesn't already have a variable. Just remember - if you use them for a host/service/contact that doesn't have it defined, odd things may result.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
User avatar
eloyd
Cool Title Here
 
Posts: 2104
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY


Return to Open Source Nagios Projects

Who is online

Users browsing this forum: No registered users and 7 guests