Patch pour batb-5.crans.org
This commit is contained in:
parent
ed91745fec
commit
6a51e0c520
1 changed files with 17 additions and 4 deletions
|
@ -9,9 +9,12 @@
|
||||||
# celle-ci, démerdez-vous avec un des responsables de
|
# celle-ci, démerdez-vous avec un des responsables de
|
||||||
# l'association pour les fioritures.
|
# l'association pour les fioritures.
|
||||||
|
|
||||||
import os, sys
|
import os
|
||||||
|
import sys
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
|
|
||||||
from commands import getstatusoutput
|
from commands import getstatusoutput
|
||||||
|
|
||||||
# 1 avril 2012 - PEB :
|
# 1 avril 2012 - PEB :
|
||||||
|
@ -21,6 +24,13 @@ from commands import getstatusoutput
|
||||||
# (plante lamentablement quand j'essaye avec mon compte sur vo, sous
|
# (plante lamentablement quand j'essaye avec mon compte sur vo, sous
|
||||||
# ipython. Mais si je sudo ipython, ça marche...
|
# 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):
|
def liste_chambres_macs(switch, annuaire):
|
||||||
u'''
|
u'''
|
||||||
Fonction générant un dictionnaire (macs) contenant pour chaque prise une
|
Fonction générant un dictionnaire (macs) contenant pour chaque prise une
|
||||||
|
@ -29,11 +39,15 @@ def liste_chambres_macs(switch, annuaire):
|
||||||
multiples connexions sql pour rien.
|
multiples connexions sql pour rien.
|
||||||
'''
|
'''
|
||||||
liste_bats = ['a', 'b', 'c', 'g', 'h', 'i', 'j', 'm', 'p']
|
liste_bats = ['a', 'b', 'c', 'g', 'h', 'i', 'j', 'm', 'p']
|
||||||
|
|
||||||
split = switch.replace('.adm.crans.org', '').split('-')
|
split = switch.replace('.adm.crans.org', '').split('-')
|
||||||
bat, num_switch = split[0][-1], int(split[1][0])
|
bat, num_switch = split[0][-1], int(split[1][0])
|
||||||
if bat not in liste_bats:
|
if bat not in liste_bats:
|
||||||
return {}
|
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')
|
data = walk(switch, 'STATISTICS-MIB::hpSwitchPortFdbAddress')
|
||||||
|
|
||||||
liste_chbres = []
|
liste_chbres = []
|
||||||
|
@ -84,7 +98,6 @@ def walk(host, oid):
|
||||||
if not re.match('([0-9a-f]{2}){6}', mac):
|
if not re.match('([0-9a-f]{2}){6}', mac):
|
||||||
mac = mac.encode('hex').lower()
|
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])
|
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):
|
if not result.has_key(port):
|
||||||
result[port] = [mac]
|
result[port] = [mac]
|
||||||
else:
|
else:
|
||||||
|
@ -92,7 +105,7 @@ def walk(host, oid):
|
||||||
except:
|
except:
|
||||||
print "Ligne moisie : %s de l'hôte : %s" % (ligne, host)
|
print "Ligne moisie : %s de l'hôte : %s" % (ligne, host)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def __exec(cmd):
|
def __exec(cmd):
|
||||||
u'''
|
u'''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue