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
Not able to call custom variables from bash script
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: Not able to call custom variables from bash script
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.
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$)
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
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.
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$"
Introduction to Event Handlers
Let me know if it works now when testing.
Best Regards,
Benjamin
You do not have the required permissions to view the files attached to this post.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!