Passing Host Custom Variables to Service Notifications

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

Passing Host Custom Variables to Service Notifications

Post 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.
dchurch
Posts: 858
Joined: Wed Oct 07, 2020 12:46 pm
Location: Yo mama

Re: Passing Host Custom Variables to Service Notifications

Post 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
If you didn't get an 8% raise over the course of the pandemic, you took a pay cut.

Discussion of wages is protected speech under the National Labor Relations Act, and no employer can tell you you can't disclose your pay with your fellow employees.
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

Re: Passing Host Custom Variables to Service Notifications

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Passing Host Custom Variables to Service Notifications

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked