def callback(self, pdu): """netsnmp session callback""" result = [] response = netsnmp.getResult(pdu) try: d, oids_requested = self._signSafePop(self.defers, pdu.reqid) except KeyError: # We seem to end up here if we use bad credentials with authPriv. # The only reasonable thing to do is call all of the deferreds with # Snmpv3Errors. for usmStatsOid, count in response: usmStatsOidStr = asOidStr(usmStatsOid) if usmStatsOidStr == ".1.3.6.1.6.3.15.1.1.2.0": # Some devices use usmStatsNotInTimeWindows as a normal part of the SNMPv3 handshake (JIRA-1565) # net-snmp automatically retries the request with the previous request_id and the values for # msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime from this error packet log.debug("Received a usmStatsNotInTimeWindows error. Some devices use usmStatsNotInTimeWindows as a normal part of the SNMPv3 handshake.") return if usmStatsOidStr == ".1.3.6.1.2.1.1.1.0": # Some devices (Cisco Nexus/MDS) use sysDescr as a normal part of the SNMPv3 handshake (JIRA-7943) log.debug("Received sysDescr during handshake. Some devices use sysDescr as a normal part of the SNMPv3 handshake.") return default_msg = "packet dropped (OID: {0})".format(usmStatsOidStr) message = USM_STATS_OIDS.get(usmStatsOidStr, default_msg) break else: message = "packet dropped" for d in (d for d, rOids in self.defers.itervalues() if not d.called): reactor.callLater(0, d.errback, failure.Failure(Snmpv3Error(message))) return for oid, value in response: if isinstance(value, tuple): value = asOidStr(value) result.append((oid, value)) if len(result)==1 and result[0][0] not in oids_requested: usmStatsOidStr = asOidStr(result[0][0]) if usmStatsOidStr in USM_STATS_OIDS: msg = USM_STATS_OIDS.get(usmStatsOidStr) reactor.callLater(0, d.errback, failure.Failure(Snmpv3Error(msg))) return elif usmStatsOidStr == ".1.3.6.1.6.3.15.1.1.2.0": # we may get a subsequent snmp result with the correct value # if not the timeout will be called at some point self.defers[pdu.reqid] = (d, oids_requested) return if pdu.errstat != netsnmp.SNMP_ERR_NOERROR: # fixme: we can do better: use errback m = PDU_ERRORS.get(pdu.errstat, 'Unknown error (%d)' % pdu.errstat) # log.warning("Packet for %s has error: %s", self.ip, m) result = [] reactor.callLater(0, d.callback, result)
def callback(self, pdu): results = netsnmp.getResult(pdu, self._log) oid, value = results[0] if oid <= self.lastOid: self.stop() else: self.results.append((oid, value)) self.lastOid = oid self.walk(oid)
def callback(self, pdu): results = netsnmp.getResult(pdu) oid, value = results[0] if oid <= self.lastOid: self.stop() else: self.results.append( (oid, value) ) self.lastOid = oid self.walk(oid)
def callback(self, pdu): """netsnmp session callback""" result = [] response = netsnmp.getResult(pdu) try: d, oids_requested = self._signSafePop(self.defers, pdu.reqid) except KeyError: # We seem to end up here if we use bad credentials with authPriv. # The only reasonable thing to do is call all of the deferreds with # Snmpv3Errors. for usmStatsOid, count in response: usmStatsOidStr = asOidStr(usmStatsOid) if usmStatsOidStr == ".1.3.6.1.6.3.15.1.1.2.0": # Some devices use usmStatsNotInTimeWindows as a normal part of the SNMPv3 handshake (JIRA-1565) # net-snmp automatically retries the request with the previous request_id and the values for # msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime from this error packet log.debug( "Received a usmStatsNotInTimeWindows error. Some devices use usmStatsNotInTimeWindows as a normal part of the SNMPv3 handshake." ) return default_msg = "packet dropped (OID: {0})".format( usmStatsOidStr) message = USM_STATS_OIDS.get(usmStatsOidStr, default_msg) break else: message = "packet dropped" for d in (d for d, rOids in self.defers.itervalues() if not d.called): reactor.callLater(0, d.errback, failure.Failure(Snmpv3Error(message))) return for oid, value in response: if isinstance(value, tuple): value = asOidStr(value) result.append((oid, value)) if len(result) == 1 and result[0][0] not in oids_requested: usmStatsOidStr = asOidStr(result[0][0]) if usmStatsOidStr in USM_STATS_OIDS: msg = USM_STATS_OIDS.get(usmStatsOidStr) reactor.callLater(0, d.errback, failure.Failure(Snmpv3Error(msg))) return if pdu.errstat != netsnmp.SNMP_ERR_NOERROR: # fixme: we can do better: use errback m = PDU_ERRORS.get(pdu.errstat, 'Unknown error (%d)' % pdu.errstat) # log.warning("Packet for %s has error: %s", self.ip, m) result = [] reactor.callLater(0, d.callback, result)
def callback(self, pdu): results = netsnmp.getResult(pdu, self._log) for oid, value in results: if oid[:len(self.root)] != self.root: self.stop("table end") return print ".".join(map(str, oid)), ":", repr(value) print if not results: self.stop("empty result") else: self.getbulk(0, self.max, [results[-1][0]])
def callback(self, pdu): results = netsnmp.getResult(pdu) for oid, value in results: if oid[:len(self.root)] != self.root: self.stop("table end") return print '.'.join(map(str, oid)), ':', `value` print if not results: self.stop("empty result") else: self.getbulk(0, self.max, [results[-1][0]])
def callback(self, pdu): result = netsnmp.getResult(pdu) print(result) for oid, value in result: oid = '.'.join(map(str, oid)) print(translateOid(oid), value) print(pdu.command) if pdu.command == SNMP_MSG_TRAP: pass elif pdu.command == SNMP_MSG_TRAP2: pass elif pdu.command == SNMP_MSG_INFORM: pass
def callback(self, pdu): result = netsnmp.getResult(pdu) print result for oid, value in result: oid = '.'.join(map(str, oid)) print translateOid(oid), value print pdu.command if pdu.command == SNMP_MSG_TRAP: pass elif pdu.command == SNMP_MSG_TRAP2: pass elif pdu.command == SNMP_MSG_INFORM: pass
def callback(self, pdu): result = netsnmp.getResult(pdu, self._log) print result for oid, value in result: oid = ".".join(map(str, oid)) print translateOid(oid), value print pdu.command if pdu.command == C.SNMP_MSG_TRAP: pass elif pdu.command == C.SNMP_MSG_TRAP2: pass elif pdu.command == C.SNMP_MSG_INFORM: pass
def callback(self, pdu): """netsnmp session callback""" result = [] response = netsnmp.getResult(pdu) try: d, oids_requested = self._signSafePop(self.defers, pdu.reqid) except KeyError: # We seem to end up here if we use bad credentials with authPriv. # The only reasonable thing to do is call all of the deferreds with # Snmpv3Errors. for usmStatsOid, count in response: usmStatsOidStr = asOidStr(usmStatsOid) if usmStatsOidStr == ".1.3.6.1.6.3.15.1.1.2.0": # Some devices use usmStatsNotInTimeWindows as a normal part of the SNMPv3 handshake (JIRA-1565) # net-snmp automatically retries the request with the previous request_id and the values for # msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime from this error packet log.debug( "Received a usmStatsNotInTimeWindows error. Some devices use usmStatsNotInTimeWindows as a normal part of the SNMPv3 handshake." ) return if usmStatsOidStr == ".1.3.6.1.2.1.1.1.0": # Some devices (Cisco Nexus/MDS) use sysDescr as a normal part of the SNMPv3 handshake (JIRA-7943) log.debug( "Received sysDescr during handshake. Some devices use sysDescr as a normal part of the SNMPv3 handshake." ) return default_msg = "packet dropped (OID: {0})".format( usmStatsOidStr) message = USM_STATS_OIDS.get(usmStatsOidStr, default_msg) break else: message = "packet dropped" for d in (d for d, rOids in self.defers.itervalues() if not d.called): reactor.callLater(0, d.errback, failure.Failure(Snmpv3Error(message))) return for oid, value in response: if isinstance(value, tuple): value = asOidStr(value) result.append((oid, value)) if len(result) == 1 and result[0][0] not in oids_requested: usmStatsOidStr = asOidStr(result[0][0]) if usmStatsOidStr in USM_STATS_OIDS: msg = USM_STATS_OIDS.get(usmStatsOidStr) reactor.callLater(0, d.errback, failure.Failure(Snmpv3Error(msg))) return elif usmStatsOidStr == ".1.3.6.1.6.3.15.1.1.2.0": # we may get a subsequent snmp result with the correct value # if not the timeout will be called at some point self.defers[pdu.reqid] = (d, oids_requested) return if pdu.errstat != netsnmp.SNMP_ERR_NOERROR: pduError = PDU_ERRORS.get(pdu.errstat, 'Unknown error (%d)' % pdu.errstat) message = "Packet for %s has error: %s" % (self.ip, pduError) if pdu.errstat in ( SNMP_ERR_NOACCESS, SNMP_ERR_RESOURCEUNAVAILABLE, SNMP_ERR_AUTHORIZATIONERROR, ): reactor.callLater(0, d.errback, failure.Failure(SnmpError(message))) return else: result = [] log.warning(message + '. OIDS: {0}'.format(oids_requested)) reactor.callLater(0, d.callback, result)
def callback(self, pdu): results = netsnmp.getResult(pdu) for oid, value in results: print oid, ` value ` reactor.stop()
def callback(self, pdu): results = netsnmp.getResult(pdu) for oid, value in results: print oid, `value` reactor.stop()
def callback(self, pdu): results = netsnmp.getResult(pdu, self._log) for oid, value in results: print oid, repr(value) reactor.stop()