Created
August 28, 2013 16:21
-
-
Save hackeys/6367951 to your computer and use it in GitHub Desktop.
Zenoss Contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# import the stuff that zendmd needs and create the dmd context | |
import Globals | |
from Products.ZenUtils.ZenScriptBase import ZenScriptBase | |
from transaction import commit | |
dmd = ZenScriptBase(connect=True, noopts=True).dmd | |
# import the stuff that zep needs | |
from Products.Zuul import getFacade, listFacades | |
from zenoss.protocols.jsonformat import from_dict | |
from zenoss.protocols.protobufs.zep_pb2 import EventSummary | |
from Products.ZenEvents.events2.proxy import EventSummaryProxy | |
# function to delete device | |
def delDevice(host): | |
zep = getFacade('zep') | |
zep_host_filter = zep.createEventFilter(element_identifier=host) | |
zep.closeEventSummaries(eventFilter=zep_host_filter) | |
dev = dmd.Devices.findDeviceByIdExact(host) | |
if dev: | |
dev.deleteDevice() | |
commit() | |
# read list of devices from a file and delete them if they exist | |
f = open('devicelist.txt') | |
lines = f.read().splitlines() | |
for l in lines: | |
d = None | |
d = dmd.Devices.findDevice(l) | |
if d: | |
print 'Deleting: %s (%s)' % (d.getDeviceName(), d.getManageIp()) | |
delDevice(l) | |
else: | |
print 'Device %s does not exist.' % (l) | |
f.close() |
May I do this with a zenbatchload file ? for instance:
$ zenbatchdump > devicelist.txt
$ ./file-bulkdevicedeletion-py
Ty!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, This works great, nice script, but it leaves the count in the device classes. I tried reindex, and reboot, but no better, counts are in the device class but no devices are there. How do I fix the device counts? My Zenoss 4.2.5 is patched to current and is on Centos 6.6. I'm adding devices through zenbatchload.