Add notification user via API

Hi,

I’m now trying sometimes with an API command to modify the dynamically created host with his notification users but it won’t work.
I don’t understand why it won’t work because the needed variables are set correctly.

Here is my used command:

curl -k -s -S -i -u xxxxxxx:xxxxxxxxxxxx -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/objects/hosts/xxxxxxxxxxxxx' \
 -d '{ "attrs": { "vars.notifications_opsgenie" : "true" }, "pretty": true }'

The notification is configured and it workes on many other hosts and services.

Greetings
dcz01

Does nobody know how to do that with the API?

Hi,

what exactly do you expect to happen after setting that custom var? That an apply Notification ... takes effect also for the host in question?

Best,
A/K

@Al2Klimov Hi,
Thanks for your answer.
Well yes, i thinked that it would work to set only the variable and then have the correct notification contact set on the hostalive command.
Isn’t it so?

Greetings
dcz01

It depends on the Notification apply rule, please show it.

@Al2Klimov Ok, good to know.
Here is my notification apply rule:

apply Notification "notify-opsgenie-host" to Host {
  command = "opsgenie-host-notification"
  users = ["opsgenie"]
  states = [ Down, Up ]
  types = [ Problem, Recovery, Acknowledgement ]

  # assign rules
  assign where host
  assign where host.vars.notifications_opsgenie == "true"
  ignore where host.vars.notifications_opsgenie == "false"
}

apply Notification "notify-opsgenie-service" to Service {
  command = "opsgenie-service-notification"
  users = ["opsgenie"]
  states = [ Critical, OK ]
  types = [ Problem, Recovery, Acknowledgement ]

  # assign rules
  assign where service.vars.notifications_opsgenie == "true" && service.enable_notifications == true
  ignore where host.vars.notifications_opsgenie == "false"

I’m afraid apply rules don’t see CV changes made via API:

https://github.com/Icinga/icinga2/issues/5235

Not to mention re-evaluation at runtime:

@Al2Klimov Thanks for your answer.
Well so there isn’t right now a fix and won’t be…
So what sould i do then?
Remove and create the object (host with services) newly?

Greetings
dcz01

You can modify it, but via plain config or Director, not the API.

@Al2Klimov
Well i tried to modify it plain via the config but that doesn’t even change anything.
An service for the same host with the problem has set the variable but it doesn’t activate the contact.

apply Service "nameserver_port53" {
  import "check-tcp"
  display_name = "Nameserver - bind:53"
  vars.notifications_opsgenie = true
  vars.tcp_port = "53"
  vars.tcp_timeout = "5"
  assign where host.vars.group == "nameserver"
}

Try:

  1. Stop Icinga
  2. Remove the API modifications to that particular custom vars from /var/lib/icinga2/modified-attributes.conf
  3. Start Icinga