Open julenl opened 5 years ago
As written in the documentation you have to fetch all applyrules and compare the names of the objects in the list you get with the name of the rule you are looking for, then you have to work with its id.
Here some parts from my python code:
url = "https://icinga2host/icingaweb2/director"
headers = {
'Accept': 'application/json',
'X-HTTP-Method-Override': 'POST'
}
auth = ("admin", "admin")
r = request.post(url+"/service/applyrule", headers, auth)
for object in r.json()['objects']:
if object['object_name'] == "apply rule Im looking for":
id = object['id']
Then you can edit/delete the rule using url+"/service?id="+id
Hi, It's true that we can use serviceapplyrules to see it but How can creeate it? It's seems that serviceapplyrules don't work for create
Best regards, Emilio J.
You call the service api and use the JSON you get by doing a call to see it, e.g. (Ansible snippet ):
- name: Create service_rule for service_template_check_some_rule
ansible.builtin.uri:
url: https://{{ inventory_hostname }}/icingaweb2/director/service
url_username: admin
url_password: admin
body_format: json
body: {
"assign_filter": "host.vars.cluster_role=%22master%22",
"imports": [
"service_template_check_some_service"
],
"object_name": "service_template_check_some_service_rule",
"object_type": "apply",
"vars": {
"var1": "testdb",
"var2": "something",
}
}
headers:
Accept: 'application/json'
validate_certs: false
force_basic_auth: true
method: POST
Expected Behavior
To have full support for apply rules from API and CLI. Including checking if a rule with a given name exists and deleting it.
To the best of my knowledge, the CLI cannot even create rules, right?
In CLI:
On the API:
Current Behavior
The apply rules work perfect from the web interface, and it also work fine in case of creating them with the API. But there is no way to figure out how to check if a rule already exists in director or to delete it. I can query the icinga2 API and find a
host!service
object for each host the service is applied for, but I cannot delete them, because they were not created with the icinga2 API, but with the director one.Possible Solution
Maybe the documentation is missing some hint about how to handle this. This was also requested in #1468 last year, but I haven't found any update.
Your Environment
icinga2 --version
): 2.10.1-1