Multiple host and service parents + dependencies

Hi,

I’m a bit confused regarding parent_service_name in combination with parent_host_name.

If I understand this right, you have to set for parent_service_name only the short service name without mentioning on which host this service is located. The host will then be specified in parent_host_name.

Is Icinga now using the parent_host_name and searches inside this host object for the service object named by parent_service_name? Or how is this working.

And if yes, how is this working if I’m having multiple host and service parents defined?
E.g. like this

object Host "Host_A" {
	import "generic-host"
	
	vars.parents = [ "Host_B", "Host_C" ]
	
	vars.parents_srv = [ "Service_X" ]
}

apply Dependency for (parent in host.vars.parents) to Host {
	parent_host_name = parent
}

apply Dependency for (parent in host.vars.parents_srv) to Host {
	parent_service_name = parent
}

Is Icinga now searching in both, Host_B and Host_C, for the Service_X? Or how is this working?
And if yes how can I tell Icinga to look for Service_X only in Host_C, but not in Host_B?

Or should I make sure that the parent_host_name and parent_service_name are part of the same dependency? Like this?

object Host "Host_A" {
	import "generic-host"
	
	vars.parents = [ "Host_B" ]
	
	vars.parents_srv = [ "Host_C>Service_X" ]
}

apply Dependency for (parent in host.vars.parents) to Host {
	parent_host_name = parent
}

apply Dependency for (parent in host.vars.parents_srv) to Host {
	var arr = parent.split(">")
	parent_host_name = arr[0]
	parent_service_name = arr[1]
}

Thanks.
Dirk

The easiest way to see what happens exactly is to run
# icinga2 daemon -C
and then check with icinga2 object list, e.g.
icinga2 object list -t Dependency

If you do that you’ll see that

implicitly sets parent_host_name to host_name. In other words: the host object depends on the status of parent_service_name for that host. Whether that make sense is up to you. In your example, Host_A would depend on Service_X of Host_A.

What you want and need and how to define it is up to you. Every Dependency Object needs a parent_host_name defined somehow, either explicitly or implicit in the apply context.

See Dependency object documentation and in particular the “Service-to-Service-on-the-same-Host Dependency Example”.

Thank you. Using icinga object list -t Dependency proofs my last example is creating exactly the dependency objects I wanted to. Let’s hope Icinga is treating them also the way I want it.