def process(self, device, results, log): """collect snmp information from this device""" log.info('processing %s for device %s', self.name(), device.id) getdata, tabledata = results vports = tabledata.get("vport") # Debug: print data retrieved from device. log.debug( "Get data = %s", getdata ) log.debug( "Table data = %s", tabledata ) # If no data retrieved return nothing. if not vports: log.warn( 'No data collected from %s for the %s plugin', device.id, self.name() ) return rm = self.relMap() def spt(string, size): return [string[i:i+size] for i in range(0, len(string), size)] for oid, data in vports.iteritems(): try: om = self.objectMap(data) om.intname = ifix(self, om.intname, om.vlanportindex) om.id = self.prepId(om.intname) om.snmpindex = om.vlanportindex if om.vlanporttype not in self.porttype.keys(): om.vlanporttype = 3 if om.vlantag not in self.tagtype.keys(): om.vlantag = 3 om.vlanporttype = self.porttype[om.vlanporttype] om.vlantag = self.tagtype[om.vlantag] om.vlanportids = binascii.hexlify(om.vlanportids) vlanid = spt(om.vlanportids, 4) list = [] for port in vlanid: list.append(int(port, 16)) om.vlanportids = list except AttributeError: continue rm.append(om) return rm
def process(self, device, results, log): """ From SNMP info gathered from the device, convert them to interface objects. """ getdata, tabledata = results log.info('Modeler %s processing data for device %s', self.name(), device.id) log.debug( "%s tabledata = %s" % (device.id,tabledata) ) rm = self.relMap() iptable = tabledata.get("ipAddrTable") sourceTable = 'ipAddrTable' if not iptable: iptable = tabledata.get("ipNetToMediaTable") if iptable: log.info("Unable to use ipAddrTable -- using ipNetToMediaTable instead") sourceTable = 'ipNetToMediaTable' else: log.warn("Unable to get data for %s from either ipAddrTable or" " ipNetToMediaTable" % device.id) iptable = dict() iftable = tabledata.get("iftable") if iftable is None: log.error("Unable to get data for %s for iftable -- skipping model" % device.id) return None ifalias = tabledata.get("ifalias", {}) self.prepIfTable(log, iftable, ifalias) omtable = {} # Process Avaya (Nortel) Interface Alias for key, iface in iftable.items(): if key in ifalias: try: iftable[key]['id'] = ifix(self, ifalias[key].get('ifName', ''), iftable[key].get('ifindex', '')) except AttributeError: iftable[key]['id'] = ifalias[key].get('ifName', '') duplex = tabledata.get("duplex", {}) # Process Avaya (Nortel) Interface Duplex for key, iface in iftable.items(): if key in duplex: iftable[key]['duplex'] = duplex[key].get('duplex', 0) if iftable[key]['duplex'] == 1: iftable[key]['duplex'] = 2 elif iftable[key]['duplex'] == 2: iftable[key]['duplex'] = 3 else: iftable[key]['duplex'] = 0 for ip, row in iptable.items(): #FIXME - not getting ifindex back from HP printer if 'ifindex' not in row: log.debug( "IP entry for %s is missing ifindex" % ip) continue ip_parts = ip.split('.') # If the ipAddrTable key has five octets, that probably # means this is a classless subnet (that is, <256). Usually, # the first 4 octets will be the ipAddress we care about. # Regardless, we will be using the ip address in the row # later anyway. if len(ip_parts) == 5 and sourceTable == 'ipAddrTable': ip = '.'.join(ip_parts[:-1]) # If we are using the ipNetToMediaTable, we use the # last 4 octets. elif len(ip_parts) == 5 and sourceTable == 'ipNetToMediaTable': if row['iptype'] != 1: log.debug("iptype (%s) is not 1 -- skipping" % ( row['iptype'] )) continue ip = '.'.join(ip_parts[1:]) log.warn("Can't find netmask -- using /24") row['netmask'] = '255.255.255.0' strindex = str(row['ifindex']) if strindex not in omtable and strindex not in iftable: log.warn("Skipping %s as it points to missing ifindex %s", row.get('ipAddress',""), row.get('ifindex',"")) continue if strindex not in omtable: om = self.processInt(log, device, iftable[strindex]) if not om: continue rm.append(om) omtable[strindex] = om del iftable[strindex] elif strindex in omtable: om = omtable[strindex] else: log.warn("The IP %s points to missing ifindex %s -- skipping" % ( ip, strindex) ) continue if not hasattr(om, 'setIpAddresses'): om.setIpAddresses = [] if 'ipAddress' in row: ip = row['ipAddress'] if 'netmask' in row: ip = ip + "/" + str(self.maskToBits(row['netmask'].strip())) # Ignore IP addresses with a 0.0.0.0 netmask. if ip.endswith("/0"): log.warn("Ignoring IP address with 0.0.0.0 netmask: %s", ip) else: om.setIpAddresses.append(ip) #om.ifindex = row.ifindex #FIXME ifindex is not set! for iface in iftable.values(): om = self.processInt(log, device, iface) if om: rm.append(om) return rm