65 lines
1.8 KiB
Python
Executable file
65 lines
1.8 KiB
Python
Executable file
#! /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 '<bornes date="%s">' % time.strftime("%c")
|
|
|
|
# On récupère l'ensemble des bornes
|
|
bornes = l.search('host=*.wifi.crans.org&canal=*')['borneWifi']
|
|
|
|
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 = b.hotspot() 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 '<borne nom="%s" hotspot="%d" up="%d">' % (nom,
|
|
hotspot,
|
|
up)
|
|
print ' <description>%s</description>' % infos[0].encode("utf-8")
|
|
print ' <mac>%s</mac>' % b.mac2()
|
|
try:
|
|
print ' <canal>%d</canal>' % int(canaux[nom])
|
|
except KeyError:
|
|
pass
|
|
try:
|
|
print ' <clients>%d</clients>' % int(clients[nom])
|
|
except KeyError:
|
|
pass
|
|
try:
|
|
print ' <uptime>%s</uptime>' % uptimes[nom]
|
|
except KeyError:
|
|
pass
|
|
position = b.position()
|
|
if position:
|
|
print ' <position x="%s" y="%s" />' % (position[1], position[0])
|
|
print '</borne>'
|
|
|
|
print '</bornes>'
|