Below is the file 'plugins/cisco_ios.py' from this revision. You can also download the file.
from goatpy.snmpwrapper import snmpwalk import basic_snmp import re def adjacency(table_name, table_io, device): def to_ipaddr(s): if s == None: return s return '.'.join([str(t) for t in map(lambda h: int(h, 16), s.split(' '))]) def to_ascii(s): if s == None: return s asdigits = [int(t, 16) for t in s.split(' ')] asdigits = filter(lambda x: x >= 32 and x <= 122, asdigits) return ''.join([chr(t) for t in asdigits]) row_to_field = { 4 : ('Hex-STRING', 'ip_address'), 6 : ('STRING', 'name'), 7 : ('STRING', 'remote_port') } table = {} for oid, type, value in snmpwalk(device.device_name, device.config['community'], "2c", "SNMPv2-SMI::enterprises.9.9.23.1.2.1.1", ssh_dest=device.config.get('ssh')): id, row = tuple(oid[-2:]), int(oid[-3]) if not table.has_key(id): table[id] = {} match_type, match_name = row_to_field.get(row, (None, None)) if match_name and match_type and match_type == type: table[id][match_name] = value print table for row in table: vals = table[row] if not vals.has_key('ip_address') or not vals.has_key('name') or not vals.has_key('remote_port'): continue ip = to_ipaddr(vals['ip_address']) name = vals['name'][1:-1] remote_port = vals['remote_port'][1:-1] yield device.config['zone'], name, remote_port, ip # see: http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a0080094a9b.shtml def ethernet_forwarding(table_name, table_io, device): yield device.config['zone'], 1, '00:11:24:c7:dd:41', 'en1' def ethernet_vlans(table_name, table_io, device): # walk vtpVlanName for oid, type, value in snmpwalk(device.device_name, device.config['community'], "2c", ".1.3.6.1.4.1.9.9.46.1.3.1.1.4", ssh_dest=device.config.get('ssh')): value = value[1:-1] yield device.config['zone'], int(oid[-1]), value tables = { 'adjacency' : adjacency, 'ethernet_forwarding' : ethernet_forwarding, 'ethernet_vlans' : ethernet_vlans, 'ip_addresses' : basic_snmp.ip_addresses, 'ip_arp' : basic_snmp.ip_arp, 'ip_routing' : basic_snmp.ip_routing } def init(): export['has_table'] = simple_has_table(tables) export['get_table'] = simple_get_table(tables) log("Cisco IOS initialised")