Director API Dependencies


I trying to automate a few things in regards to deployment of hosts that has a parrent relationship.
I have 320+ locations connected to our network through a router. That router is the parent for that given location.
On the location i have from zero to 10+ hosts that i monitor, in at least to diffent ip subnets.
When i deploy or refresh the location i would like to add a dependency rule in Director through the API.
Is it possible at the moment?

I have tried using the /director/dependency/ url with and without add and add?type=apply and the director/dependencies/ url.
But I am getting a internal server error (500) each time and i just add one new apply rules.

I have also tried to fetch the current apply-rule configuration, converting it to json and adding my new dependency-rule to the object, and POST / PUT but i get the http 500 error.

I am creating the hosts through the API already, so that works fine.

Is it possible to create new dependency rules through Director API?
If yes how do is it done?

Brian Møller

Hi and welcome,

Could you give us an example of your complete API request? It would be easier to help. Because it is working, we are doing this regularly.

Hi Stevie
Thank you for the reply.
I’m doing this with curl (i know the formatting is ruining something):
curl -k -H ‘Accept: application/json’ -u ‘user:pass’ -X ‘POST’ -i ‘https://icinga-host/director/director/dependency/add’ -d { “objects”: [{“apply_to”: “host”,“assign_filter”: “host.address=%22192.168.1.%2A%22|host.address=%2210.1.1.%2A%22”,“imports”: “Dependency-host-template”,“object_name”: “location123”,“object_type”: “apply”,“parent_host”: “location123-hx”,“states”: “Up”},{“apply_to”: “host”,“assign_filter”: “”,“imports”: “Dependency-host-template”,“object_name”: “location123-hx”,“object_type”: “apply”,“parent_host”: “location123-nia”,“states”: “Up”}]}

Could i see how you do it?

not really, if you are using this: :wink:

I’m doing this in a perl script. So it should something like this:

curl -k -H ‘Accept: application/json’ -u ‘user:pass’ -X ‘POST’ 'https://icinga-master/icingaweb2/director -d { [data] }`

The data is looking like this ( snippset from my perl script):

object_name => “$location”,
apply_to => “host”,
assign_filter => ““xx*”|“yy*””,
object_type => “apply”,
parent_host => “$hostname”,
states => [ “Up” ],
zone => “[icinga zone]”,