2010-03-12

Two useful Zendmd commands on Event Management

1. dmd.ZenEventManager.getEventList()

This command can get a full list of active events objects

2.dmd.Events.manage_ackEvents()

This command can acknoledge a event, with the evid provided.

An example to utilize these two commands,

++++++++++++++++++++++++++++++++++++++

events = dmd.ZenEventManager.getEventList()

for e in events:

if e.eventClass == "/Perf/CPU":

dmd.Events.manage_ackEvents(e.evid)

++++++++++++++++++++++++++++++++++++++

This script will search all the active events, if the events is from Class "/Perf/CPU", script will acknowledge the event. If you want to delete them, dmd.Events.manage_deleteEvents() will do the job.

3. For a Event object, below properties can be very useful when you want to find cerntain type of events to work with.

e.eventClass: the event classs, such as "/Perf/CPU", "/Status/Ping"

Code Example: if e.eventClass == "/Perf/CPU":

e.eventState: the event state in number, 0 is active non acknoledged; 1 is acknoledged.

Code Example: if e.eventState == 1:

e.summary: the description about the events, such as “disk space usage 100%". It is a string type of variable, so you can apply all the string operation on it. str.split, str.replace.

e.device: the device name associate with this event.

Code Example: if e.device == "wwwsrv1":

e.evid: the event evid, whichi s a uniq identifier for a event. Many event operations require the evid as the parameter.

Code Example: dmd.Events.manage_ackEvents(e.evid)

2010-01-27

Migrate devices from Zenoss 2.3.0 to Zenoss 2.5.1

We have about 250 devices monitoring in a Zenoss Core 2.3.0. Now we decided to move the 2.5.1. The information we want to migrate from 2.3.0 is the devices, device group and device production state. The migration took two steps.

1.

zendevicedump -o

Run this command on 2.3.0. A xml generated contains device name and group information.

zendeviceload -i

Run this command on 2.5.1. All device were correctly loaded, and groups were created. Devices were correctly grouped according the xml.

The issue here is that the 'production state' was not exported to the xml file, so all devices in 2.5.1 are in 'production' state. To fix this issue, the DMD interface did the job.

2.Utilize the zendmd interface to export and import the device prodState and

2.1 Export from 2.3.0

f=open("/tmp/prodstat.txt","w")
for d in dmd.Devices.getSubDevices():
f.write(d.getDeviceName()+" "+d.getProdState()+"\n")
f.close()

2.2 Import to 2.5.1

>>> f=open("/tmp/prodstat.txt","r")
>>> for l in f:
... l = l.rstrip()
... name, state = l.split(" ")
... if state == "Decommissioned":
... number = -1
... elif state == "Maintenance":
... number = 300
... elif state == "Test":
... number = 400
... elif state == "Pre-Production":
... number = 500
... elif state == "Production":
... number = 1000
... d = find(name)
... d.setProdState(number)
...

>>>commit()

I have referenced to many articles in Zenoss Community, thanks.