Multiple Inheritance Sources and variable concatenations

Ethan Galstad nagios at nagios.org
Wed Aug 22 18:55:16 CEST 2007


L B wrote:
> Hi all,
> 
> I've read the end of this page 
> https://nagios.sgs.net/nagios/docs/objectinheritance.html 
> <https://nagios.sgs.net/nagios/docs/objectinheritance.html> about 
> multiple inheritance sources.
> 
> I'm going to explain what I want with an example :
> 
> I have a template for windows-servers with an hostgroups variable defined.
> I have another template for ABC-servers with also an hostgroups variable 
> defined ( ABC is a project name).
> 
> I want my server to belong to both.
> 
> I defined a new host like this :
> 
> define host {
> name windows-server
> hostgroups windows-server
> ...
> register 0
> }
> define host {
> name ABC-server
> hostgroups ABC-server
> ...
> register 0
> }
> 
> define host {
> use  windows-server,ABC-server
> ...
> }
> 
> The problem, and according to the documentation, is that only the 
> hostgroups variable of the first template is kept.
> 
> Is it possible to add a concatenation feature to this inheritance, for 
> example by adding a + in front of the hostgroups name ?
> 
> If I define a template like this :
> define host {
> name ABC-server
> hostgroups +ABC-server
> ...
> register 0
> }
> 
> I would like the hostgroups variable to be concatenated to the previous 
> ones inherited from other templates.
> 
> I thought it was the expected behavior but it doesn't work.
> 
> Thanks,
> -- 
> L.B.

The "+" concatentation trick works with only one level of recursion and 
not with multiple inheritance sources.  Also, Nagios will inherit values 
from the first template (as you specify) in which they are found.

Nagios sees that the windows-server template already has a hostgroups 
variable defined, so it won't use the value from the ABC-server template.

So in order to accomplish what you want, you have two options.

The first option:

define host {
name windows-server
hostgroups windows-server
...
register 0
}

define host {
use  windows-server
hostgroups +ABC-server
...
}

The second option:

define host{
name windows-server
hostgroups windows-server
...
register 0
}

define host {
name ABC-server
use windows-server
hostgroups +ABC-server
...
register 0
}

define host {
use  ABC-server
...
}


Ethan Galstad,
Nagios Developer
---
Email: nagios at nagios.org
Website: http://www.nagios.org

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/




More information about the Developers mailing list