Page 1 of 1

Passing Host Custom Variables to Service Notifications

Posted: Fri Apr 23, 2021 8:44 am
by dsynapalos
Hello,

I have created a Custom Variable called _location in all of my hosts.
I would like the variable's value to be mentioned in Service Nortifications.

I have edited the Service Alert Message to be as follows, notice the location definition:

Code: Select all

***** Nagios XI Alert *****

%alertsummary%

Notification Type: %type%

Service: %service%
Host: %host%
Location: %location%
Address: %hostaddress%
State: %servicestate%
Info:
%serviceoutput%
Date/Time: %datetime%

Respond: %responseurl%
Nagios URL: %xiserverurl%
My problem is referencing the Services' Host's _location value.
The value cannot be hardcoded in every Service _location custom variable because we have custom Services spanning multiple hosts with different location values. Is it possible to add the dynamic definition in the service custom variable definition? I.E. Name: _location, Value $_HOSTlocation$ ? Perhaps as an environmental variable NAGIOS__HOSTlocation?

If not how should the xi_service_notification_handler command be structured to allow for dynamic on demand host macros? Would the following work?

Code: Select all

/usr/bin/php/user/local/nagiosxi/scripts/handle_nagioscore_notification.php --location="$_HOSTlocation:HOSTNAME$"
Please provide alternatives or assitance.

Re: Passing Host Custom Variables to Service Notifications

Posted: Fri Apr 23, 2021 12:09 pm
by dchurch
You can attach the variable to the host and use it in the service notification handler.

If your Host's Free Variable is called "location", you'll want to use --location="$_HOSTLOCATION$". When executed as a service notification handler, this comes from the host's variables for which the service is currently executing.

Note also that the Free Variable name and the "--[option]" DON'T need to be the same. E.g. You could use --whereami="$_HOSTLOCATION$" so long as you reference it in your notification template as %whereami%.

Here's an example of how to add a Free Variable to a notification template:

1. Set a Free Variable on the host called "mythingy"
2. Modify xi_host_notification_handler under CCM -> Commands, adding --mygroup="$_HOSTMYTHINGY$"
3. Open Admin -> Notification Management, and add a line Group Responsible: %mygroup%

Once you do this, you'll want to "deploy" the notification preferences to the contacts/users affected.

- More about free variables
- Using Free Variables in Notifications

Re: Passing Host Custom Variables to Service Notifications

Posted: Mon Apr 26, 2021 7:09 am
by dsynapalos
Hello, capitalizing the variable name in $_HOSTVARIABLE$ worked as suggested.
Perhaps updating the reference @ https://assets.nagios.com/downloads/nag ... =209668515 helps clear any confusion.

Thank you for your prompt response, you may close the ticket.

Re: Passing Host Custom Variables to Service Notifications

Posted: Mon Apr 26, 2021 7:14 am
by scottwilkerson
dsynapalos wrote:Hello, capitalizing the variable name in $_HOSTVARIABLE$ worked as suggested.
Perhaps updating the reference @ https://assets.nagios.com/downloads/nag ... =209668515 helps clear any confusion.

Thank you for your prompt response, you may close the ticket.
Locking thread