Page 1 of 2

Using host macros in static service definition

Posted: Wed Aug 13, 2014 12:48 pm
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).

Re: Using host macros in static service definition

Posted: Wed Aug 13, 2014 12:57 pm
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.

Re: Using host macros in static service definition

Posted: Wed Aug 13, 2014 1:03 pm
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$

Re: Using host macros in static service definition

Posted: Wed Aug 13, 2014 1:11 pm
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.

Re: Using host macros in static service definition

Posted: Wed Aug 13, 2014 3:10 pm
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.

Re: Using host macros in static service definition

Posted: Wed Aug 13, 2014 3:14 pm
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.

Re: Using host macros in static service definition

Posted: Wed Aug 13, 2014 3:18 pm
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.

Re: Using host macros in static service definition

Posted: Thu Aug 14, 2014 8:01 pm
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.

Re: Using host macros in static service definition

Posted: Fri Aug 15, 2014 8:57 am
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.

Re: Using host macros in static service definition

Posted: Mon Aug 18, 2014 5:00 pm
by abrist
This does look right. COuld you open a potential issue on github at https://github.com/NagiosEnterprises/nagioscore