Hmm... I was trying to find a better way to do it, so here's my rundown of my update script:
1. Poll Oracle database (cmdb) for all switches, access points, upses, etc 2. Parse all object data (switches, access points, UPSes, etc), includes parent device (ex. uplink switch) 3. Verify if object exists in Icinga2 via API (to set POST or PUT) 4. Add/Update object in Icinga2 API 5. Verify if child/parent dependency already exists in Icinga2 via API (to set POST or PUT) 6. Add/update the dependency in Icinga2 API 7. Delete all old hosts created via API 8. Delete all old dependencies created via API Now, step 7 and 8 are interesting, how do I delete all 'old' devices..? When starting my update script I take the current time stamp and put this into a var (vars.database_run = script run time) as well as another variable (vars.database_source = cmdb) To then delete the old hosts & dependencies I run a DELETE for all entries that match the vars.database_source = cmdb and vars.database_run not like the current time of the new script run. This works fine for hosts, but I don't think it is working right for dependencies with parent hosts that were created in conf files (not via API). My example: curl -k -s -u 'root:icinga' \ -H 'Accept: application/json' \ -X GET 'https://localhost:5665/v1/objects/dependencies' \ -d '{ "filter": "match(\"cmdb\",dependency.vars.database_source)"}' \ | python -m json.tool { "results": [ { "attrs": { "__name": "1010sherb-sw1!bronfman-c6k", "active": true, "child_host_name": "1010sherb-sw1", "child_service_name": "", "disable_checks": false, "disable_notifications": true, "ha_mode": 0.0, "ignore_soft_states": true, "name": "bronfman-c6k", "original_attributes": { "child_host_name": "1010sherb-sw1", "parent_host_name": "bronfman-c6k", "vars": null }, "package": "_etc", "parent_host_name": "bronfman-c6k", "parent_service_name": "", "paused": false, "period": "", "states": null, "templates": [ "bronfman-c6k" ], "type": "Dependency", "vars": { "database_run": "Fri Sep 30 10:11:11 2016", "database_source": "cmdb", "device_type": "cisco_switch" }, "version": 1475244672.135489, "zone": "" }, "joins": {}, "meta": {}, "name": "1010sherb-sw1!bronfman-c6k", "type": "Dependency" }, The I try and delete with the same filter: curl -k -s -u 'root:icinga' \ -H 'Accept: application/json' \ -X DELETE 'https://localhost:5665/v1/objects/dependencies' \ -d '{ "filter": "match(\"cmdb\",dependency.vars.database_source)"}' \ | python -m json.tool I notice that the dependencies that were created with two hosts via the API are deleted, however I also have hosts (mostly more core and distribution routers) that were created using conf files. The dependencies that are created with these hosts as parents are not deleted! example: "code": 500.0, "errors": [ "Object cannot be deleted because it was not created using the API." ], "name": "1010sherb-sw2!bronfman-c6k", "status": "Object could not be deleted.", "type": "Dependency" Am I doing something wrong here or does this look like a bug? - Zac On Fri, Sep 30, 2016 at 3:24 AM, Michael Friedrich < michael.friedr...@netways.de> wrote: > > > On 29 Sep 2016, at 20:03, Zachary McGibbon <zachary.mcgib...@gmail.com> > wrote: > > > > Is there any way to delete a host dependency with a wildcard? In my > example, I create a dependency for an access point to the switch, but if I > remove the access point I might not know which switch it was connected to > so I would want to clear all upstream dependencies. > > > > Example: > > > > Create dependency: > > > > curl -k -s -u 'root:pass' \ > > -H 'Accept: application/json' \ > > -X PUT 'https://localhost:5665/v1/objects/dependencies/burnside- > 2-ap225!burnside-sw66' \ > > -d '{ "attrs": { "parent_host_name": "burnside-sw66", "child_host_name": > "burnside-2-ap225" } }' \ > > | python -m json.tool > > > > Delete dependency: (DOES NOT WORK??) > > > > # delete object > > curl -k -s -u 'root:pass' \ > > -H 'Accept: application/json' \ > > -X DELETE 'https://localhost:5665/v1/objects/dependencies' \ > > -d '{ "filter": "match(\"burnside-2-ap225\",child_host_name)"}' \ > > | python -m json.tool > > I’d try dependency.child_host_name but generally I’m always interested in > the error message returned by statements in the first place :) > > Kind regards, > Michael > > > -- > Michael Friedrich, DI (FH) > Senior Developer > > NETWAYS GmbH | Deutschherrnstr. 15-19 | D-90429 Nuernberg > Tel: +49 911 92885-0 | Fax: +49 911 92885-77 > CEO: Julian Hein, Bernd Erk | AG Nuernberg HRB18461 > http://www.netways.de | michael.friedr...@netways.de > > ** OSMC 2016 - November - netways.de/osmc ** > ** OSDC 2017 - Mai – osdc.de ** > _______________________________________________ > icinga-users mailing list > icinga-users@lists.icinga.org > https://lists.icinga.org/mailman/listinfo/icinga-users >
_______________________________________________ icinga-users mailing list icinga-users@lists.icinga.org https://lists.icinga.org/mailman/listinfo/icinga-users