Including Custom Variables in Notification

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
jtata
Posts: 47
Joined: Thu Sep 02, 2010 12:27 pm

Including Custom Variables in Notification

Post by jtata »

I've added a custom variable to my host definitions denoting the SLA level of covering the host. I would like to include this information in notifications so the on call techs no how urgent a given alert is, but I can't seem to get this working.

My notification command looks like this:

Code: Select all

/usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTNAME$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $_HOSTSLATYPE$ $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
I have tried defining the custom variable _SLATYPE both in a template as well as directly in a host definition and but when I generate an alert the subject of the email looks like
RECOVERY Service Alert - MYHOSTNAME/MY SERVICE NAME is OK
the SLA type is not included.

I also tried defining the same variable directly in the service and referencing it as _SERVICESLATYPE but got the same results.

Is there a trick I am missing to sending custom variable macros in notifcations or can this not be done?
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Including Custom Variables in Notification

Post by mguthrie »

I would check out the Nagios Core documentation for more info on this one.

http://nagios.sourceforge.net/docs/3_0/macros.html - look for the custom variables section

http://nagios.sourceforge.net/docs/3_0/ ... tvars.html


See if that has your answer, if not let us know and we'll take a closer look at it. I haven't used custom variables myself so I'd have to do some hunting...
jtata
Posts: 47
Joined: Thu Sep 02, 2010 12:27 pm

Re: Including Custom Variables in Notification

Post by jtata »

Thanks, but I actually read both those documents thoroughly before I posted my original question. According to them I should be able to create the variable by adding _slatype to the host's .CFG file (this is actually done in the Misc section of the hosts properties in CCM, and apparently the xi_wizard templates make use of this funcitonality for some purpose because there is already a property there).

I've checked the actually .CFG for my test host and confirmed that _slatype exists and has the value PRODUCTION, just like in the example. So we know the problem isn't with CCM not writing the data correctly. I should be able to reference it with $_HOSTSLATYPE$ in my macro definition but this is where things are breaking down. My notificaiton command should include the value PRODUCTION in front of the hostname, but it doesn't. So it looks like I'm either formatting my macro string wrong, or its being ignored for some reason.
TSCAdmin
Posts: 155
Joined: Wed Apr 14, 2010 3:00 pm
Location: India

Re: Including Custom Variables in Notification

Post by TSCAdmin »

I'm using custom variables with our processing (but I've completely replaced the notification email script with a python/SOAP automated ticket generation program with our service desk) without issues at the moment.

I hate to ask an obvious question, but after you changed the notification command, did you re-apply the configuration? In other words, what's the notify command look like in your commands.cfg file?
jtata
Posts: 47
Joined: Thu Sep 02, 2010 12:27 pm

Re: Including Custom Variables in Notification

Post by jtata »

First rule of troubleshooting: take nothing for granted. :)

Double checked my commands.cfg, looks like its applying:

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: $HOSTNAME$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $_HOSTSLATYPE$ $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Locked