Patch pour batb-5.crans.org

This commit is contained in:
Pierre-Elliott Bécue 2015-09-27 14:00:01 +02:00
parent ed91745fec
commit 6a51e0c520

View file

@ -9,9 +9,12 @@
# celle-ci, démerdez-vous avec un des responsables de
# l'association pour les fioritures.
import os, sys
import os
import sys
import sys
import re
import socket
from commands import getstatusoutput
# 1 avril 2012 - PEB :
@ -21,6 +24,13 @@ from commands import getstatusoutput
# (plante lamentablement quand j'essaye avec mon compte sur vo, sous
# ipython. Mais si je sudo ipython, ça marche...
def host_exists(hostname):
"""Vérifie si hostname résout bien, sinon retourne false"""
try:
socket.gethostbyname(hostname)
except socket.gaierror:
return False
def liste_chambres_macs(switch, annuaire):
u'''
Fonction générant un dictionnaire (macs) contenant pour chaque prise une
@ -34,6 +44,10 @@ def liste_chambres_macs(switch, annuaire):
bat, num_switch = split[0][-1], int(split[1][0])
if bat not in liste_bats:
return {}
if not host_exists(switch):
switch = switch.replace('adm.crans.org', 'crans.org')
if not host_exists(switch):
return {}
data = walk(switch, 'STATISTICS-MIB::hpSwitchPortFdbAddress')
liste_chbres = []
@ -84,7 +98,6 @@ def walk(host, oid):
if not re.match('([0-9a-f]{2}){6}', mac):
mac = mac.encode('hex').lower()
mac = "%s:%s:%s:%s:%s:%s" % (mac[0:2], mac[2:4], mac[4:6], mac[6:8], mac[8:10], mac[10:12])
if not result.has_key(port):
result[port] = [mac]
else: