JosefJezek
3/7/2013 - 6:11 PM

snmpindex_dct example usage

snmpindex_dct example usage

from Products.DataCollector.plugins.CollectorPlugin import SnmpPlugin
from Products.DataCollector.plugins.CollectorPlugin import GetTableMap


class MyPlugin(SnmpPlugin):
    relname = 'myrelation'
    modname = 'ZenPacks.example.MyStuff'

    snmpGetTableMaps = (
        GetTableMap('sometable',
            '1.3.6.1.4.1.58172.100.1.1', {
                '.1': 'someIndex',
                '.2': 'someAlternateIndex',
                '.3': 'someName',
            })
        )

    def process(self, device, results, log):
        rm = self.relMap()
        for snmpindex, row in results[1].get('sometable').items():

            # Any SNMP datasources with the 1.3.6.1.4.1.58172.200.1.1
            # prefix will use someAlternateIndex as their snmpindex
            # instead of the component's snmpindex attribute.
            snmpindex_dct = {
                '1.3.6.1.4.1.58172.200.1.1': row.get('someAlternateIndex'),
                }

            om = self.objectMap({
                'id': self.prepId(row['someName']),
                'title': row.get('someName'),
                'snmpindex_dct': snmpindex_dct,
                })

        return rm