diff --git a/gestion/hptools.py b/gestion/hptools.py index a7399384..601caf75 100755 --- a/gestion/hptools.py +++ b/gestion/hptools.py @@ -19,9 +19,13 @@ from os import system from re import findall from config import vlans +path.append('/usr/scripts/gestion') +from ldap_crans import crans_ldap +cl = crans_ldap() + try: path.append('/usr/scripts/gestion/secrets') - from secrets import config_snmp_secrete, reconf_snmp, engineid + from secrets import config_snmp_secrete, reconf_snmp except: # Si a pas le droit de lire config_snmp_secrete # on va tenter de tout faire en snmpv1 et communauté public @@ -118,10 +122,20 @@ class snmp : """ self.host = host self.version = version + + try: + self._machine = cl.search("host=%(host)s" % {'host': host})["machineCrans"][0] + except IndexError: + raise ValueError(u"Cette machine n'est pas un switch du Cr@ns") + + # l'engineid du switch n'est que sa mac avec quelques fioritures autour... + mac = self._machine.mac().replace(':', '') + self._engineid = '0000000b0000%(mac)s0' % {'mac': mac[:-1]} + if version == '1' or version == '2c' : self.options = "-v %s -c '%s' %s " % ( version, community, host ) elif version =='3' : - self.options = "-v 3 -e %s -u %s -a %s -A '%s' -l authNoPriv" % ( engineid[host.split('.',1)[0]], username, authentication_protocol, authentication_pass ) + 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 self.options += " %s " % host