We are using some configuration packages via api to dynamically update hostgroups. With each update we have a new stage added to the configuration package.
Docs say we have to remove old stages ourselves.
Old stages are not purged automatically. You can remove stages that are no longer in use.
What is the correct and safe way to purge old stages? So far, the only way we came up with is to list all stage directories in the package directory /var/lib/icinga2/api/packages/packagename
, sorted by modification date and delete (rm -rf
) all those stage directories except for the latest two ones. But it seems something like this isn’t even possible with the API.
The basic task is straight forward:
- Obtain the list of packages and stages via
/v1/config/packages
- In each package delete all stages except the one listed as active-stage
Now the problem of course is, that those two steps aren’t transactional. I have no way to guarantee that the dynamic update of the hostgroups isn’t happening between those two steps or during those two steps.
Thus I may delete a stage which just has been created but not yet activated. There are probably other race conditions which may have effects, too.
By biggest problem at the moment is that stages only have a uuid as name. No timestamps associated nor any version number. Thus there is no reliable way to track in which order those stages were created (which is why I reverted to the rm -rf
method).
There also doesn’t seem to be a way to prevent the deletion of an active stage (i.e. an option to DELETE /v1/config/stages/
to prevent deletion if it’s the active stage)
So overall, it seems I cannot purge old stages via the API because it might happen that it’ll remove the stage which is supposed to become active or is active, killing the hostgroup definitions and thus killing our icinga2 server because the definitions are referenced in other objects.
I understand it’s an unlikely event, but I think if there is a chance it’ll happen eventually and then it usually happens at the most inconvenient time.
icinga2 - The Icinga 2 network monitoring daemon (version: r2.14.4-1)
Copyright (c) 2012-2025 Icinga GmbH (https://icinga.com/)
License GPLv2+: GNU GPL version 2 or later <https://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: AlmaLinux
Platform version: 9.5 (Teal Serval)
Kernel: Linux
Kernel version: 5.14.0-503.22.1.el9_5.x86_64
Architecture: x86_64