Dynamic Service-to-Service Dependencies based on parent service var

I am trying to do service to service dependency for an env with service names like this:

envX node1 alpha
envX node1 beta
envX node1 gamma

envX node2 alpha
envX node2 beta
envX node2 gamma

envY node 1 alpha
...

There’s many nodes and many envs.

Now I am trying to do a simple “If node1 alpha is down, don’t check node1 beta” via Dependencies, for each node across some of the envs.

I can set that up just fine, one dependency rule by one, but there’s hundreds of nodes total, so we’d end up with thousands of relations when all is done.

I thought to add a node number as a $service.vars.node$, so then I could create a dependency with a Parent Service envX node$service.vars.node$ alpha assigned where service.name = envX node$service.vars.node$ beta, and while that seems to pass the config check, it does not seem to work.

How do I achieve what I want in a smarter way than bruteforcing everything?

I believe I will also run into a situation where envX is spread across multiple zones, to possibly complicate matters further.

Thanks for posting, this one is quite interesting.

I hope that I got your problem description right. Thus, I came up with the following Dependency, which adds a Service dependency hierarchy from a “beta” to an “alpha” Service, where the “beta” Service name matches a pattern derived from your post.

apply Dependency "alpha-beta-hierachy" to Service {
  parent_service_name = service.name.replace("beta", "alpha")

  assign where match("env* node* beta", service.name)
}

In my test setup, I created a few hosts following the suggested naming schema, and the inspected Dependency objects[1] looked quite right.

Please note that the String#replace function can become a footgun, e.g., when “beta” is part of your hostname. Consider stripping the last four chars and adding “alpha” afterwards - but this was enough for a PoC.

I am not quite sure which role “gamma” plays here, but if it should be a dependent of “beta”, just duplicate the Dependency example and switch names.

This makes things a bit spicy as objects are part of a zone. With no intention to sound rude, but then maybe reconsider your object placement within the zones.


  1. icinga2 object list -t Dependency ↩︎

1 Like

That seems like it would work for our use case!

Would you know how/if I could apply such a rule from Director UI?

I see it ends up as an escaped string which is why I presume it fails as non-existent:

parent_service_name = "service.name.replace(\"NFY\", \"NSY\")"

I’ve ended up applying it is a raw file for now - and it seems to have worked, so thank you!

There’s some more complex cases I may need to follow-up about, but this works for now!

Glad to hear this :slight_smile:

Unfortunately, I am not fluent in the Director. But have you tried setting the value without the surrounding quotes and without escaping the inner quotes, as this is something to be expressed in Icinga 2 DSL?

Otherwise, maybe someone more familiar with the Director might step in.

Otherwise, maybe someone more familiar with the Director might step in.

Im not totally sure on how or whether i could use these Icinga DSL Functions in the Director. Ofc, you could use the Directors Import Source/Sync Rule Features to work with such things.

1 Like