Icinga2 REST API variable synchronization with Icinga Director. #2887

Expected Behavior

Icinga Director should be able to update a variable object if the object has a null value and the value is already provided by Icinga Director for example in Service Template or Service Set.

Current Behavior

If previously the value for the variable object was given using Icinga2 REST API and we want to overwrite this value with the help of the Icinga Director, it is impossible.

Steps to Reproduce (for bugs)

With the help of Icinga2 REST API, I passed the value “13” for the postgres_critical variable.
Which resulted in overwriting the value that I had configured in “Icinga Service Sets”

curl -k -s -S -i -u user:pass -H ‘Accept: application/json’ -X POST 'https://localhost:5665/v1/objects/services/host-object!service-object -d ‘{ “attrs”: { “vars.postgres_critical” : “13” }}’

image

I would like to reverse the process.
However, when I’m using the Icinga2 REST API to overite postgres_critical and put a null value for this variable.
curl -k -s -S -i -u user:pass -H ‘Accept: application/json’ -X POST 'https://localhost:5665/v1/objects/services/host-object!service-object -d ‘{ “attrs”: { “vars.postgres_critical” : null }}’

It doesn’t change anything.
I am unable to get back the value specified in Icinga Director.
The variable postgres_critical takes the value null
Inspect >> Executed Command >> ‘-c’ ‘’
and does not retrieve the value previously configured in Icinga Director.

I can only see the Icinga Director value under original_attributes.
image

How to use a value defined in Icinga Director if previously this value was put under variable by Icinga2 REST API?

Your Environment

  • Director version 1.11.0
  • Icinga Web 2: 2.12.1
  • Icinga 2 version: r2.14.0-1
  • Operating System and version: Debian Linux 11 (bullseye)
  • Webserver, PHP versions: 7.4.33

GIT: Icinga2 REST API variable synchronization with Icinga Director. · Issue #2887 · Icinga/icingaweb2-module-director (github.com)

You should not use icinga2 api to update director managed objects.

things you can do:

  • You can use the director api to update vars and deploy automatically or via api

Some thoughts:

  • It is actually good that the director and icinga2 are not like superglued together.
  • changes can be reviewed (directorbranches)
  • changes can be reviewed if other users are not allowed to deploy
  • you monitoring is relatively save from misconfiguration, even if the deployment failed the old config is still running.
  • if you want to change a var via api why not change it in director using director api

if you thing that these var changes persist you can look into /var/lib/icinga2/modified-attributes.conf
since this is independent from icinga director these changes persist after deply.

If think you will find the vars.postgres_critical

var obj = get_object("Service", "host-object!service-object")
if (obj) {
        obj.modify_attribute("vars.postgres_critical", "test")
        obj.version = 1729298366.438069
}

use this to restore the default (works since icinga2 2.14.0):

curl -k -s -S -i -u user:pass -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/objects/services/host-object!service-object' -d '{ "restore_attrs": [ "vars.postgres_critical" ]}'

and the var should be fixed

here is an option for icinga2 < 2.14 but it works on 2.14 too:

if you want to edit the file /var/lib/icinga2/modified-attributes.conf or delete it

  • stop icinga2
  • do modification or removal
  • start icinga2

Best Regards
Nicolas