def _snmp_set(self, oid, value): community, sock = self._snmp_connect() pdu = SNMPset(varbindlist=[SNMPvarbind(oid=str(oid), value=value)]) p = SNMP(community=community, PDU=pdu) sock.sendall(p.build()) r = SNMP(sock.recv(4096)) return r
def _snmp_set(self, oid, value): community, sock = self._snmp_connect() pdu = SNMPset(varbindlist=[SNMPvarbind(oid=str(oid), value=value)]) p = SNMP(version=0, community=community, PDU=pdu) #{0:"v1", 1:"v2c", 2:"v2", 3:"v3"}) sock.sendall(p.build()) r = SNMP(sock.recv(4096)) return r
def _snmp_get(self, oid): community, sock = self._snmp_connect() pdu = SNMPget(varbindlist=[SNMPvarbind(oid=str(oid))]) p = SNMP(community=community, PDU=pdu) sock.sendall(p.build()) r = SNMP(sock.recv(4096)) return r.PDU.varbindlist[0].value.val
def _snmp_walk(self, oid_prefix): community, sock = self._snmp_connect() nextoid = oid_prefix while True: p = SNMP(community=community, PDU=SNMPnext(varbindlist=[SNMPvarbind(oid=nextoid)])) sock.sendall(p.build()) r = SNMP(sock.recv(4096)) oid = r.PDU.varbindlist[0].oid.val if oid.startswith(oid_prefix): yield (oid, r.PDU.varbindlist[0].value.val) else: break nextoid = oid sock.close()