Icinga / icinga2

The core of our monitoring platform with a powerful configuration language and REST API.
https://icinga.com/docs/icinga2/latest
GNU General Public License v2.0
2.03k stars 578 forks source link

Live created object lingers even if creation fails #10110

Closed w1ll-i-code closed 2 months ago

w1ll-i-code commented 3 months ago

Describe the bug

If you create an object over the API PUT /v1/objects/hosts/api-host, but the validation fails, the object should not be created. However, when you try to create it again in a second requests, icinga2 tells you that the object already exists, until icinga2 is restarted.

To Reproduce

$ curl -u root:45e399d4e09e712e  -H 'Accept: application/json' -k -XPUT 'https://localhost:5665/v1/objects/hosts/api-host' -d '{ "imports": [], "attrs": {}, "pretty": true }'
{
    "results": [
        {
            "code": 500,
            "errors": [
                "Error: Validation failed for object 'api-host' of type 'Host'; Attribute 'check_command': Attribute must not be empty.\nLocation: in /var/lib/icinga2/api/packages/_api/7bc698af-01ee-4961-9aee-782963390ce9/conf.d/hosts/api-host.conf: 1:0-1:21"
            ],
            "status": "Object could not be created."
        }
    ]
}

$ curl -u root:45e399d4e09e712e  -H 'Accept: application/json' -k -XPUT 'https://localhost:5665/v1/objects/hosts/api-host' -d '{ "imports": [], "attrs": { "check_command": "dummy" }, "pretty": true }'
{
    "results": [
        {
            "code": 500,
            "errors": [
                "Error: Object 'api-host' of type 'Host' re-defined: in /var/lib/icinga2/api/packages/_api/fbca10c4-5df9-461d-9a01-eeb9caa96109/conf.d/hosts/api-host.conf: 1:0-1:21; previous definition: in /var/lib/icinga2/api/packages/_api/7bc698af-01ee-4961-9aee-782963390ce9/conf.d/hosts/api-host.conf: 1:0-1:21\nLocation: in /var/lib/icinga2/api/packages/_api/7bc698af-01ee-4961-9aee-782963390ce9/conf.d/hosts/api-host.conf: 1:0-1:21"
            ],
            "status": "Object could not be created."
        }
    ]
}

$ podman exec -i --tty icinga2-master cat /var/lib/icinga2/api/packages/_api/eee7aa8a-2832-412f-921b-8d80a2bd4052/conf.d/hosts/api-host.conf
cat: /var/lib/icinga2/api/packages/_api/7bc698af-01ee-4961-9aee-782963390ce9/conf.d/hosts/api-host.conf: No such file or directory

Expected behavior

I expect the object to not be present if it was not created, so I can try creating it again without having to restart icinga2

Your Environment

$ podman run -p 5665:5665 -e ICINGA_MASTER=1 --name icinga2-master --rm icinga/icinga2
sabatale commented 1 month ago

@yhabteab Is this available in the latest Ubuntu release? I still have the same issue.

systemcl restart icinga2 is the only workaround.

yhabteab commented 1 month ago

Hi, the fix for this is going to be available with the next Icinga 2 release, but in the meantime you can use the snapshot packages if you want. They are based on the master branch and are also available for the latest Ubuntu release as well.