{"id":698,"date":"2015-11-25T12:09:16","date_gmt":"2015-11-25T11:09:16","guid":{"rendered":"http:\/\/www.netnea.com\/cms\/?p=698"},"modified":"2015-11-25T12:13:22","modified_gmt":"2015-11-25T11:13:22","slug":"efficient-component-look-up-in-zenoss","status":"publish","type":"post","link":"https:\/\/www.netnea.com\/cms\/2015\/11\/25\/efficient-component-look-up-in-zenoss\/","title":{"rendered":"Efficient component look-up in Zenoss"},"content":{"rendered":"<p>&#8230; or how to find an interface object from d.os.interfaces() or d.hw.fans() without a loop.<\/p>\n<p>The problem: in Zenoss transforms, I often need to do a check on an attribute of a component, e.g. re.search(&#8216;stuff&#8217;, interface.description). The problem is, the event component does not contain the &#8220;interface&#8221; object. Instead, it contains the interface.getInterfaceName() string. The usual way to find the object until now was:<\/p>\n<pre>for iface in device.os.interfaces():\r\n    if iface.getInterfaceName() == evt.component:\r\n        # found\r\n        if re.search('stuff', iface.description):\r\n            # do something\r\n        break\r\n<\/pre>\n<p>For devices with huge number of interfaces (Cisco 4500 or Cisco Nexus), this took often 40-100 ms, which is a lot\u00a0inside an event transform. Just imagine a small flood of events&#8230;<\/p>\n<p>The solution: found in a transformation by Lionel Seydoux:<\/p>\n<pre>iface =\u00a0d.os.interfaces._getOb(evt.component)\r\nif re.search('stuff', iface.description):\r\n    # do something\r\n<\/pre>\n<p>Works as well for other elements, e.g. a fan:<\/p>\n<pre>d.hw.fans._getOb('Switch_1, Fan_1')\r\n<\/pre>\n<p>Now I&#8217;m not sure what _getOb() really does. Maybe it loops as well. But still, the code is much nicer without these unrolled loops.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230; or how to find an interface object from d.os.interfaces() or d.hw.fans() without a loop. The problem: in Zenoss transforms, I often need to do a check on an attribute of a component, e.g. re.search(&#8216;stuff&#8217;, interface.description). The problem is, the event component does not contain the &#8220;interface&#8221; object. Instead, it contains the interface.getInterfaceName() string. The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":{"0":"post-698","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-nms","7":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts\/698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/comments?post=698"}],"version-history":[{"count":4,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":702,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/posts\/698\/revisions\/702"}],"wp:attachment":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/media?parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/categories?post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/tags?post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}