Help needed with Director API behavior when trying to add data list entries

Hello all,

i am currently facing an interesting problem using the Director Rest-API.
Trying to add entries to a data list via the API, is resulting in really weird behavior looking at the result in the webUI.


First of all, here are all informations of my setup:

  • Director version:1.8.1
  • Icinga Web 2 version: 2.9.0
  • Icinga 2 version: 2.12.5
  • Operating System and version: CentOS 7
  • PHP version: 7.4.25

I am using the following API Call:

curl -X POST -u 'user:pwd' -H 'Accept: application/json' 'https://HOST/director/host' \
-d '{"object_type": "object", "object_name": "VAR-TEST-HOST", "address": "localhost", "imports": [ "base" ], "vars": { "test-list": [ "entry1", "entry2" ] } }'

I assumed, that this results in a host, that has a custom var data list attached, where the entries are: “entry1” and “entry2”.

But instead, the activity log entry shows me, that a dictionary is used:

test-host-activity-log

Which results in a very strange key → value reference when viewing the variables in the webUI:

test-host-custom-var-overview



My question is now, how do i have to construct my JSON/API-Call, so that the variables are correctly added to a list?

Example, for how i would want it to be:

test-host-custom-var-expectation

Your syntax is correct, but the variable name is not, it should not contain - but _ instead. Because of this the director has to use the different syntax which has the same meaning. And very likely this syntax confuses Icinga Web 2.

2 Likes

Thank you for the fast reply @dgoetz!
Changing the variable name does indeed result in the list beeing shown correctly in the activity log:

test-host-activity-log-v2

…but the incorrect mapping in the custom variables view remains:

test-host-custom-var-overview-v2


This also begs the question if there is a workaround possible, to still use a “-” in the data list name?
My data list is already in use on a large portion of hosts, changing the name would cause a lot of overhead.

Another thing to take note of:
The custom variables overview in the webinterface is wrong, but the variables are correctly defined when looking in the inspect tab.
It seems like a bug in the director api, where the api is correctly assigning the values, but on some other part of the processing, the variables get messed up and are therefore not shown correctly in the webui.

I tested this with a command, using the variables and could correctly use them.

Alright, this situation gets more and more confusing by the minute.

I added the data list via the director api, as explained in my last comments and since there was no fix for the incorrect mapping, i just let it sit there overnight.
Coming back to the problem this morning, all of a sudden, without any changes from my side, the problem was magically fixed:

test-host-custom-var-overview-v3

Does anyone have any explanation to this?
Does the director run some sort of cleanup tasks overnight or am i missing something completely here?

In this part the Director is not involved (its job is finished after the configuration was deployed to Icinga 2), it is just Icinga 2 writing to IDO and Icinga Web 2 reading from IDO. As far as I know there was a bug in older versions regarding the update of custom variables by Icinga 2, but this should be fixed and I am not aware of another open one.