Creating a Dependency in Director

Hi,

Trying to figure out how make a dependency in icinga2 director. Normally in etc/icinga2/conf.d/hosts.conf I would create the dependency and hosts like this:

apply Dependency “Parent” for (parent in host.vars.parents) to Host {
parent_host_name = parent
assign where host.address && host.vars.parents
}
object Host “Zues” {
import “generic-host”
display_name = “Zues_1.1”
address = “192.168.1.1”
check_command = “hostalive”
}
object Host “3850_12X_ToyRoom” {
import “generic-host”
display_name = “3850_12X_ToyRoom_1.179”
address = “192.168.1.179”
check_command = “hostalive”
vars.parents = [“Zues”]
}

This dependency is required for the visgence module. In director I have been able to create the vars.parents field and fill in the correct values. However, am struggling how to create the dependency itself in director. Attached is what I have, but it does not work.

What am I missing?

Hi,

the way you showed as config files should work - I did it in the same way.

When moving the config from files to Director, IMHO the variable $host.vars.parents$ in “Parent Host”
is missing. Then you should find a similar config in Preview as in filebased config.

Greetings,
Manfred

Hi,

I am not sure if I get the question correct but I’ll try to help. :sweat_smile:

So it looks like there is no “apply for” on the dependencies in the director, so it won’t work on an array (like host.vars.parents = [ “hostA”, “hostB” ]). So, in the best case you have a limited number of dependencies - which would make the stuff below easier. So we assume you have at max 2 parents.
So I would create 2 fields for the host. Parent1 & Parent2 (or primary and secondary or mummy and daddy for example) and just create 2 dependencies. One has Parent Host: host.vars.mummy and the 2nd has host.vars.daddy as parent in the director config.

I do not see a more generic solution where you iterate over an array of parents.

We - who try to restrict all config. steps to Director as a policy for our Icinga2 instances we build - solved the multi-parent problem by defining a dummy “aggregate” host with IP 0.0.0.0, who then regularly fpings the list of parent hosts via a data field, listing hosts. (I.e. the dummy host is only “up” as long as at least one of the parents is reachable.) Then you can put the dummy host in the Parent field of the dependency.

This is not very elegant or efficient, but tested successfully and is now in production for one of our customers…

Hi Manfred, the Parent Host field will not take the value, “host.vars.parents”. It throws the error: “Failed to load icinga_host “host.vars.parents” (DbObject.php:628)”. The only values it will take is an acutal host name. Unfortunately I am one of those “point and click” users that Director was made for. I get lost when it comes to the programming language in the config files.

1 Like

Hi William,
I’ve tested it in my lab, you’re right - there are only hostnames of your setup allowed, but no variables.
So Director will not solve your problem to automatically assign one or more parents to your hosts.

But you can combine both - file based config and Director. Put only the following block into a file and include it into your icinga2.conf:

apply Dependency “Parent” for (parent in host.vars.parents) to Host {
parent_host_name = parent
assign where host.address && host.vars.parents
}

Then this rule is applied to every host with set address and parent variable - regardless if the host is defined in file or via Director. Be sure that the variable “parents” is always an array. By using Director set variable type array, within files you have to use syntax [“parent1” “parent2”]

To verify functionality, look for dependency objects within your running icinga2
icinga2 object list --type Dependency

You can actually use host vars. It should work with $host.vars.parent1$ for example. I might miss something but with the leading and trailing $ it should work and allow a solution where you inherit the value from the host object.

Hi Manfred,

So here is what I did. In etc/icinga2 I created file visgence.conf. In that file I put the following:
apply Dependency “Parent” for (parent in host.vars.parents) to Host {
parent_host_name = parent
assign where host.address && host.vars.parents
}
Then in icinga2.conf I added this line:
include “visgence.conf”

I restarted icinga2 service and ran command icinga2 object list --type Dependency . That command returned no results. Did I do it wrong?

Hi Marcel, nope the host field does not seem to take any variables. I think that is a limitation of director and dependencies.

Let’s check some preconditions:

  • Added a custom data field named parents, type array, to Director?
  • Added this data field to your host template (template is in cluster zone director-global or master)?
  • Filled this field with parent host name(s) for each Director defined host?
  • Host name in parents field are spelled correct (like host object name)?
  • Deployed all settings?

Host preview in Director should look like this:

object Host “ap-01” {
import “[tmpl-host-generic]”

display_name = “Accesspoint ap-01”
address = “172.16.1.1”
vars.parents = [ “switch-01” ]
}

1 Like

Well, OK. I had the data type set to string instead of array. Now all works. Brilliant!!! So creating the separate conf file and adding it to the icinga2.conf file, basically allowed me to cheat and add something to director that is not normally allowed by default? That is a nifty trick. Thanks much for your help. I can now proceed with project. You Rock!!! Thanks to everyone else who responded as well. This is a good community.