Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
I have written a bash script to get the authorization header token to be written to the /usr/local/nagios/etc/resource.cfg file. The bash script works fine and in the resource.cfg the token value is saved as below,
ACCESS_TOKEN="Authorization: Bearer 38255d19-724a-4e2c-b8bc-1234retff13"
When configuring the nagios service I need to read the authorization header from the above file.
I'd write a wrapper script in Bash (or PHP, Python, Perl, whatever) to evaluate ACCESS_TOKEN then plug it into a call to check_http. That wrapper script would then become your check_command. This doesn't require the usage of resource.cfg if your wrapper script evaluates the token then plugs it into the execution's -k argument directly.
Thanks for the reply. I manage to get it working. I need to refresh the access token every 60 mins. So I have scheduled a cron job to be run, every 55mins to retive a new access token and save it in resource.cfg as a $USER8$ macro. But it seems nagios caches the resource.cfg file. even the resource.cfg macro value gets overridden by the new value every 60mins, the command picks the old value (the one which was there when nagios server was started )
Can I know a way to tackle this issue?
Thank you.
What command did you use to eventually get this to pull the value? Tests on my lab machine show Nagios picking up changes to the config file nearly instantly.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
The test I was running was actually on XI and it was reading the resources.cfg for the test function but not for the actual check. Sorry for the confusion! The service does need to be restarted in order to load resources.cfg again.
That said, you could instead use a Linux environment variable in the command. And instead of the cronjob updating the macro it would update the environment variable.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
I had trouble, loading the environmental variable in the check command. Can you guide me on how I can update the command to use the environmental variable value?
You would probably have more luck using the environment variable in the plugin script itself rather than in the command line, due to the way Nagios handles macros (which also start with a $). Simply referencing something like $HOME or $PWD in your bash script should suffice to access those two environment variables, for example.