Below is the file 'plugins/basic_snmp.py' from this revision. You can also download the file.
# # basic_snmp : stuff a generic managed switch should support # from goatpy.snmpwrapper import snmpwalk plugin_info = { 'description' : '''\ A basic module, which provides as many tables as possible without vendor specific knowledge. It aims to work with any SNMP version 1 device that exports the required MIBs. ''' } def ip_arp(table_name, table_io, device): for oid, type, value in snmpwalk(device.device_name, device.config['community'], "2c", "IP-MIB::ipNetToMediaPhysAddress", ssh_dest=device.config.get('ssh')): ip_address = '.'.join(oid[-4:]) mac_address = value yield device.config['zone'], None, mac_address, ip_address def ip_routing(hostname, community): routes = {} for oid, route_type, value in snmpwalk(hostname, community, "2c", "ipRouteTable"): row_name = oid[0] colon = row_name.rfind(':') if colon <> -1: row_name = row_name[colon+1:] ip_address = '.'.join(oid[-4:]) if not routes.has_key(ip_address): routes[ip_address] = {} routes[ip_address][row_name] = value for row in routes: route = routes[row] route_type = route.get('ipRouteType') if route_type: m = re.match(r'([a-zA-Z]+)\(', route_type) if m: route_type = m.groups()[0] if route.has_key('ipRouteDest') and route.has_key('ipRouteMask'): network = route.get('ipRouteDest') + '/' + str(int_to_length(ip_to_int(route.get('ipRouteMask')))) else: network = None via = route.get('ipRouteNextHop') metric = route.get('ipRouteMetric1') ifindex = route.get('ipRouteIfIndex') if ifindex: ifindex = int(ifindex) yield route_type, ifindex, False, network, via, metric tables = { 'ip_arp' : ip_arp, 'ip_routing' : ip_routing, } def init(): export['has_table'] = simple_has_table(tables) export['get_table'] = simple_get_table(tables) log("basic snmp initialised")