Difference between revisions of "ZenDMD Tip - ShowEventMappingsAndTransforms"

From Zenoss Wiki
Jump to: navigation, search
(Created page with "<syntaxhighlight lang=javascript> #!/opt/zenoss/bin/pythonimport Globalsfrom Products.ZenUtils.ZenScriptBase import ZenScriptBasedmd = ZenScriptBase(connect=True).dmdOrganizer...")
 
Line 1: Line 1:
 
<syntaxhighlight lang=javascript>
 
<syntaxhighlight lang=javascript>
#!/opt/zenoss/bin/pythonimport Globalsfrom Products.ZenUtils.ZenScriptBase import ZenScriptBasedmd = ZenScriptBase(connect=True).dmdOrganizers = dmd.Events.getSubOrganizers()Organizers.insert(0, dmd.Events)def get_transforms():   for ec in Organizers:       if ec:           if ec.transform:               print "= %s ===" % ec.getOrganizerName()               print "<transform>"               print ec.transform               print "</transform>\n"               print           for i in ec.instances():               if (i.eventClassKey or i.rule or i.regex or i.transform) is not '':                   print "= %s/%s ===\n" % (ec.getOrganizerName(), i.id)                   if i.eventClassKey:                       print "<eventClassKey>"                       print i.eventClassKey                       print "</eventClassKey>\n"                   if i.rule:                       print "<rule>"                       print i.rule                       print "</rule>\n"                   if i.regex:                       print "<regex>"                       print i.regex                       print "</regex>\n"                   if i.transform:                       print "<transform>"                       print i.transform                       print "</transform>\n"                       printif __name__ == '__main__':   get_transforms()
+
#!/opt/zenoss/bin/python
 +
import Globals
 +
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
 +
dmd = ZenScriptBase(connect=True).dmd
 +
Organizers = dmd.Events.getSubOrganizers()
 +
Organizers.insert(0, dmd.Events)
 +
 
 +
def get_transforms():
 +
    for ec in Organizers:
 +
        if ec:
 +
            if ec.transform:
 +
                print "= %s ===" % ec.getOrganizerName()
 +
                print "<transform>"
 +
                print ec.transform
 +
                print "</transform>\n"
 +
                print
 +
            for i in ec.instances():
 +
                if (i.eventClassKey or i.rule or i.regex or i.transform) is not '':
 +
                    print "= %s/%s ===\n" % (ec.getOrganizerName(), i.id)
 +
                    if i.eventClassKey:
 +
                        print "<eventClassKey>"
 +
                        print i.eventClassKey
 +
                        print "</eventClassKey>\n"
 +
                    if i.rule:
 +
                        print "<rule>"
 +
                        print i.rule
 +
                        print "</rule>\n"
 +
                    if i.regex:
 +
                        print "<regex>"
 +
                        print i.regex
 +
                        print "</regex>\n"
 +
                    if i.transform:
 +
                        print "<transform>"
 +
                        print i.transform
 +
                        print "</transform>\n"
 +
                        print
 +
 
 +
if __name__ == '__main__':
 +
    get_transforms()
  
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Tips]]
 
[[Category:Tips]]

Revision as of 20:17, 31 January 2013

#!/opt/zenoss/bin/python
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
dmd = ZenScriptBase(connect=True).dmd
Organizers = dmd.Events.getSubOrganizers()
Organizers.insert(0, dmd.Events)
 
def get_transforms():
    for ec in Organizers:
        if ec:
            if ec.transform:
                print "= %s ===" % ec.getOrganizerName()
                print "<transform>"
                print ec.transform
                print "</transform>\n"
                print
            for i in ec.instances():
                if (i.eventClassKey or i.rule or i.regex or i.transform) is not '':
                    print "= %s/%s ===\n" % (ec.getOrganizerName(), i.id)
                    if i.eventClassKey:
                        print "<eventClassKey>"
                        print i.eventClassKey
                        print "</eventClassKey>\n"
                    if i.rule:
                        print "<rule>"
                        print i.rule
                        print "</rule>\n"
                    if i.regex:
                        print "<regex>"
                        print i.regex
                        print "</regex>\n"
                    if i.transform:
                        print "<transform>"
                        print i.transform
                        print "</transform>\n"
                        print
 
if __name__ == '__main__':
    get_transforms()