def get_bulk(self, oid, non_repeaters=0, max_repetitions=10, base_oid=None): """ Takes a single numeric oid and returns a list of PanoptesSNMPVariables which start with the oid Args: oid (str): A numeric oid non_repeaters (int): A non-negative integer max_repetitions (int): A non-negative integer base_oid (str): An optional numeric oid which is used to set the oid in the returned PanoptesSNMPVariables Returns: list(): A list of PanoptesSNMPVariables starting with the provided oid """ assert PanoptesValidators.valid_numeric_snmp_oid(oid), u'oid must be numeric string with a leading period' assert PanoptesValidators.valid_positive_integer(non_repeaters), u'non_repeaters must a positive integer' assert PanoptesValidators.valid_positive_integer(max_repetitions), u'max_repetitions must a positive integer' assert (base_oid is None) or PanoptesValidators.valid_numeric_snmp_oid( base_oid), u'oid must be numeric string with a leading period' assert self._easy_snmp_session is not None, u'PanoptesSNMPSession not initialized' try: varbinds = self._easy_snmp_session.get_bulk(oids=oid, non_repeaters=non_repeaters, max_repetitions=max_repetitions) result = list() for varbind in varbinds: if varbind.oid.startswith(base_oid): result.append(PanoptesSNMPVariable(queried_oid=base_oid if base_oid else oid, oid=varbind.oid, index=varbind.oid_index, value=varbind.value, snmp_type=varbind.snmp_type)) return result except Exception as e: raise self._wrap_panoptes_snmp_exception(e)
def test_valid_numeric_snmp_oid(self): self.assertTrue( PanoptesValidators.valid_numeric_snmp_oid( u".1.3.6.1.4.1.2636.3.1.13.1.6.2.1.0.0")) self.assertFalse( PanoptesValidators.valid_numeric_snmp_oid( u"1.3.6.1.4.1.2636.3.1.13.1.6.2.1.0.0"))
def bulk_walk(self, oid, non_repeaters=0, max_repetitions=10): """ Takes a single numeric oid and fetches oids under it's subtree using GETBULKs Args: oid (str): A numeric oid non_repeaters (int): A non-negative integer max_repetitions (int): A non-negative integer Returns: list(PanoptesSNMPVariable): A list of PanoptesSNMPVariables within the subtree of the provided oid """ assert PanoptesValidators.valid_numeric_snmp_oid(oid), u'oid must be numeric string with a leading period' assert PanoptesValidators.valid_positive_integer(non_repeaters), u'non_repeaters must a positive integer' assert PanoptesValidators.valid_positive_integer(max_repetitions), u'max_repetitions must a positive integer' assert self._easy_snmp_session is not None, u'PanoptesSNMPSession not initialized' base_oid = oid varbinds = list() running = 1 while running: results = self.get_bulk(oid=oid, non_repeaters=non_repeaters, max_repetitions=max_repetitions, base_oid=base_oid) varbinds.extend(results) if len(results) < max_repetitions: break oid = base_oid + u'.' + results[-1].index return varbinds
def get(self, oid): """ Takes a single numeric oid and returns a PanoptesSNMPVariable containing the queried oid, index, value and type Args: oid (str): A numeric oid Returns: PanoptesSNMPVariable: A PanoptesSNMPVariable containing the queried oid, index, value and type """ assert PanoptesValidators.valid_numeric_snmp_oid(oid), u'oid must be numeric string with a leading period' assert self._easy_snmp_session is not None, u'PanoptesSNMPSession not initialized' try: varbind = self._easy_snmp_session.get(oids=oid) return PanoptesSNMPVariable(queried_oid=oid, oid=varbind.oid, index=varbind.oid_index, value=varbind.value, snmp_type=varbind.snmp_type) except Exception as e: raise self._wrap_panoptes_snmp_exception(e)