Debugging Event Transforms

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

You can run zeneventd in the foreground with zeneventd run -v10 (you do not need to stop the existing zeneventd service). If you add import pdb; pdb.set_trace() to a transform, then cause an event that executes the transform, you will get a (Pdb) prompt in your zeneventd window. This allows you to interactively look at evt and all of the other variables available to your transform. If you do not have zeneventd running as debug and your transform has the pdb code above in it, the transform will error with an exception "BdbQuit". See the following examples for how to look at the event details.

(Pdb) # Introspecting evt in a transform.
(Pdb) p dir(evt)
(Pdb) pp dir(evt)
(Pdb) pp dir(evt.details._map.keys())
(Pdb) # Any value that comes back from details._map.keys()
(Pdb) value = getattr(evt, 'netBotzV2TrapSensorID', '')

Sometimes you don’t know the exact name of the event detail. The following transform code shows how you can loop through all of the details looking for detail names that start with a specific value.

# Check all event details for varbinds that start with 1.3.6.1.4.1.x
for detail in evt.details._map.keys():
    if detail.startswith('1.3.6.1.4.1.x'):
        varbind_value = getattr(evt, detail)

The same in functional-style. For pdb, not for transforms.

(Pdb) [ getattr(evt, x) for x in evt.details._map.keys() if x.startswith('netBotz')]