Concerning my issues with "Free (custom) variables"

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.
Locked
ashleydrees
Posts: 27
Joined: Tue Apr 12, 2011 3:37 am

Concerning my issues with "Free (custom) variables"

Post by ashleydrees »

I am trying to get a "Free variable" to work - i am using what i believe to be the latest core VM available to me - Nagios® Core™ Version 4.0.7 June 03, 2014, i have failed at the first hurdle as i cannot get even one to work.

The first thing i was trying to do is the following, in a command pass a Free (custom) variable to the check script.

I set (first of all) "_remoteport" in my host template and applied that to the host, as that did not work i then set _remoteport in the host directly - i have checked, BOTH are in the config files.. i then tried to use this as the check command line.

$USER1$/check_ncpa.py -H $HOSTADDRESS$ -P $_HOSTREMOTEPORT$ -t myhiddenkey $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$

The script returns

"COMMAND: /usr/local/nagios/libexec/check_ncpa.py -H xxx.xxx.xxx.xxx -P $_HOSTREMOTEPORT$ -t myhiddenkey -M cpu/percent"

Which of course will never work... i cannot get it to work with the variable placed in the host template nor the host config file itself, and CCM IS putting the variable and value in the .cfg files... if i set the check to use $ARG1$ and put my port number in there it works fine.

Nagios.cfg has:-
use_large_installation_tweaks=0
enable_environment_macros=1

Watching the logs on the nagios core server i see the following when i run the above command... seems that the macro is not being replaced with the value at all.
Usage: check_ncpa.py [options]
check_ncpa.py: error: option -P: invalid integer value: '$'

I have found:-
http://tracker.nagios.org/view.php?id=498
https://support.nagios.com/forum/viewto ... =7&t=12040

which i wonder are related.

Am i doing something stupid or am i doing something stupid? If anyone can give a pointer or at least a pointer to the Core documentation online i would be grateful.

I am a bit hamstrung at the moment as i cannot get to the main documentation as the sourceforge documentation seems offline still.
Last edited by ashleydrees on Mon Jul 20, 2015 2:50 am, edited 1 time in total.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: concerning my inability to get a "Free (custom) variable

Post by Box293 »

ashleydrees wrote:I am a bit hamstrung at the moment as i cannot get to the main documentation as the sourceforge documentation seems offline still.
Yes this is frustrating.

What Core VM are you using, Pro or Student?

I tested what you are going using the Pro VM and it all works. You have everything configured as expected.

I made all the changes through CCM http://ipaddress/ccm

Have a look at the file /usr/local/nagios/var/objects.cache as this is the running config and will show the free variable definition.

Give us some steps that you are performing so we can try and reproduce.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
ashleydrees
Posts: 27
Joined: Tue Apr 12, 2011 3:37 am

Re: concerning my inability to get a "Free (custom) variable

Post by ashleydrees »

Using Pro Nagios® Core™ Version 4.0.7 June 03, 2014.

I made all my changes using CCM, first time i put the variable in the host template, then i put it in the host itself.

The Variable is visible in the /usr/local/nagios/var/objects.cache file in all the hosts i expect it to be.

To add the variable.

1, open CCM
2, open host template
3, navigate to the misc settings / manage variable definitions
4, add the variable with an underscore to the variable definitions
5, run the save/write/reload process.
6, test command (which uses the variable) with host

I checked using a shell, the variable is always in the host.cfg and the host template.cfg - it is showing the correct value in the cache file and it seems to be in the right format with the underscore at the beginning of the variable name. I have rebooted the machine, i have re-applied the possible update that is available ATM.

From the cache file.
_NATPORT 5694
_REMOTEPORT 5694

(i created a second variable/_name just in case i was getting into trouble with an existing variable although i believe the underscore is to stop that happening)

The inheritance is also working as i expected with the hosts using generic-host-template having the expected value and the custom host having the altered value having what i expect.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Concerning my issues with "Free (custom) variables"

Post by tmcdonald »

For the record, Google's cache works wonders for when sites go down: http://webcache.googleusercontent.com/s ... clnk&gl=us

Let's get some debugging going and see what we can find. In your nagios.cfg, set debug_level=-1 and restart nagios. Wait long enough for a check with the custom variable to be run, then stop nagios, set debug_level=0 again and start nagios back up. Then send us your /usr/local/nagios/var/nagios.debugfile, either directly shared here or in a PM to myself or another member of the team.
Former Nagios employee
ashleydrees
Posts: 27
Joined: Tue Apr 12, 2011 3:37 am

Re: Concerning my issues with "Free (custom) variables"

Post by ashleydrees »

OK, before we go any further with the debug, i need to check something with you all.

I had not activated the check as i was testing it from the host section of CCM, and did not want to start getting a load of failures... on further investigating and because you wanted the debug log, i enabled the check using the command variant that used the free/custom variable that i wanted to use. It worked, i was not expecting that but it did, so i enabled it for a host group - and that seems to be working too.

SO, my question is, should i be able to test a host from CCM with the test command "button" or will the free/custom variables NOT present themselves if i run it that way?

If the variable is not presented when running from the CCM interface, how am i meant to test commands ? make them live and watch?

Unfortunately, i need to clean up some of my config files as this is showing my host groups are badly thought out, i will keep you informed and hopefully you will explain how i can test these commands from within CCM or that i should not as the custom variables do not present themselves there.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Concerning my issues with "Free (custom) variables"

Post by tmcdonald »

Update: It appears the CCM does have some limited ability to resolve macros. I am speaking with the developers right now to get clarification. I suspect there is a hard-coded list of macros that the CCM can resolve when using the Test Check Command button.

Update 2: I think I'm right here. I changed my test command to use $HOSTALIAS$ instead, and tried - this time it showed similar results to using a custom variable. However when the check ran organically, it resolved properly.

---

Ahhh, I didn't realize that step 6 above was using the Test Command button (should have been obvious by the "COMMAND:" output).

Your assumptions are correct, using the Test Command button will not respect the macros. Those macros are expanded when nagios runs the check naturally, as opposed to the Test Command button which runs the plugin directly through PHP (which does not have access to the macros nor would it know what to do with them if it did).

For reference, I made a command that just does echo "Hello $_HOSTREMOTEPORT$ world!" and then gave a random host the _remoteport variable with the value 1234 and ran the test command. These are my results:
2015-07-20 16_14_27-Nagios XI - Nagios Core Config Manager.png
2015-07-20 16_14_27-Nagios XI - Nagios Core Config Manager.png (3.79 KiB) Viewed 5125 times
Does this match up with what you are seeing? The condensing of the $_HOSTREMOTEPORT$ macro into a single $ is due to PHP failing to find a variable named $_HOSTREMOTEPORT and then reporting the remaining dollar sign as a literal.

If so, then unfortunately yes - the proper way to test is to save and let it run. There are a few known flaws with the Test Command button, and this is one of them.
Former Nagios employee
ashleydrees
Posts: 27
Joined: Tue Apr 12, 2011 3:37 am

Re: Concerning my issues with "Free (custom) variables"

Post by ashleydrees »

Yes, the above is exactly what i am seeing, but it is OK; after three or four days of fretting about this, i have it doing what i want.

It would have speeded up this process if the "results" pop up in CCM "testing" a command string had some kind of warning about the variables in the main execution thread not being available in the "test command" (php) button (or the test somehow managed to use all available macros and variables), but i understand completely what is happening now, and thanks for your time. I guess i will have to be very careful that i do not send out lots of spurious messages when i am testing a new site or command setup.

:)

PS. it would be good to know where this is documented in the CORE docs, i am certain that this issue will raise its head again, or already has.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Concerning my issues with "Free (custom) variables"

Post by tmcdonald »

Documentation for this will likely never make it into the Core docs, since it is not technically a Core feature. It's the CCM on top of Core (which is taken from XI) that handles this, so it would probably be documented in the XI docs if anything. As for popping up a warning or otherwise letting people know the Test Check Command button is flawed, I have been barking up that tree for a while - it's up to the devs whether or not it gets in.

And you can always turn off notifications for a service while you are testing, then turn them back on when you have it working how you would like.

Are we all set to close this thread?
Former Nagios employee
ashleydrees
Posts: 27
Joined: Tue Apr 12, 2011 3:37 am

Re: Concerning my issues with "Free (custom) variables"

Post by ashleydrees »

sorry, yes, please close this thread.
Locked