dcz01
December 1, 2023, 9:26am
1
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
dcz01
December 6, 2023, 2:14pm
2
Does nobody know how to do that with the API?
Al2Klimov
(Grandmaster)
December 11, 2023, 11:52am
3
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
dcz01
December 12, 2023, 6:06am
4
@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
Al2Klimov
(Grandmaster)
December 12, 2023, 3:20pm
5
It depends on the Notification apply rule, please show it.
dcz01
December 13, 2023, 6:21am
6
@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"
Al2Klimov
(Grandmaster)
December 13, 2023, 9:34am
7
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:
opened 10:43AM - 01 Apr 16 UTC
enhancement
area/configuration
area/api
needs-sponsoring
queue/wishlist
This issue has been migrated from Redmine: https://dev.icinga.com/issues/11501
… **Created by buhtik on 2016-04-01 10:43:48 +00:00**
Assignee: _(none)_
Status: _New_
Target Version: _Backlog_
Last Update: _2016-11-16 10:07:14 +00:00 (in Redmine)_
Backport?: Not yet backported
Include in Changelog: 1
---
After hosts object were updated, service custom variables were not changed.
Example of service definitions:
apply Service "\[CONS\]\[OPS\] CPU AVG 5 min." {
import "generic-service"
check\_command = "check\_zabbix"
vars.ARG1 = host.vars.zabbix\_host\_id
vars.ARG2 = "zabbix\_db"
vars.ARG3 = "system.cpu.load\[,avg5\]"
vars.ARG4 = host.vars.cpu\_load
assign where host.vars.cpu\_load
}
Steps to reproduce:
1. Creating host with attributes: {'templates': \['generic-host'\], 'attrs': {'vars.location': 'dub', 'vars.connection\_time\_wait': '14<OK<45', 'vars.cpu\_load': '2<OK<4', 'vars.zabbix\_agent\_health': 'OK=1', 'vars.notes': 'to\_add', 'vars.disk\_space\_opt': '20<OK<80<90', 'vars.role': 'app', 'vars.application': 'SM', 'vars.disk\_spase\_root': '44<OK<110', 'vars.description': 'Not in prod', 'address': '127.0.0.1', 'vars.zabbix\_host\_id': '11725', 'vars.type': 'virtual', 'vars.connection\_established': '20<OK<40', 'vars.swap\_used': '1.2<2<OK<4<4'}}
cat /var/lib/icinga2/api/packages/\_api/first-1458367266-1/conf.d/hosts/app-02-prod.dub.conf
object Host "app-02-prod.dub" {
import "generic-host"
address = "127.0.0.1"
vars\["application"\] = "SM"
vars\["connection\_established"\] = "20<OK<40"
vars\["connection\_time\_wait"\] = "14<OK<45"
vars\["cpu\_load"\] = "2<OK<4"
vars\["description"\] = "Not in prod"
vars\["disk\_space\_opt"\] = "20<OK<80<90"
vars\["disk\_spase\_root"\] = "44<OK<110"
vars\["location"\] = "dub"
vars\["notes"\] = "to\_add"
vars\["role"\] = "app"
vars\["swap\_used"\] = "1.2<2<OK<4<4"
vars\["type"\] = "virtual"
vars\["zabbix\_agent\_health"\] = "OK=1"
vars\["zabbix\_host\_id"\] = "11725"
version = 1459503512.559020
}
2. Updating host with attributes: {'templates': \['generic-host'\], 'attrs': {'vars.location': 'dub', 'vars.connection\_time\_wait': '23<OK<44', 'vars.zabbix\_agent\_health': 'OK=1', 'vars.notes': 'to\_update', 'vars.disk\_space\_opt': '20<OK<80<90', 'vars.role': 'app', 'vars.application': 'SM', 'vars.disk\_spase\_root': '44<OK<110', 'vars.description': 'Not in prod', 'address': '127.0.0.1', 'vars.zabbix\_host\_id': '11725', 'vars.type': 'virtual', 'vars.connection\_established': '29<OK<99', 'vars.swap\_used': '1.2<2<OK<4<4', 'vars.zabbix\_name': 'app-02-prod.dub'}}
Please note:
'vars.cpu\_load': '2<OK<4' - - WAS REMOVED
'vars.connection\_time\_wait': '14<OK<45' - WAS CHANGED to 'vars.connection\_time\_wait': '23<OK<44'
'vars.connection\_established': '20<OK<40' - WAS CHANGED to 'vars.connection\_established': '29<OK<99'
API Result: {u'results': \[{u'status': u'Attributes updated.', u'code': 200.0, u'type': u'Host', u'name': u'app-02-prod.dub'}\]}
'vars.connection\_time\_wait' and 'vars.connection\_established' **were changed in HOST Custom variables, but were not changed in Service Custom variables.**
'vars.cpu\_load' **was not removed**.
File '/var/lib/icinga2/api/packages/\_api/first-1458367266-1/conf.d/hosts/app-02-prod.dub.conf' was not changed.
More details in attached screenshots.
**Attachments**
* [create_log.png](https://dev.icinga.com/attachments/download/3258/create_log.png) buhtik - _2016-04-01 10:36:41 +00:00_
* [created host service cpu.png](https://dev.icinga.com/attachments/download/3259/created%20host%20service%20cpu.png) buhtik - _2016-04-01 10:36:41 +00:00_
* [created host.png](https://dev.icinga.com/attachments/download/3260/created%20host.png) buhtik - _2016-04-01 10:36:42 +00:00_
* [custom_vars1.png](https://dev.icinga.com/attachments/download/3261/custom_vars1.png) buhtik - _2016-04-01 10:36:42 +00:00_
* [created host services.png](https://dev.icinga.com/attachments/download/3262/created%20host%20services.png) buhtik - _2016-04-01 10:36:42 +00:00_
* [update host services.png](https://dev.icinga.com/attachments/download/3263/update%20host%20services.png) buhtik - _2016-04-01 10:36:42 +00:00_
* [update host vars.png](https://dev.icinga.com/attachments/download/3264/update%20host%20vars.png) buhtik - _2016-04-01 10:36:42 +00:00_
* [updating host log.png](https://dev.icinga.com/attachments/download/3265/updating%20host%20log.png) buhtik - _2016-04-01 10:36:42 +00:00_
---
**Relations**:
* relates [#11501](https://dev.icinga.com/issues/11501)
* relates [#11501](https://dev.icinga.com/issues/11501)
* duplicates [#11501](https://dev.icinga.com/issues/11501)
* duplicates [#11501](https://dev.icinga.com/issues/11501)
dcz01
December 13, 2023, 10:01am
8
@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
Al2Klimov
(Grandmaster)
December 13, 2023, 10:20am
9
You can modify it, but via plain config or Director, not the API.
dcz01
December 13, 2023, 10:47am
10
@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"
}