Tuesday, November 2, 2010

Displaying Even Classes on the command line

I whipped up a little script the other day to check all my events for typos and such.  It can also be easily modified to clear out rules, regex or transforms in event classes.  Just be sure to call commit() if you do modify any data.

Here it is:

#!/usr/bin/env python
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
dmd = ZenScriptBase(connect=True).dmd

def _displayEventRules(evtclass):
    for eclass in evtclass.getSubOrganizers():
        _displayEventRules(eclass)

    for inst in evtclass.instances():
        out = ""
        if inst.rule:
            out += "  [rule]  " + str(inst.rule) +"\n"
        if inst.regex:
            out += "  [regex] " + str(inst.regex) +"\n"
        if inst.transform:
            out += "  [transform] " + str(inst.regex) +"\n"
        if out:
            print str(evtclass.getOrganizerName())
            print out
            print
            
def displayEventClasses():
    for e in dmd.Events.getSubOrganizers():
        _displayEventRules(e)

displayEventClasses()

No comments:

Post a Comment