scripts/wifi/status.py
bernat 83380da0ed Avec du XML valide, ca marche mieux.
darcs-hash:20051111181524-d1718-72ab1b3132d05e7e95a536161fafcafc59f20d5d.gz
2005-11-11 19:15:24 +01:00

67 lines
1.9 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")
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 '<bornes date="%d">' % 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 = "<nvram>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 '<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 = filter(lambda x: x.startswith("<position>"), b.info())
if position:
position = position[0].replace("<position>","").split(" ")
print ' <position x="%s" y="%s" />' % (position[0], position[1])
print '</borne>'
print '</bornes>'