diff --git a/wifi/status.py b/wifi/status.py new file mode 100755 index 00000000..5667ca12 --- /dev/null +++ b/wifi/status.py @@ -0,0 +1,63 @@ +#! /usr/bin/env python +# -*- encoding: iso-8859-15 -*- + +# Génération d'un fichier XML indiquant le status des bornes + +import sys +import os +import time +sys.path.append("/usr/scripts/gestion") +sys.path.append("/etc/munin/plugins") + +from canal_bornes import bornes_canal +from wifi_clients import bornes_clients +from uptime_bornes import bornes_uptime + +from ldap_crans import crans_ldap +l = crans_ldap() + +# On commence le fichier XML +print '' % time.time() + +# On récupère l'ensemble des bornes +bornes = l.search('host=*.wifi.crans.org&canal=*')['machine'] + +canaux = bornes_canal() +clients = bornes_clients() +uptimes = bornes_uptime() + +for b in bornes: + infos = filter(lambda x: not x.startswith("<"), b.info()) + if not infos: + # Rien à propos de cette borne... + continue + + # Est-ce un hotspot ? + hotspot = "crans_hotspot=1" in b.info() and 1 or 0 + # Est-ce que la borne est up ? + if os.system("/usr/sbin/fping -q %s" % b.nom()) == 0: + up = 1 + else: + up = 0 + # Quel nom ? + nom = b.nom().split(".")[0] + print '' % (nom, + hotspot, + up) + print ' %s' % infos[0].encode("utf-8") + print ' %s' % b.mac2() + try: + print ' %d' % int(canaux[nom]) + except KeyError: + pass + try: + print ' %d' % int(clients[nom]) + except KeyError: + pass + try: + print ' %s' % uptimes[nom] + except KeyError: + pass + print '' + +print ''