TECHZEN Zenoss User Community ARCHIVE  

Zenoss 4.2.5 Event Transform

Subject: Zenoss 4.2.5 Event Transform
Author: Davide Mancosu
Posted: 2020-12-10 13:57

Hi,

I'm trying to get the value of an attribute contained in event details like this:
ifDescr.21618.36          MTP2_LINK_TS_16
I know how to get the value if the attribute was just "ifDescr", but in this case the numeric code (.21618.36) that follows changes.
For example, if I have an event on MTP2_LINK_TS_17, it change in:
ifDescr.21618.37          MTP2_LINK_TS_17

I know how to get the attribute with getattr() but not in this case.
I need this value to change the event summary and to apply an event de-duplication.
So the question is:
- How can I get the ifDescr value?

------------------------------
Davide Mancosu
system administartor
Tiscali Italia S.p.A.
Cagliari
------------------------------


Subject: RE: Zenoss 4.2.5 Event Transform
Author: Pheripheral Pheripheral
Posted: 2020-12-11 09:02

​Hi,

I came across a similar problem recently, where the event attribute had .0 or .1 etc.. on the end so changed my transforms to use something like the below instaed of getAttr():

# get attribute
for key in evt.details._map.keys():
    if key.startswith('ifDescr'):
        ifDescr = evt.details.get(key)
        break

Essentially, looping through all the event fields and checking which one starts with the string that you're looking for.
As with most things I figured this out with the help of one of Jane Curry's pdf documents, I forget which one.

Hope this helps

------------------------------
Pheripheral Pheripheral
------------------------------


Subject: RE: Zenoss 4.2.5 Event Transform
Author: Davide Mancosu
Posted: 2020-12-11 15:07

Hi,
Thank you for your answer. I'm not a python developer, I work with PHP and javascript.
I have just finished now with a script that works.
This is my code:
if device and evt.DeviceGroups and evt.DeviceGroups == '|/VSTP':
   for i in range(1, 500):
       if (hasattr(evt.details, 'ifDescr.21618.%s' % (i))):
          descr=getattr(evt.details,'ifDescr.21618.%s' % (i))
          evt.summary = descr
          evt.component = descr
it's not as simple and clean as what you suggested but it works. Anyway, out of curiosity, I'll test with the code you suggested.
Regards


------------------------------
Davide Mancosu
system administartor
Tiscali Italia S.p.A.
Cagliari
------------------------------


< Previous
Zenoss 4.2.5 zenbatchload
  Next
Unable to model Juniper edge router
>