Commit ffaeaaf6 authored by Daniel STAN's avatar Daniel STAN
Browse files

hptools/walk: autorise plusieurs formats d'output

parent f9646ab6
......@@ -182,20 +182,25 @@ class snmp :
"""
return self.__exec('snmpset -O vq %s %s %s %s' % (self.options, oid, typ, val ) )
def walk(self,base_oid, bin_comp=False) :
def walk(self,base_oid, bin_comp=False, output='x'):
""" Retourne le résultat de snmpwalk
le retour est un dictionnaire { oid : valeur }
"""
if bin_comp:
return snmp.bin_walk(self, base_oid)
lignes = self.__exec('snmpwalk -Ox %s %s' % (self.options, base_oid ) ).split('\n')
if output not in list('abeEfnqQsStTuUvxX'):
output = 'q'
lignes = self.__exec('snmpwalk -O%s %s %s' % (output, self.options, base_oid ) ).split('\n')
result = {}
for ligne in lignes:
try:
oid, valeur = ligne.split('Hex-STRING: ')
result[oid] = valeur
except:
pass
except ValueError:
try:
oid, valeur = ligne.split(' ', 1)
except ValueError:
continue
result[oid] = valeur
return result
def bin_walk(self, base_oid):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment