Host Custom Variables problem

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Fred Kroeger
Posts: 588
Joined: Wed Oct 19, 2011 11:36 pm
Location: Perth, Western Australia
Contact:

Host Custom Variables problem

Post by Fred Kroeger »

I'm having problems trying to pass a custom Host variable in a Service Check.
I have defined _AWS_Instance ID in a host entry
(I've removed the hostname/ IP etc. in this listing)

Code: Select all

define host {
        host_name                       ServerA
        _AWS_InstanceID                 i-c58a9a0a
        register                        1
        }
In the Service Check I have tried to reference this variable but all that I get when it's passed to my script is "$"

Code: Select all

define service {
        host_name                       ServerA
        service_description             Check Instance Scheduled Events
        check_command                   check_instance_status!asg-txt!$_HOSTAWS_InstanceID$!$HOSTNAME$!!!!!
        register                        1
        }
I have even tried to embed the variable in the command as well as the above - it also returns a '$"

Code: Select all

define command {
       command_name                             check_instance_status
       command_line                             $USER3$/AWS/check_instance_status.sh $ARG1$ $_HOSTAWS_InstanceID$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$
}
So given the above I would expect the following to be executed

Code: Select all

$USER3$/AWS/check_instance_status.sh asg-txt i-c58a9a0a i-c58a9a0a SERVERA
I have added the following line to the start of my check_instance_status.sh script

Code: Select all

echo $* >> /tmp/event-status.log
This is what I see in the log

Code: Select all

asg-txt $ $ ServerA
I've tried different variable names, etc. - but they all produce the same result.
I am using NagiosXI 2014 R2.3
Any ideas ?

regards... Fred
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Host Custom Variables problem

Post by Box293 »

I'm thinking CaSe is important. Try:

Code: Select all

$_HOSTAWS_INSTANCEID$
Thats how the examples are shown here:
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html

If that doesn't work turn on debugging and that should shed some more light.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
questrad
Posts: 160
Joined: Wed Mar 21, 2012 3:08 pm
Location: Toronto
Contact:

Re: Host Custom Variables problem

Post by questrad »

Can you please executed following and check if you have those variable in objects.cache.

Code: Select all

cat /usr/local/nagios/var/objects.cache | sed -rn "/define host \{/{:a;N;/}/{/.AWS_InstanceID/p;d};ba}"
cat /usr/local/nagios/var/objects.cache | sed -rn "/define service \{/{:a;N;/}/{/.AWS_InstanceID/p;d};ba}"
Try as well the upper case, as @Box293 suggested.
In my configuration everything is UPPER CASE, so, and everything is working. (did not tried using mixed cases)
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Host Custom Variables problem

Post by lmiltchev »

Any updates, Fred? Have you tried using uppercase? Did it work for you?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Fred Kroeger
Posts: 588
Joined: Wed Oct 19, 2011 11:36 pm
Location: Perth, Western Australia
Contact:

Re: Host Custom Variables problem

Post by Fred Kroeger »

I changed the Variable name to uppercase on one of the Hosts and it works correctly for that host.
The problem was in fact that you can't use lowercase characters in the Custom Variable Name ! That caught me by surprise!

I did check the objects.cache as suggested but nothing was returned if I used the old variable name or the all-uppercase variable name.

Thanks all for your time and suggestions to resolve this.

regards... Fred
questrad
Posts: 160
Joined: Wed Mar 21, 2012 3:08 pm
Location: Toronto
Contact:

Re: Host Custom Variables problem

Post by questrad »

I did check the objects.cache as suggested but nothing was returned if I used the old variable name or the all-uppercase variable name.
It is strange.
So, you said you have changed it in to UPPERCASE.
Can you do following:

Code: Select all

cat /usr/local/nagios/var/objects.cache | sed -rn "/define host \{/{:a;N;/}/{/.YOUR_UPPER_CASE_VARIABLE/p;d};ba}"
cat /usr/local/nagios/var/objects.cache | sed -rn "/define service \{/{:a;N;/}/{/.YOUR_UPPER_CASE_VARIABLE/p;d};ba}"
This must give you output of those hosts and services that has the YOUR_UPPER_CASE_VARIABLE variable.
You can use that objects.cache to troubleshooting and finding any miss configuration that can be happened with NagiosXI.
objects.cache - it is exactly the cache of configuration that used Nagios Core, if otherwise you have disabled it or configured to be in other place

http://nagios.sourceforge.net/docs/3_0/configmain.html
Object Cache File
Format: object_cache_file=<file_name>
Example: object_cache_file=/usr/local/nagios/var/objects.cache
This directive is used to specify a file in which a cached copy of object definitions should be stored. The cache file is (re)created every time Nagios is (re)started and is used by the CGIs. It is intended to speed up config file caching in the CGIs and allow you to edit the source object config files while Nagios is running without affecting the output displayed in the CGIs.
Fred Kroeger
Posts: 588
Joined: Wed Oct 19, 2011 11:36 pm
Location: Perth, Western Australia
Contact:

Re: Host Custom Variables problem

Post by Fred Kroeger »

Oh dear... you can tell it's getting the end of the day...
I blindly did a copy/paste of your command - of course my object.cache resides on my ramdisk!

So yes - I can see 1 host defined with _AWS_INSTANCEID when I run the check now on object.cache.
Interestingly , even though I still have defined _AWS_Instance-ID on some other hosts , they appear as _AWS_INSTANCE-ID in object.cache.

So you can use lowercase when defining the custom variable names - you need to remember that they are mapped to uppercase when you apply the configuration.

Thanks for the tip ... Fred
cmerchant
Posts: 546
Joined: Wed Sep 24, 2014 11:19 am

Re: Host Custom Variables problem

Post by cmerchant »

Its Ok, Fred. Its too early for me to make sense of case insensitivity. We'll go ahead and close this thread. Thanks.
Locked