[wiki/{bornes.py,status.py}] Mise a jour pour les nouvelles bornes

Bon, il y a probablement des couacs, et j'ai peut-etre casse d'autres trucs,
mais au moins status.xml est bon ...

darcs-hash:20090922192037-ddb99-ab3956ec60f23429c5f854828c66e8bb40990513.gz
This commit is contained in:
Michel Blockelet 2009-09-22 21:20:37 +02:00
parent 34787874db
commit 20a4dfd6eb
2 changed files with 71 additions and 6 deletions

View file

@ -34,11 +34,78 @@ 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 %(host)s exec %(cmd)s" % locals())
(stdin, stdout, stderr) = os.popen3("ssh -T -x -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no %(host)s exec %(cmd)s" % locals())
stdin.close()
stderr.close()
return stdout
def bornes_canal():
names = bornes()
outputs = {}
for name in names:
outputs[name] = ssh_exec(name+".wifi", 'iwlist wl0 channel')
count = 0
total = len(names)
while count < total:
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] = '0'
output.close()
return results
def bornes_clients():
names = bornes()
outputs = {}
for name in names:
outputs[name] = ssh_exec(name+".wifi", 'brctl showmacs br-crans')
count = 0
total = len(names)
while count < total:
try: os.wait()
except OSError: break
# On lit tout les résultats:
results = {}
for name, output in outputs.iteritems():
macs = map(lambda x: x.split(), output.readlines())
results[name] = str(len([x for x in macs if x[0] == '2' and x[2] != 'yes']))
output.close()
return results
def bornes_uptime():
names = bornes()
outputs = {}
for name in names:
outputs[name] = ssh_exec(name+".wifi", 'cat /proc/uptime')
count = 0
total = len(names)
while count < total:
try: os.wait()
except OSError: break
# On lit tout les résultats:
results = {}
for name, output in outputs.iteritems():
uptime = output.read().strip()
if uptime:
results[name] = str(float(uptime.split()[1]) / (24*3600))
else:
results[name] = '0'
output.close()
return results
def munin(config, cmd, process=(lambda x: x)):
"""plugin munin"""

View file

@ -9,9 +9,7 @@ import time
sys.path.append("/usr/scripts/gestion")
sys.path.append("/usr/scripts/wifi")
from canal_bornes import bornes_canal
from wifi_clients import bornes_clients
from uptime_bornes import bornes_uptime
from bornes import bornes_canal, bornes_clients, bornes_uptime
from ldap_crans import crans_ldap
l = crans_ldap()
@ -65,12 +63,12 @@ for b in bornes:
# Certains résultats (ragnarok) n'ont pas tous les champs.
if (canaux.has_key(nom)):
xml_canal=status.createElement(u"canal")
xml_canal.appendChild(status.createTextNode(unicode(int(canaux[nom]))))
xml_canal.appendChild(status.createTextNode(unicode(int('0' + canaux[nom]))))
xml_borne.appendChild(xml_canal)
if (clients.has_key(nom)):
xml_clients=status.createElement(u"clients")
xml_clients.appendChild(status.createTextNode(unicode(int(clients[nom]))))
xml_clients.appendChild(status.createTextNode(unicode(int('0' + clients[nom]))))
xml_borne.appendChild(xml_clients)
if (uptimes.has_key(nom)):