def _lldplocportid(self, oidonly=False): """Return dict of LLDP-MIB lldpLocPortId for each port. Args: oidonly: Return OID's value, not results, if True Returns: data_dict: Dict of lldpLocPortId using ifIndex as key """ # Initialize key variables data_dict = defaultdict(dict) # Descriptions oid = '.1.0.8802.1.1.2.1.3.7.1.3' # Return OID value. Used for unittests if oidonly is True: return oid # Process results results = self.snmp_object.swalk(oid, normalized=True) for key, value in results.items(): data_dict[int(key)] = general.cleanstring( str(bytes(value), encoding='utf-8')) # Return the interface descriptions return data_dict
def lldpremportdesc(self, oidonly=False): """Return dict of LLDP-MIB lldpRemPortDesc for each port. Args: oidonly: Return OID's value, not results, if True Returns: data_dict: Dict of lldpRemPortDesc using ifIndex as key """ # Initialize key variables data_dict = defaultdict(dict) # Descriptions oid = '.1.0.8802.1.1.2.1.4.1.1.8' # Return OID value. Used for unittests if oidonly is True: return oid # Process results results = self.snmp_object.swalk(oid, normalized=False) for key, value in results.items(): # Check if this OID is indexed using iFindex or dot1dBasePort ifindex = self._ifindex(key) # We have seen issues where self.baseportifindex doesn't always # return a complete dict of values that include all ifindexes if bool(ifindex) is True: data_dict[ifindex] = general.cleanstring( str(bytes(value), encoding='utf-8')) # Return the interface descriptions return data_dict
def test_cleanstring(self): """Testing method / function cleanstring.""" # Initializing key variables dirty_string = (' %s\n \r %s \n %s ') % ( self.random_string, self.random_string, self.random_string) clean_string = ('%s %s %s') % (self.random_string, self.random_string, self.random_string) # Test result result = general.cleanstring(dirty_string) self.assertEqual(result, clean_string)
def system(self): """Get system data from device. Args: None Returns: final: Final results """ # Initialize key variables data_dict = defaultdict(lambda: defaultdict(dict)) final = {} getvalues = [0] key = 0 # Process oidroot = '.1.3.6.1.2.1.1' for node in range(1, 7): oid = ('%s.%s.0') % (oidroot, node) results = self.snmp_object.get(oid, normalized=True) for value in results.values(): getvalues.append(value) # Assign values data_dict['sysDescr'][key] = general.cleanstring( getvalues[1].decode('utf-8')) data_dict['sysObjectID'][key] = getvalues[2].decode('utf-8') data_dict['sysUpTime'][key] = int(getvalues[3]) data_dict['sysContact'][key] = getvalues[4].decode('utf-8') data_dict['sysName'][key] = getvalues[5].decode('utf-8') data_dict['sysLocation'][key] = getvalues[6].decode('utf-8') # Return final['SNMPv2-MIB'] = data_dict return final