One of the very few disadvantages of Icinga 2 over Nagios/Icinga 1 is that the child-parent relationships are missing.
In Nagios/Icinga 1.x, multiple parents could be configured in the host definition:
define host{
use generic-host
host_name child
address 10.10.10.50
parents parent1,parent2,parent3
}
This is especially helpful for representing the relationships in networking (for example server1's parent is switch1) but also for other child-parent relationships like virtual machines and their physical hosts.
The "parents" syntax disappeared on Icinga 2. However a "Dependency" can be set which, in theory, should replace the child-parent-relationship with a dependency-relationship:
object Dependency "child-depends-on-parent" {
child_host_name = "child1"
parent_host_name = "parent1"
}
But here comes the problem: The dependency's "parent_host_name" only allows one value, not multiple values. Which makes chlid1 only dependant on parent1 - yet networkwise it should be dependant on mulitple parents.
Apply rules to the rescue (once again)! As described in a previous article on dynamic apply rules to monitor partitions, it is possible to apply rules with a for-loop. Just in this case, I didn't apply a service but rather a dependency.
In the host object, the parents are defined in an array:
object Host "child" {
import "generic-host"
address = "10.10.10.50"
# Define the parent(s) of this object
vars.parents = [ "parent1", "parent2", "parent3" ]
}
Each parent object is a value of the array "vars.parents". Which makes this way of configuration lightweight and easy as with Nagios/Icinga 1; one simple line.
For each found value in the array, a dependency is applied:
apply Dependency "Parent" for (parent in host.vars.parents) to Host {
parent_host_name = parent
assign where host.address && host.vars.parents
}
I just tested it successfully. NagVis correctly shows the relationship in the map and Icinga Classic UI mentions multiple parents in the host view.
Max from wrote on Oct 7th, 2019:
Saved my day! Thanks!
Guillermo from wrote on May 24th, 2018:
Thanks for the information, very useful.