diff --git a/wifi/bornes.py b/wifi/bornes.py index 1e8f71ba..caa8bc8b 100755 --- a/wifi/bornes.py +++ b/wifi/bornes.py @@ -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""" diff --git a/wifi/status.py b/wifi/status.py index a9cca3dc..3db68266 100644 --- a/wifi/status.py +++ b/wifi/status.py @@ -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)):