Skip to content

Instantly share code, notes, and snippets.

@dougsyer
Created October 25, 2017 16:35
Show Gist options
  • Save dougsyer/a5dc4cbadabc550b3db95cd80ef08267 to your computer and use it in GitHub Desktop.
Save dougsyer/a5dc4cbadabc550b3db95cd80ef08267 to your computer and use it in GitHub Desktop.
Auto adding traps in zenoss from mib imported into zneoss
from Products.ZenEvents.EventClassInst import manage_addEventClassInst
from Products.ZenUtils.Utils import prepId
# get mib organizer
MIBS = dmd.Mibs
org = MIBS.CISCO.SB # CHANGEME: this is the container your mib is in
mib = getattr(org.mibs, 'CISCOSB-TRAPS-MIB') # CHANGEME: this points to the MIB
"""
properties on notications are:
oid
moduleName
nodetype
objects
id
status
"""
all_traps = [(notif.id, notif.description, notif.objects) for notif in mib.notifications()]
# get event CLass
ec = dmd.Events.Unknown.Testing.CiscoSBSwitches # CHANGEME: this is your final event class
"""
how to add single event CLass INstance
1. assign variable to evnent class then create like this
manage_addEventClassInst(ec.instances, 'test123233')
note - sequence not created for some reason when do though gui
so you can manually assign it, just assign it 0...but you need though
make sure this isnt a duplicate event class key...if it is you need to
ideally deal with that....
so you can do
inst = gettattr(ec.instances, 'test123233')
inst.sequence = 0
next you have to call this to modify attribs
def manage_editEventClassInst(self, name='', eventClassKey='',
regex='', rule='', example='',
transform='',
explanation='', resolution='', REQUEST=None):
TO DO>>>make sure no non-askii chars in explanation..
"""
for _id, explanation, example in all_traps:
instance_id = prepId(_id)
if not hasattr(ec.instances, instance_id):
manage_addEventClassInst(ec.instances, instance_id)
commit()
sync()
sync()
for sequence, (_id, explanation, example) in enumerate(all_traps):
instance_id = prepId(_id)
eck = getattr(ec.instances, instance_id)
eck.manage_editEventClassInst(
example=str(example),
explanation=explanation,
eventClassKey=_id)
eck.sequence = sequence
commit()
sync()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment