Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zenoss Contents
#!/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()
@harpermann

This comment has been minimized.

Copy link

commented Jun 1, 2015

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.

@acondoriml

This comment has been minimized.

Copy link

commented Jun 10, 2015

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
You can’t perform that action at this time.