Page 1 of 1

Free variable definitions

Posted: Sat Nov 29, 2014 2:56 pm
by reincarne
Hi,
Is there a clear explanation of how to use Free variable definitions? What is it good for? Some example?

Thanks.

Re: Free variable definitions

Posted: Sun Nov 30, 2014 10:31 pm
by Box293
There are many different ways to use free variables, here's just one example :

I am running some VMware Guest checks
The plugin requires the name of the Guest (as named in the vSphere inventory) for the --guest argument
I have three separate guest checks (memory, cpu, disk)
So in three separate services I need to provide the name of the Guest.
And that’s just for one Guest. What if I'm monitoring 50 guests. That's 150 service definition entries.

So what I could do is create a free variable in the HOST object.
It needs to be named beginning with an underscore
So we'll call it _GUESTNAME
And in the variable we've given it the value "File Server Production"
Now that can be referenced as a macro using $_HOSTGUESTNAME$
It looks confusing but host macros are referneced as $_HOST followed by the free variable without the underscore and ending with $

So now, in my service definition, instead of populating one of the $ARGx$ fields with the name of the guest, I could use $_HOSTGUESTNAME$ instead. I do this to all three service definitions.
To extend that further, I could assign that service to a host group instead of directly to a host. That host group ONLY has hosts that have that _GUESTNAME free variable defined.
So in the future, every time I add a new host to that host group, it will automatically get those three guest services.
So instead of three guest service definitions per host, we have just three guest service definitions for ALL hosts in the host group.

Does this make sense?

Here's some more reading on it:
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html

Re: Free variable definitions

Posted: Mon Dec 08, 2014 10:15 am
by reincarne
I'm not sure I understood you :/
I will need to test it somehow to understand it.

Re: Free variable definitions

Posted: Mon Dec 08, 2014 12:42 pm
by lmiltchev
Another document that can help you how you can use custom variables is this one:

http://assets.nagios.com/downloads/nagi ... iables.pdf

Check the "Using Custom Host Macros In Notifications" section. Hope this helps.

Re: Free variable definitions

Posted: Mon Dec 08, 2014 6:33 pm
by Box293
Have a play and then let us know what you need explaining. Remember there are no silly questions.

Re: Free variable definitions

Posted: Wed Dec 10, 2014 2:33 am
by reincarne
According to the document you provided it looks very simple, but as I see it, they are talking about static variable, which can be then used in message notifications.
What if I want to make a dynamic variable? is there a way to do that?

Now I have another question related to macros.
Let's set I want to make an http check for 100 servers. The check shout test this site http://www.something.com/{Variable}
Is there a way to do that? I mean, can I define a variable definition like that: _landingpage ==> 1212.html
And then in the check itself, it will be something like that: http://www.something.com/$_SERVICELANDINGPAGE$
Is that possible?

Re: Free variable definitions

Posted: Wed Dec 10, 2014 12:48 pm
by slansing
Yep, that is what Box was mentioning, you will want the host address to remain constant (URL of the site), then define that additional variable on the host object in the CCM, depending on your command definition you may need to duplicate the command, then append the new variable onto it in the correct location. The following definition is just an example:

Code: Select all

$USER1$/check_http -H $HOSTADDRESS$/$ARG1$
Then on each service check, in the ARG1 slot, you can give it something like:

Code: Select all

$_HOSTLANDINGPAGE1$
Or:

Code: Select all

$_HOSTLANDINGPAGE2$
For whatever page they are supposed to be checking. Hopefully that makes things a bit more clear.