Discussion:
Help improving an event transform
tcaiazza
2011-11-28 20:51:11 UTC
Permalink
tcaiazza [http://community.zenoss.org/people/tcaiazza] created the discussion

"Help improving an event transform"

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

--------------------------------------------------------------
I have an event transform which I was hoping someone could help improve for me.  The first part is I want to load the device object, so I've seen a bunch of examples where it is written like this

for d in dmd.Devices.getSubDevices():
if d.id == evt.device:
  dev = d

Does anyone know if there is a way to say something like this instead of having to loop through all the devices?

d = dmd.Devices.getDevice(devicename)


Next I want to load a specific interface object for that device, so I have this

for int in dev.os.interfaces():
if int.ifindex == evt.pimNeighborIfIndex:
  ifdescr = int.id

Again, I was hoping there was a way I could say something like whats below without having to loop through all the interfaces.

int = dev.os.interface( evt.pimNeighborIfIndex )
--------------------------------------------------------------

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

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]
tcaiazza
2011-11-28 21:14:38 UTC
Permalink
tcaiazza [http://community.zenoss.org/people/tcaiazza] created the discussion

"Re: Help improving an event transform"

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

--------------------------------------------------------------
Ok so I found the first part

dev = dmd.Devices.findDevice(evt.device)

Anyone know if there is something like the findDevice command for the interfaces?
--------------------------------------------------------------

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

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]
dpetzel
2011-11-29 03:33:06 UTC
Permalink
dpetzel [http://community.zenoss.org/people/dpetzel] created the discussion

"Re: Help improving an event transform"

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

--------------------------------------------------------------
Perhaps this could work (Its untested in the context of a transform). You should be able to use getattr to fetch the the interface by name/id. I'm not sure if you have to use pimNeighborIfIndex as in your example or if the interface id is exposed in a way you can use it.
int = getattr(dev.os.interfaces, "eth0", None)
print int
<IpInterface at eth0>
int = getattr(dev.os.interfaces, "bogus0", None)
print int
None
--------------------------------------------------------------

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

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]
tcaiazza
2011-11-29 16:53:10 UTC
Permalink
tcaiazza [http://community.zenoss.org/people/tcaiazza] created the discussion

"Re: Help improving an event transform"

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

--------------------------------------------------------------
The pimNeighborIfIndex (16777309) is what the trap sends me, and with that I'm trying to get the interface's name/id.

So the getattr isn't quite what I'm looking for, unless I can have it look at something other than the id.  Is that possible? 
int = getattr(dev.os.interfaces,"16777309",None)
print int
int = getattr(dev.os.interfaces,"v93",None)
print int
<IpInterface at v93>
int.id
'v93'
int.ifindex
16777309
--------------------------------------------------------------

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

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]
dpetzel
2011-11-30 03:25:53 UTC
Permalink
dpetzel [http://community.zenoss.org/people/dpetzel] created the discussion

"Re: Help improving an event transform"

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

--------------------------------------------------------------
I'm sure there is probably a way, but I'm not too sure what it would it be. I'd have to defer to folks that know more about the system than I. However given that your already limiting the loop to just a single device it would seem "OK" to run through the loop, but obviously directing fetching the object rather than looping would be less overhead and a little cleaner.

Sorry I dont have a better answer.
--------------------------------------------------------------

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

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...