Defining Const Variables in Service Definition

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
badonde
Posts: 1
Joined: Mon Aug 04, 2014 3:26 am

Defining Const Variables in Service Definition

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Defining Const Variables in Service Definition

Post 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.
Former Nagios employee
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Defining Const Variables in Service Definition

Post 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.
Last edited by eloyd on Tue Aug 05, 2014 10:20 am, edited 1 time in total.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Defining Const Variables in Service Definition

Post 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!
Former Nagios employee
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Defining Const Variables in Service Definition

Post by eloyd »

I wasn't sure, but I do think that would be a cool idea. :-)
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Locked