Free variable definitions

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
reincarne
Posts: 146
Joined: Wed Jun 26, 2013 4:39 am

Free variable definitions

Post by reincarne »

Hi,
Is there a clear explanation of how to use Free variable definitions? What is it good for? Some example?

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

Re: Free variable definitions

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
reincarne
Posts: 146
Joined: Wed Jun 26, 2013 4:39 am

Re: Free variable definitions

Post by reincarne »

I'm not sure I understood you :/
I will need to test it somehow to understand it.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Free variable definitions

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Free variable definitions

Post by Box293 »

Have a play and then let us know what you need explaining. Remember there are no silly questions.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
reincarne
Posts: 146
Joined: Wed Jun 26, 2013 4:39 am

Re: Free variable definitions

Post 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?
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Free variable definitions

Post 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.
Locked