Page 1 of 1
Defining Const Variables in Service Definition
Posted: Mon Aug 04, 2014 3:49 am
by badonde
Hi,
It is possible to create constant variables when defining services? I'd like to do something like this:
Code: Select all
IP1 = 192.168.1.1
define service{
check_command check_something!IP1
}
I think I can probably achieve something similar with a macro, but it would be nice to have the variable in the same file as the service definition.
Re: Defining Const Variables in Service Definition
Posted: Mon Aug 04, 2014 4:28 pm
by tmcdonald
This isn't possible. The first line Nagios finds that isn't a proper nagios config line, it will error out and tell you the offending line is a misconfig.
You can use the $USERX$ macros for this, but they would all be in the one file.
Disregard this post, complete misunderstanding. @eloyd is correct here.
Re: Defining Const Variables in Service Definition
Posted: Mon Aug 04, 2014 6:41 pm
by eloyd
There are a prodigious number of macros available within Nagios (
http://nagios.sourceforge.net/docs/3_0/macrolist.html). Plus you can define your own (
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html). Depending on what you want to do, you may be able to cobble together something that way.
For instance, we define a "_SSH_PORT" custom object variable on each host because we run SSH on non-standard ports. We can then use this on a "check_ssh -p $_HOST_SSH_PORT" service check so that each host gets its custom SSH port checked without having to do something weird.
Your mileage may vary, but you can do a lot with the built-in macro capabilities.
Re: Defining Const Variables in Service Definition
Posted: Tue Aug 05, 2014 9:55 am
by tmcdonald
Thank you eloyd!
I completely misread the initial post - I thought @badonde was asking how to pass variables into a service (like passing arguments to a function), implying the config files have their own scripting language!
Re: Defining Const Variables in Service Definition
Posted: Tue Aug 05, 2014 10:20 am
by eloyd
I wasn't sure, but I do think that would be a cool idea.
