Page 1 of 1

Passing Macros Into Free Variables

Posted: Fri Sep 24, 2021 12:13 pm
by wneville
Hello,

Does Nagios XI allow for passing custom macros into free variables? For example, we would like to pass a variable from the host to a service. The values are:

host free variables:
"_environment" = "development"
"_owner" = xxxxxxx

service free variables:
"_environment" = "$_HOSTENVIRONMENT"

Tailing /tmp/nagios-send-service-event.txt shows the Service Environment coming through as "$"

However, when we set service free variable "_environment" = "$HOSTOWNER" the Service Environment comes through with the correct Host Owner value. So it seems like the functionality is there to pass a macro through a free variable but for some reason we can't get it to work with the macro we've created ($_HOSTENVIRONMENT). Are custom macros not compatible with this?

Thanks for your time!

Re: Passing Macros Into Free Variables

Posted: Mon Sep 27, 2021 2:40 pm
by benjaminsmith
Hi,

You can pass the free variables assigned at the host level, to services, that will work. However, I just tested this and got similar results ($). I'm not quite sure why it doesn't pass the whole string along without parsing the variable, but that may be a security issue or the parsing rules.

You can pass the free variables assigned at the host level, to services.

What are the requirements? I can try to suggest a workaround.

Thanks,
Benjamin

Re: Passing Macros Into Free Variables

Posted: Tue Sep 28, 2021 10:42 am
by wneville
How do we pass the free variables from the host to the service? Can we do it for just one host free variable and not all?

Re: Passing Macros Into Free Variables

Posted: Tue Sep 28, 2021 3:32 pm
by benjaminsmith
Hi,

Are the free variables being passed to an event handler or plugin? One way to set this up, is to pass the free variable in the command definition. So if the host had a variable set for $_HOSTFREE$ (_free in the CCM), then you would configure the command for the script like,

Code: Select all

$USER1$/event_handler_test.sh $_SERVICEFREE$ $_HOSTFREE$
Every service is associated with a host, so only the free variable assigned for that service's host would be passed.

Hopefully, that helps answer your question. Let us know if you need clarification on anything.

--Benjamin

Re: Passing Macros Into Free Variables

Posted: Wed Oct 06, 2021 11:43 am
by wneville
Hi Benjamin,

We worked it a couple different ways and settled on editing the script we use to send service events to our Event Handler. This way we can pass the $HOSTOWNER$ and $HOSTENVIRONMENT$ through to the service. Thank you for your time and insights.

-Will

Re: Passing Macros Into Free Variables

Posted: Wed Oct 06, 2021 4:42 pm
by benjaminsmith
Hi Will,

Your welcome. Thanks for the update!

We'll go ahead this out, but feel free to open another if you have any new questions.

--Benjamin