After deleting a Service via API with parameter cascade=1, all of the dependencies that this Service is their child_service_name aren't being deleted.
Note: When deleting the Host of the Service with cascade=1, both the Service and the Dependencies are deleted.
Tested with Postman but every api solution would fit.
cascade=1cascade=1All of the Dependencies that the Service is related to them (it is the child_service_name) should be deleted when the Service is deleted with cascade=1.
Currently tested against Icinga2 on a Docker machine. Also, I have Puppet service that runs and add configurations for Icinga as well as using the API directory.
I have dependencies that are added via Puppet, so whenever I create the Service with the API, there are Dependencies that getting created in package _etc.
The reproduce procedure creates the Dependencies in package _api.
Still, all Dependencies (from both packages) aren't being deleted when the Service is deleted, but only get deleted when the Host is deleted.
icinga2 - The Icinga 2 network monitoring daemon (version: r2.11.4-1)
Copyright (c) 2012-2020 Icinga GmbH (https://icinga.com/)
License GPLv2+: GNU GPL version 2 or later http://gnu.org/licenses/gpl2.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
System information:
Platform: Ubuntu
Platform version: 16.04.4 LTS (Xenial Xerus)
Kernel: Linux
Kernel version: 4.14.181-142.260.amzn2.x86_64
Architecture: x86_64
Build information:
Compiler: GNU 5.4.0
Build host: runner-ltrjqz9n-project-298-concurrent-0
Application information:
General paths:
Config directory: /etc/icinga2
Data directory: /var/lib/icinga2
Log directory: /var/log/icinga2
Cache directory: /var/cache/icinga2
Spool directory: /var/spool/icinga2
Run directory: /run/icinga2
Old paths (deprecated):
Installation root: /usr
Sysconf directory: /etc
Run directory (base): /run
Local state directory: /var
Internal paths:
Package data directory: /usr/share/icinga2
State path: /var/lib/icinga2/icinga2.state
Modified attributes path: /var/lib/icinga2/modified-attributes.conf
Objects path: /var/cache/icinga2/icinga2.debug
Vars path: /var/cache/icinga2/icinga2.vars
PID path: /run/icinga2/icinga2.pid
Disabled features: compatlog elasticsearch gelf graphite influxdb livestatus notification opentsdb perfdata statusdata syslog
Enabled features: api checker command debuglog ido-mysql mainlog
I could also reproduce it with the following commands.
Create a Host: curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/icinga_example' -d '{ "templates" : [ "generic-host" ], "attrs": { "address": "192.198.1.0", "check_command": "hostalive", "vars.os": "MacOs" }, "pretty": true }'
Create a Service: curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/icinga_example!icinga_services' -d '{ "templates": [ "generic-service" ], "attrs": { "check_command": "http", "check_interval": 1,"retry_interval": 1 } }'
Create Dependencies: curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/dependencies/icinga_example!icinga_services!depend' -d '{ "child_service": "icinga_services", "attrs": { "parent_host_name": "icinga_example" }, "pretty": true }'
Then I restarted icinga2 and deleted the service with the following command:
curl -k -s -u root:icinga -H 'Accept: application/json' -X DELETE 'https://localhost:5665/v1/objects/services/icinga_example!icinga_services?cascade=1&pretty=1'
Output :
```
{
"results": [
{
"code": 200.0,
"errors": [],
"name": "icinga_example!icinga_services",
"status": "Object was deleted.",
"type": "Service"
}
]
}
Try to query for the service object:
curl -k -s -u root:icinga 'https://localhost:5665/v1/objects/services/icinga_example!icinga_services?pretty=1'
{
"error": 404.0,
"status": "No objects found."
}
Try to query for Dependencies: Still there
curl -k -s -u root:icinga 'https://localhost:5665/v1/objects/dependencies/icinga_example!icinga_services!depend?pretty=1'
{
"results": [
{
"attrs": {
"__name": "icinga_example!icinga_services!depend",
"active": true,
"child_host_name": "icinga_example",
"child_service_name": "icinga_services",
"disable_checks": false,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "depend",
"original_attributes": null,
"package": "_api",
"parent_host_name": "icinga_example",
"parent_service_name": "",
"paused": false,
"period": "",
"source_location": {
"first_column": 0.0,
"first_line": 1.0,
"last_column": 25.0,
"last_line": 1.0,
"path": "/PATH/TO/icinga2/prefix/var/lib/icinga2/api/packages/_api/c66d655c-1f48-4ffd-82fb-a86b8a3c1de1/conf.d/dependencies/icinga_example!icinga_services!depend.conf"
},
"states": null,
"templates": [
"depend"
],
"type": "Dependency",
"vars": null,
"version": 1598445089.285009,
"zone": "yonass-mbp.int.netways.de"
},
"joins": {},
"meta": {},
"name": "icinga_example!icinga_services!depend",
"type": "Dependency"
}
]
}
`
I also tried usingparent_serviceinstead ofchild_servicewhen creating thedependencies. When I deleted the service the dependencies were also deleted. This problem only occurs when you create dependencies withchild_service``.
Are you sure about this?
Are you sure about this?
Sorry!
My mistake, the error occurs only if the service name is not entered as follows when creating dependencies.
Before: curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/dependencies/icinga_example!icinga_services!depend' -d '{ "child_service": "icinga_services", "attrs": { "parent_host_name": "icinga_example" }, "pretty": true }'
After: curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/dependencies/icinga_example!depend' -d '{ "child_service": "icinga_services", "attrs": { "parent_host_name": "icinga_example" }, "pretty": true }'
The last command causes the error.
And of course, the service name must be removed from the query as follows.
curl -k -s -u root:icinga 'https://localhost:5665/v1/objects/dependencies/icinga_example!depend?pretty=1'
That way you create a Host->Host Dependency. Of course It's not being deleted.
โ icinga2 git:(master) prefix/sbin/icinga2 daemon -d
[2020-08-26 18:35:01 +0200] information/cli: Icinga application loader (version: v2.12.0)
[2020-08-26 18:35:01 +0200] information/cli: Closing console log.
โ icinga2 git:(master) curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/icinga_example' -d '{ "templates" : [ "generic-host" ], "attrs": { "address": "192.198.1.0", "check_command": "hostalive", "vars.os": "MacOs" }, "pretty": true }'
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
โ icinga2 git:(master) curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/icinga_example!icinga_services' -d '{ "templates": [ "generic-service" ], "attrs": { "check_command": "http", "check_interval": 1,"retry_interval": 1 } }'
{"results":[{"code":200.0,"status":"Object was created"}]}% โ icinga2 git:(master) curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/dependencies/icinga_example!depend' -d '{ "child_service": "icinga_services", "attrs": { "parent_host_name": "icinga_example" }, "pretty": true }'
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
โ icinga2 git:(master) curl -k -s -u root:icinga -H 'Accept: application/json' 'https://localhost:5665/v1/objects/dependencies?pretty=1'
{
"results": [
{
"attrs": {
"__name": "icinga_example!depend",
"active": true,
"child_host_name": "icinga_example",
"child_service_name": "",
"disable_checks": false,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "depend",
"original_attributes": null,
"package": "_api",
"parent_host_name": "icinga_example",
"parent_service_name": "",
"paused": false,
"period": "",
"source_location": {
"first_column": 0.0,
"first_line": 1.0,
"last_column": 25.0,
"last_line": 1.0,
"path": "/Users/aklimov/NET/WS/icinga2/prefix/var/lib/icinga2/api/packages/_api/c3e85913-863a-4996-8ceb-8ca8799d4454/conf.d/dependencies/icinga_example!depend.conf"
},
"states": null,
"templates": [
"depend"
],
"type": "Dependency",
"vars": null,
"version": 1598459728.559594,
"zone": "alexanders-mbp.int.netways.de"
},
"joins": {},
"meta": {},
"name": "icinga_example!depend",
"type": "Dependency"
}
]
}
โ icinga2 git:(master)
My Dependencies are targeting the services, not just the hosts.
For example:
curl -k -s -u root:icinga -H 'Accept: application/json' 'https://localhost:5665/v1/objects/dependencies/my-test-host!checkIngressRequests!internet_to_service?pretty=1'
provides the data:
{
"results": [
{
"attrs": {
"__name": "my-test-host!checkIngressRequests!internet_to_service",
"active": true,
"child_host_name": "my-test-host",
"child_service_name": "checkIngressRequests",
"disable_checks": true,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "internet_to_service",
"original_attributes": null,
"package": "_etc",
"parent_host_name": "Yahoo",
"parent_service_name": "",
"paused": false,
"period": "",
"source_location": {
"first_column": 1.0,
"first_line": 3.0,
"last_column": 49.0,
"last_line": 3.0,
"path": "/etc/icinga2/conf.d/objects/dependency/internet_to_service.conf"
},
"states": null,
"templates": [
"internet_to_service"
],
"type": "Dependency",
"vars": null,
"version": 0.0,
"zone": ""
},
"joins": {},
"meta": {},
"name": "my-test-host!checkIngressRequests!internet_to_service",
"type": "Dependency"
}
]
}
As I mentioned in the issue description, I'm using puppet service to populate these dependencies, and using puppet-icinga.
My icinga2::object::dependency (as mentioned here) are using the "apply_target": "Service" parameter, and thus I cannot re-create the same service with same name, because the Dependencies still exist after deletion of the Service itself
For simplicity: The Host & Service are created via the API, and the Dependencies are created via the Puppet service
I can't reproduce it either.
โ icinga2 git:(master) curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/lolcat' -d '{ "attrs": { "check_command": "hostalive" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
โ icinga2 git:(master) curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/lolcat!mew' -d '{ "attrs": { "check_command": "hostalive" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
โ icinga2 git:(master) curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/lolcat!rofl' -d '{ "attrs": { "check_command": "hostalive" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
โ icinga2 git:(master) curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/dependencies/lolcat!rofl!mew' -d '{ "attrs": { "parent_host_name": "lolcat", "parent_service_name": "mew" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
โ icinga2 git:(master) curl -fksSLu root:icinga -H 'Accept: application/json' -X GET 'https://localhost:5665/v1/objects/dependencies/lolcat!rofl!mew' -d '{ "pretty": true }'; echo
{
"results": [
{
"attrs": {
"__name": "lolcat!rofl!mew",
"active": true,
"child_host_name": "lolcat",
"child_service_name": "rofl",
"disable_checks": false,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "mew",
"original_attributes": null,
"package": "_api",
"parent_host_name": "lolcat",
"parent_service_name": "mew",
"paused": false,
"period": "",
"source_location": {
"first_column": 0.0,
"first_line": 1.0,
"last_column": 22.0,
"last_line": 1.0,
"path": "/Users/aklimov/NET/WS/icinga2/prefix/var/lib/icinga2/api/packages/_api/863ee7b5-f854-4508-b7ba-81215ac1636d/conf.d/dependencies/lolcat!rofl!mew.conf"
},
"states": null,
"templates": [
"mew"
],
"type": "Dependency",
"vars": null,
"version": 1598521816.628439,
"zone": "alexanders-mbp.int.netways.de"
},
"joins": {},
"meta": {},
"name": "lolcat!rofl!mew",
"type": "Dependency"
}
]
}
โ icinga2 git:(master) curl -fksSLu root:icinga -H 'Accept: application/json' -X DELETE 'https://localhost:5665/v1/objects/services/lolcat!rofl' -d '{ "pretty": true, "cascade": true }'; echo
{
"results": [
{
"code": 200.0,
"errors": [],
"name": "lolcat!rofl",
"status": "Object was deleted.",
"type": "Service"
}
]
}
โ icinga2 git:(master) curl -fksSLu root:icinga -H 'Accept: application/json' -X GET 'https://localhost:5665/v1/objects/dependencies/lolcat!rofl!mew' -d '{ "pretty": true }'; echo
curl: (22) The requested URL returned error: 404 Not Found
โ icinga2 git:(master)
@bobapple Does the mentioned Puppet thing uses API, packages or config files?
The mentioned Puppet is using config files (Not sure about packages). It doesn't use the API itself.
Furthermore, As you can see, the parent host/service of my dependencies are different from the child host/service, as seen in @Al2Klimov result of creating the Dependency.
"child_host_name": "my-test-host",
"child_service_name": "checkIngressRequests",
"parent_host_name": "Yahoo",
"parent_service_name": "",
Please share a step-by-step instruction to reproduce this with a fresh Icinga w/o using Puppet.
Create 2 hosts:
curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/lolcat' -d '{ "attrs": { "check_command": "hostalive" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/lolcat2' -d '{ "attrs": { "check_command": "hostalive" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
Create 2 services, each one on a different host:
curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/lolcat!mew' -d '{ "attrs": { "check_command": "hostalive" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/services/lolcat2!rofl' -d '{ "attrs": { "check_command": "hostalive" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
Create 2 Dependencies:
curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/dependencies/lolcat2!rofl!mew' -d '{ "attrs": { "child_host_name": "lolcat2", "child_service_name": "rofl", "parent_host_name": "lolcat", "parent_service_name": "mew" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
curl -fksSLu root:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/dependencies/lolcat2!rofl!lolcat' -d '{ "attrs": { "child_host_name": "lolcat2", "child_service_name": "rofl", "parent_host_name": "lolcat", "parent_service_name": "" }, "pretty": true }'; echo
{
"results": [
{
"code": 200.0,
"status": "Object was created"
}
]
}
Show the 2 Dependencies:
curl -fksSLu root:icinga -H 'Accept: application/json' -X GET 'https://localhost:5665/v1/objects/dependencies/lolcat2!rofl!mew' -d '{ "pretty": true }'; echo
{
"results": [
{
"attrs": {
"__name": "lolcat2!rofl!mew",
"active": true,
"child_host_name": "lolcat2",
"child_service_name": "rofl",
"disable_checks": false,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "mew",
"original_attributes": null,
"package": "_api",
"parent_host_name": "lolcat",
"parent_service_name": "mew",
"paused": false,
"period": "",
"source_location": {
"first_column": 0.0,
"first_line": 1.0,
"last_column": 22.0,
"last_line": 1.0,
"path": "/var/lib/icinga2/api/packages/_api/c5eb58f5-3ea3-494e-9fb3-af04840b8911/conf.d/dependencies/lolcat2!rofl!mew.conf"
},
"states": null,
"templates": [
"mew"
],
"type": "Dependency",
"vars": null,
"version": 1598524345.406751,
"zone": "icinga2master.soluto.local"
},
"joins": {},
"meta": {},
"name": "lolcat2!rofl!mew",
"type": "Dependency"
}
]
}
curl -fksSLu root:icinga -H 'Accept: application/json' -X GET 'https://localhost:5665/v1/objects/dependencies/lolcat2!rofl!lolcat' -d '{ "pretty": true }'; echo
{
"results": [
{
"attrs": {
"__name": "lolcat2!rofl!lolcat",
"active": true,
"child_host_name": "lolcat2",
"child_service_name": "rofl",
"disable_checks": false,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "lolcat",
"original_attributes": null,
"package": "_api",
"parent_host_name": "lolcat",
"parent_service_name": "",
"paused": false,
"period": "",
"source_location": {
"first_column": 0.0,
"first_line": 1.0,
"last_column": 25.0,
"last_line": 1.0,
"path": "/var/lib/icinga2/api/packages/_api/c5eb58f5-3ea3-494e-9fb3-af04840b8911/conf.d/dependencies/lolcat2!rofl!lolcat.conf"
},
"states": null,
"templates": [
"lolcat"
],
"type": "Dependency",
"vars": null,
"version": 1598524365.816644,
"zone": "icinga2master.soluto.local"
},
"joins": {},
"meta": {},
"name": "lolcat2!rofl!lolcat",
"type": "Dependency"
}
]
}
Delete the service from the second host (rofl):
curl -fksSLu root:icinga -H 'Accept: application/json' -X DELETE 'https://localhost:5665/v1/objects/services/lolcat2!rofl' -d '{ "pretty": true, "cascade": true }'; echo
{
"results": [
{
"code": 200.0,
"errors": [],
"name": "lolcat2!rofl",
"status": "Object was deleted.",
"type": "Service"
}
]
}
Query for both Dependencies:
curl -fksSLu root:icinga -H 'Accept: application/json' -X GET 'https://localhost:5665/v1/objects/dependencies/lolcat2!rofl!mew' -d '{ "pretty": true }'; echo
{
"results": [
{
"attrs": {
"__name": "lolcat2!rofl!mew",
"active": true,
"child_host_name": "lolcat2",
"child_service_name": "rofl",
"disable_checks": false,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "mew",
"original_attributes": null,
"package": "_api",
"parent_host_name": "lolcat",
"parent_service_name": "mew",
"paused": false,
"period": "",
"source_location": {
"first_column": 0.0,
"first_line": 1.0,
"last_column": 22.0,
"last_line": 1.0,
"path": "/var/lib/icinga2/api/packages/_api/c5eb58f5-3ea3-494e-9fb3-af04840b8911/conf.d/dependencies/lolcat2!rofl!mew.conf"
},
"states": null,
"templates": [
"mew"
],
"type": "Dependency",
"vars": null,
"version": 1598524345.406751,
"zone": "icinga2master.soluto.local"
},
"joins": {},
"meta": {},
"name": "lolcat2!rofl!mew",
"type": "Dependency"
}
]
}
curl -fksSLu root:icinga -H 'Accept: application/json' -X GET 'https://localhost:5665/v1/objects/dependencies/lolcat2!rofl!lolcat' -d '{ "pretty": true }'; echo
{
"results": [
{
"attrs": {
"__name": "lolcat2!rofl!lolcat",
"active": true,
"child_host_name": "lolcat2",
"child_service_name": "rofl",
"disable_checks": false,
"disable_notifications": true,
"ha_mode": 0.0,
"ignore_soft_states": true,
"name": "lolcat",
"original_attributes": null,
"package": "_api",
"parent_host_name": "lolcat",
"parent_service_name": "",
"paused": false,
"period": "",
"source_location": {
"first_column": 0.0,
"first_line": 1.0,
"last_column": 25.0,
"last_line": 1.0,
"path": "/var/lib/icinga2/api/packages/_api/c5eb58f5-3ea3-494e-9fb3-af04840b8911/conf.d/dependencies/lolcat2!rofl!lolcat.conf"
},
"states": null,
"templates": [
"lolcat"
],
"type": "Dependency",
"vars": null,
"version": 1598524365.816644,
"zone": "icinga2master.soluto.local"
},
"joins": {},
"meta": {},
"name": "lolcat2!rofl!lolcat",
"type": "Dependency"
}
]
}
As you can see, the Dependencies are still exist, although the child service is deleted.
In your case of reproduction, the host for both of the services were the same host.
@bobapple Does the mentioned Puppet thing uses API, packages or config files?
The puppet module creates plain config files.
The config files are created based on the following ERB template: https://github.com/Icinga/puppet-icinga2/blob/master/templates/object.conf.erb
@Al2Klimov Hi,
Is there any update regarding the fix for the issue?
Saw that the PR is open for quite long time with no merge
Wouldn't hold my breath, they have a lot of bug-fixes with fairly small code changes with milestone 2.13, which is likely going to take a lot of time before it's released.
Your best bet is to patch it yourself. Been doing myself like this and while it's definitely PITA it is manageable, and considering severity of some bugs, the only way to use Icinga in my case.
If you are on Debian repackaging their packages with your own patch set is not particularly difficult.