Generation d'un status des bornes en XML
darcs-hash:20051111164148-d1718-0b8970d24a2d138b84f14495e7d0f7cb8f93dfde.gz
This commit is contained in:
parent
9c996ca6b5
commit
cd96de5ff4
1 changed files with 63 additions and 0 deletions
63
wifi/status.py
Executable file
63
wifi/status.py
Executable file
|
@ -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 '<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</clients>' % uptimes[nom]
|
||||
except KeyError:
|
||||
pass
|
||||
print '</borne>'
|
||||
|
||||
print '</bornes>'
|
Loading…
Add table
Add a link
Reference in a new issue