Discussion:
Ignoring AttributeError for devices without a group when using evt.DeviceGroups in a transform
0graham0
2011-11-15 18:27:31 UTC
Permalink
0graham0 [http://community.zenoss.org/people/0graham0] created the discussion

"Ignoring AttributeError for devices without a group when using evt.DeviceGroups in a transform"

To view the discussion, visit: http://community.zenoss.org/message/62623#62623

--------------------------------------------------------------
Hi all. I had an event transform set up in zenoss 3.2.0 using the evt.DeviceGroup attribute. I was getting the following errors in event.log (a lot of these over and over):

2011-11-15T11:42:43 WARNING zen.Events Error processing transform/mapping on Event Class /
Problem on line 0: AttributeError: Event instance has no attribute 'DeviceGroups'
if evt.DeviceGroups == '|/GroupName':


This was the transform:

if evt.DeviceGroups == '|/GroupName':
    con = device.findDevice('DeviceDependency')
    if con.getPingStatus() > 0:
        evt.eventState = 2 # suppressed
        evt.severity = 0 # clear


After reading http://stackoverflow.com/questions/610883/how-to-know-if-an-object-has-an-attribute-in-python http://stackoverflow.com/questions/610883/how-to-know-if-an-object-has-an-attribute-in-python and http://stackoverflow.com/questions/574730/python-how-to-ignore-an-exception-and-proceed http://stackoverflow.com/questions/574730/python-how-to-ignore-an-exception-and-proceed I changed the transform to:

try:
    if evt.DeviceGroups == '|/VP':
        con = device.findDevice('Carlsbad VPN Concentrator')
        if con.getPingStatus() > 0:
            evt.eventState = 2 # suppressed
            evt.severity = 0 # clear
except AttributeError:
    sys.exc_clear()



Does this look like a better transform? Does anyone have a better recommendation?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/62623#62623]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Shane Scott
2011-11-17 09:24:33 UTC
Permalink
Shane Scott [http://community.zenoss.org/people/hackman238] created the discussion

"Re: Ignoring AttributeError for devices without a group when using evt.DeviceGroups in a transform"

To view the discussion, visit: http://community.zenoss.org/message/62669#62669

--------------------------------------------------------------
0graham0:

If some events have this attribute and others dont't, you might do the following:

if device and evt.DeviceGroups:
    if evt.DeviceGroups == '|/GroupName':
        con = device.findDevice('DeviceDependency')
        if con.getPingStatus() > 0:
            evt.eventState = 2 # suppressed
            evt.severity = 0 # clear


'if device' ensures the device in the event exists. 'if evt.DeviceGroups' qualifies if the attribute exists and is not None.

Best,
--Shane (Hackman238)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/62669#62669]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
0graham0
2011-11-17 14:03:56 UTC
Permalink
0graham0 [http://community.zenoss.org/people/0graham0] created the discussion

"Re: Ignoring AttributeError for devices without a group when using evt.DeviceGroups in a transform"

To view the discussion, visit: http://community.zenoss.org/message/62673#62673

--------------------------------------------------------------
Thanks very much
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/62673#62673]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Loading...