Der Pate
04.07.05, 16:43
Hallo!
Ich habe Schwierigkeiten ein 1.x Script zu 3.4.x zu portieren. Sieht so aus:
# query a SNMP agent for table
def sesstable (session, objid):
# initialize objid & vals lists (pysnmp methods
# expect lists as input args)
encoded_oids = []
encoded_vals = []
# encode objid
encoded_oids.append(session.encode_oid(session.str 2nums(mibtr.mid(objid))))
# remember the head of the table
head_enc_oid = encoded_oids[0]
# traverse the agent's MIB
tabres=[]
while 1:
# build a packet
packet = session.encode_request ('GETNEXTREQUEST', encoded_oids, encoded_vals)
# send SNMP request and recieve a response
packet = session.send_and_receive (packet)
# parse a response packet
(encoded_oids, encoded_vals) = session.decode_response (packet)
# stop at the end of the table
if not session.oid_prefix_check(head_enc_oid, encoded_oids[0]):
return tabres
# decode objid & vals
index = 0
while index < len(encoded_oids):
# print it out
# print mibtr.mstr(session.decode_value(encoded_oids[index])),
# print ' --> ',
# print session.decode_value(encoded_vals[index])
tabres.append(session.decode_value(encoded_vals[index]))
# go to the next objid
index = index + 1
Ich komm mit den VarBindLists nicht zureckt und weiß nicht, wo ich im Beispiel meine Adressen eintrage, etc.
Vielleicht kann mir hier jemand helfen...
Ich habe Schwierigkeiten ein 1.x Script zu 3.4.x zu portieren. Sieht so aus:
# query a SNMP agent for table
def sesstable (session, objid):
# initialize objid & vals lists (pysnmp methods
# expect lists as input args)
encoded_oids = []
encoded_vals = []
# encode objid
encoded_oids.append(session.encode_oid(session.str 2nums(mibtr.mid(objid))))
# remember the head of the table
head_enc_oid = encoded_oids[0]
# traverse the agent's MIB
tabres=[]
while 1:
# build a packet
packet = session.encode_request ('GETNEXTREQUEST', encoded_oids, encoded_vals)
# send SNMP request and recieve a response
packet = session.send_and_receive (packet)
# parse a response packet
(encoded_oids, encoded_vals) = session.decode_response (packet)
# stop at the end of the table
if not session.oid_prefix_check(head_enc_oid, encoded_oids[0]):
return tabres
# decode objid & vals
index = 0
while index < len(encoded_oids):
# print it out
# print mibtr.mstr(session.decode_value(encoded_oids[index])),
# print ' --> ',
# print session.decode_value(encoded_vals[index])
tabres.append(session.decode_value(encoded_vals[index]))
# go to the next objid
index = index + 1
Ich komm mit den VarBindLists nicht zureckt und weiß nicht, wo ich im Beispiel meine Adressen eintrage, etc.
Vielleicht kann mir hier jemand helfen...