Using host macros in static 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.
jkbuster
Posts: 8
Joined: Thu Feb 14, 2013 1:02 pm

Using host macros in static service definition

Post by jkbuster »

I'm trying to use custom host variables as part of my service definition. More specifically for the servicegroups definition. Has anyone else tried to do this with any success?

Example:
define host {
...
_environment testing
}

define service {
...
servicegroups $_HOSTENVIRONMENT$-service1
}

The overall goal is this: have a hostgroup for each type of service we have. Then apply the same hostgroup configuration across all environments (prod, test, mock, etc). But, maintain servicegroups to allow those releasing new code to silence all notifications for a given environment's service (All test voip services, etc).
--
Thanks,
JKB
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Using host macros in static service definition

Post by eloyd »

Look at http://nagios.sourceforge.net/docs/3_0/ ... tvars.html more closely. You need to prefix your variable with _HOST OR _SERVICE to make them expand.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
jkbuster
Posts: 8
Joined: Thu Feb 14, 2013 1:02 pm

Re: Using host macros in static service definition

Post by jkbuster »

eloyd wrote:Look at http://nagios.sourceforge.net/docs/3_0/ ... tvars.html more closely. You need to prefix your variable with _HOST OR _SERVICE to make them expand.
Haven't I?

The variable is _env, and I'm using $_HOSTENV$
--
Thanks,
JKB
jkbuster
Posts: 8
Joined: Thu Feb 14, 2013 1:02 pm

Re: Using host macros in static service definition

Post by jkbuster »

In more testing, I'm able to get it to expand in the check_command, but not in the servicegroups part of the service definition. Copy/pasted so this isn't the issue I'm having.
--
Thanks,
JKB
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Using host macros in static service definition

Post by eloyd »

Sorry, I read that while traveling in the car. Host and service macros are only valid in host service and contact definitions, not service groups or host groups.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
jkbuster
Posts: 8
Joined: Thu Feb 14, 2013 1:02 pm

Re: Using host macros in static service definition

Post by jkbuster »

Even if I'm just using the servicegroups directive in a service definition? I was hoping that since I'm in a service definition I'd be able to leverage the host variable.
--
Thanks,
JKB
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Using host macros in static service definition

Post by eloyd »

I would have to go and look at source to see if that were the case or not. Someone more intimate with core code might be able to tell you before I can.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Using host macros in static service definition

Post by sreinhardt »

Agreed, that is going to take some digging to know for sure. I will talk with one of the developers or have a look myself tomorrow.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Using host macros in static service definition

Post by eloyd »

My browse through common/macros.c indicates that _SERVICE and _HOST and _CONTACT variables are all included at the same time, but only in service, host, and contact configurations.

So you're trying to use a $_HOST macro in a service definition and I think it should work. So I'm guessing you're either not doing it right (doubtful) or it's a bug.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Using host macros in static service definition

Post by abrist »

This does look right. COuld you open a potential issue on github at https://github.com/NagiosEnterprises/nagioscore
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked