#! /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") 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.strftime("%c") # 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/local/sbin/fping -q %s || /usr/local/sbin/fping -q %s" % ((b.nom(),)*2)) == 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 position = filter(lambda x: x.startswith(""), b.info()) if position: position = position[0].replace("","").split(" ") print ' ' % (position[1], position[0]) print '' print ''