[ wifi/bornes.py ] Maj pour backfire

Un nouveau bornes.py avec un status.py tout propres sont en dev
(parce que ce patch est sale)

darcs-hash:20111216114947-28565-f040e71ccdaaf5e348607afedf3a166c6c8e920f.gz
This commit is contained in:
Daniel STAN 2011-12-16 12:49:47 +01:00
parent d881e6e366
commit de501e7b65

View file

@ -16,7 +16,6 @@ from optparse import OptionParser
LOG = "/var/log/wifi/wifi.log"
DELTA = 60*60
def bornes():
"""Renvoie la liste des bornes
@ -38,7 +37,7 @@ def bornes():
def ssh_exec(host, cmd):
"""Execute une commande en ssh sur une machine et renvoie le résultat"""
(stdin, stdout, stderr) = os.popen3("ssh -T -x -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no %(host)s %(cmd)s" % locals())
(stdin, stdout, stderr) = os.popen3("ssh -T -x -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no -l root -i /usr/scripts/gestion/clef-wifi %(host)s %(cmd)s" % locals())
stdin.close()
stderr.close()
return stdout
@ -47,22 +46,21 @@ def bornes_canal():
names = bornes()
outputs = {}
for name in names:
outputs[name] = ssh_exec(name+".wifi", 'iwlist wl0 channel')
outputs[name] = ssh_exec(name+".wifi", '/usr/sbin/iwlist wlan0 channel')
count = 0
total = len(names)
while count < total:
while True:
try: os.wait()
except OSError: break
# On lit tout les résultats:
results = {}
for name, output in outputs.iteritems():
curoutput = output.read().strip()
if 'Current Channel' in curoutput:
results[name] = curoutput.split(':')[-1].strip()
else:
results[name] = None
results[name] = None
for l in output.readlines():
m = re.match('\s*Current(.*)\\(Channel ([0-9]*)\\)',l)
if m:
results[name] = m.group(2)
break
output.close()
return results
@ -71,21 +69,18 @@ def bornes_clients():
names = bornes()
outputs = {}
for name in names:
outputs[name] = ssh_exec(name+".wifi", 'brctl showmacs br-crans')
outputs[name] = ssh_exec(name+".wifi", '/usr/sbin/iw dev wlan0 station dump')
count = 0
total = len(names)
while count < total:
# count = 0
# total = len(names)
while True:
try: os.wait()
except OSError: break
# On lit tout les résultats:
results = {}
for name, output in outputs.iteritems():
lines = output.readlines()
if lines:
macs = map(lambda x: x.split(), lines)
results[name] = str(len([x for x in macs if x[0] == '2' and x[2] != 'yes']))
results[name] = str(len([1 for line in output.readlines() if line.startswith('Station')]))
output.close()
return results