Page 1 of 1

Not able to call custom variables from bash script

Posted: Tue Jan 12, 2021 4:17 pm
by ScottMc
I'm running Nagios XI 5.7.3 and I'm struggling trying to get custom variables to pass to the check script via the environment variables.

In short:
- nagios.cfg contains "enable_environment_macros=1"
- Service check contains a free variable "_TEST" with value "Test123"
- check calls a bash script that executes "echo $NAGIOS_SERVICETESTVAR"
- Service detail reads "NAGIOS_SERVICETESTVAR="

I added "( set -o posix ; set ) > /tmp/vars-test.txt" to output the variables from the session and don't see any of the Nagios variables in there.

I have a bunch of templates that feed variables up to hosts and services and we noticed that they apparently stopped working some time ago (I have no idea when since the checks were just passing), but it was before the 5.7 upgrade as well as before implementing mod-gearman for distributed monitoring, so I don't know if either of those changed how this would work or if there's something else I'm overlooking.

Thanks!

Scott

Re: Not able to call custom variables from bash script

Posted: Wed Jan 13, 2021 3:30 pm
by benjaminsmith
Hi Scott,

Let's just make sure the free variables are getting pickup in the configurations, you can check this by going to the free variables tab in the host ot service status details area.
free-variables.png
Next, when you create the command for the bash script, make sure you are passing the free variables to the script as arguments when the event handler gets called. For example, to be able to access the $HOSTNAME$ macro in your script you would pass this argument. The same would apply for a custom variable but the name would be different (i.e $_HOSTMYVAR$)

Code: Select all

$USER1$/event_handler_service_ticket.sh "$HOSTNAME$"
This is outlined on page 15 of the following guide.

Introduction to Event Handlers

Let me know if it works now when testing.
Best Regards,
Benjamin