Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to purge objects on Basket import #2201

Closed
Thomas-Gelf opened this issue Oct 19, 2020 · 6 comments
Closed

Allow to purge objects on Basket import #2201

Thomas-Gelf opened this issue Oct 19, 2020 · 6 comments
Assignees
Milestone

Comments

@Thomas-Gelf
Copy link
Contributor

Expected Behavior

I want to be able to run an operation as follows:

icingacli director basket restore --purge Command,ServiceSet < exported-basket.json

For every object type provided to purge all but objects in my basket should be purged.

Current Behavior

Baskets are able to create and modify objects, but it's not possible to use them in an idempotent way.

@Thomas-Gelf Thomas-Gelf added this to the 1.8.0 milestone Oct 19, 2020
@Thomas-Gelf Thomas-Gelf self-assigned this Oct 19, 2020
@Thomas-Gelf
Copy link
Contributor Author

ref/NC/690333

@Thomas-Gelf Thomas-Gelf modified the milestones: 1.8.0, 1.9.0 Dec 2, 2020
@bornandre
Copy link

Thanks Thomas for the implementation in 1.8.0.

To have a clean configuration before a new basket restore it done it is necessary that all objects getting purged. This allows us to get rid of unused objects which are not included in the new basket anymore. Otherwise old services will still be available and must be deleted manually

maybe it is possible to implement an opreation as follows:

icingacli director basket restore --purge-all Command,ServiceSet,Service < exported-basket.json

@Thomas-Gelf
Copy link
Contributor Author

user@web:~# icingacli director basket restore --help
Restore a Basket from JSON dump provided on STDIN
=================================================

USAGE

icingacli director basket restore < basket-dump.json

OPTIONS
  --purge <ObjectType>[,<ObjectType] Purge objects of the
    Given types. WARNING: this removes ALL objects that are
    not shipped with the given basket
  --force Purge refuses to purge Objects in case there are
    no Objects of a given ObjectType in the provided basket
    unless forced to do so

user@web:~# icingacli director basket restore --purge Command,Hosts < basket.json 
ERROR: InvalidArgumentException in ObjectPurgeHelper.php:139 with message:
 "Hosts" is not eligible for purge. Valid types: Basket, Command, CommandTemplate,
 Dependency, DirectorJob, ExternalCommand, HostGroup, HostTemplate,
 IcingaTemplateChoiceHost, IcingaTemplateChoiceService, ImportSource, Notification,
 NotificationTemplate, ServiceGroup, ServiceSet, ServiceTemplate, SyncRule,
 TimePeriod

user@web:~# icingacli director basket restore --purge Command < basket.json 
Objects from Basket Snapshot have been restored

user@web:~# icingacli director basket restore --purge Command < empty.json 
ERROR: InvalidArgumentException in ObjectPurgeHelper.php:29 with message: I will NOT
 purge all object unless being forced to do so

user@web:~# icingacli director basket restore --purge Command --force < empty.json 
Objects from Basket Snapshot have been restored

@bornandre
Copy link

with any kind of object i get the following error:

user@host:~# icingacli director basket restore --purge Command --force < empty.json
ERROR: Icinga\Module\Director\Exception\JsonEncodeException in /usr/share/icingaweb2/modules/director/library/Director/Exception/JsonException.php:12 with message: JSON Syntax error

...empty.json has no content... any ideas?

@Thomas-Gelf
Copy link
Contributor Author

Hoi @bornandre,

no content isn't valid JSON syntax, and therefore also not a valid basket. Nothing bad happened at this point, it just rejected the (invalid) JSON file. In case you want to simulate an empty basket, you could write an empty object to your file:

{}

Cheers
Thomas

@bornandre
Copy link

ServiceGroup, ServiceSet ist working as expected...

icingacli director basket restore --purge ServiceGroup --force < empty.json
Objects from Basket Snapshot have been restored
icingacli director basket restore --purge ServiceSet --force < empty.json
Objects from Basket Snapshot have been restored

but...

icingacli director basket restore --purge Command --force < empty.json
ERROR: Zend_Db_Statement_Exception in /usr/share/icingaweb2/library/vendor/Zend/Db/Statement/Pdo.php:225 with message: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails ("director"."icinga_service", CONSTRAINT "icinga_service_check_command" FOREIGN KEY ("check_command_id") REFERENCES "icinga_command" ("id") ON UPDATE CASCADE), query was: DELETE FROM icinga_command WHERE (id = '237')

icingacli director basket restore --purge ServiceTemplate --force < empty.json
ERROR: InvalidArgumentException in /usr/share/icingaweb2/modules/director/library/Director/Data/Db/DbObject.php:894 with message: icinga_service has a multicolumn key, array required

THX André

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants