Director Rest API post for modify object is wrong working

Hi all,

When I try to modify the host object with the director API, all the vars properties are crushed. I want just add new vars property to existing host object. Is this a or bug?

curl -k -s -S -i -u ‘user:pass’ -H ‘Accept: application/json’ -X POST ‘https://icinga-host/icingaweb2/director/host?name=hostname1’ -d ‘{“vars”: { “event”: [ “Icinga”, “Camp” ] }}’

thanks.

I think it’s expected as your API call sets the variable vars to value { “event”: [ “Icinga”, “Camp” ] } and this overwrites the old content of vars.
Maybe you could try to address vars.event directly with -d '{"vars.event": [ "Icinga", "Camp" ] }'?

this format was not accepted by the director api

It should work this way according to the documentation.

The response always returns the full object on modification. This way you can immediately investigate the merged result. As you can see, POST requests only touch the parameters you passed - the rest remains untouched.

One more example to prove this:

{"address": "127.0.0.2", "vars.event": "Icinga CAMP" }

https://icinga.com/docs/icinga-director/latest/doc/70-REST-API/#response

If I understand the problem correctly, it could be that the Array [ “list element 1”, “element2” ] is not allowed but “string” is.

I am sorry ‘{“vars.event”: [ “Icinga”, “Camp” ] }’ and ‘{“vars.event”: “Icinga CAMP” }’ both work.

I got error because " ‘ " I tried with this character instead of " ’ " in bash command line :slight_smile:

1 Like