diff --git a/gestion/hptools.py b/gestion/hptools.py index a6eb6423..f769bc20 100644 --- a/gestion/hptools.py +++ b/gestion/hptools.py @@ -127,6 +127,7 @@ class snmp : if version == '1' or version == '2c' : self.options = "-v %s -c '%s' %s " % ( version, community, host ) elif version =='3' : + self.fetch_engineid() self.options = "-v 3 -e %s -u %s -a %s -A '%s' -l authNoPriv" % ( self._engineid, username, authentication_protocol, authentication_pass ) if privacy_pass : self.options += " -x DES -X '%s' -l authPriv" % privacy_pass @@ -134,6 +135,13 @@ class snmp : else : raise ValueError('Version incorrecte') + def get_mac(self): + s, r = getstatusoutput("arp -a %s | perl -nle '{print $& if /00(:[0-9a-f]{2}){5}/}'" % self.host) + return r + + def fetch_engineid(self): + self._engineid = '0000000b000%s0' % self.get_mac().replace(':', '') + def __init_ldap(self): try: self._machine = cl.search("host=%(host)s" % {'host': self.host})["machineCrans"][0] @@ -313,7 +321,7 @@ class hpswitch : def nb_prises(self) : """ Retourne le nombre de prises du switch """ if self.__debug : self.__logDest.write("HP DEBUG : nb_prises()\n") - return int(findall(r'Switch 26([0-9]{2})', self.version())[0]) + return int(self.get('SNMPv2-SMI::mib-2.17.1.2.0')) def version(self) : """ Retourne la version du firmware du switch """