
facile parser par le mme module dans un autre script. Il y a surement des transformations unicode en trop et il reste un problme d'encodage au niveau de la description. Pour le premier problme j'affinerais si ncessaire. Pour le second le problme vient de ce script ou bien d'un champs de description dans la base pas totalement en unicode? darcs-hash:20060422234938-9e428-f556fa2e8040f4ddb63561835fb606e8f78b4882.gz
91 lines
2.8 KiB
Python
Executable file
91 lines
2.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")
|
|
sys.path.append("/usr/scripts/wifi")
|
|
|
|
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()
|
|
|
|
import xml.dom.minidom
|
|
|
|
# création objet xml
|
|
status=xml.dom.minidom.Document()
|
|
|
|
xml_bornes=status.createElement(u"bornes")
|
|
status.appendChild(xml_bornes)
|
|
xml_bornes.setAttribute(u"date",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]
|
|
xml_borne=status.createElement(u"borne")
|
|
xml_borne.setAttribute(u"nom",unicode(nom))
|
|
xml_borne.setAttribute(u"hotspot",unicode(hotspot))
|
|
xml_borne.setAttribute(u"up",unicode(up))
|
|
|
|
|
|
xml_desc=status.createElement(u"description")
|
|
#xml_desc.appendChild(status.createTextNode(unicode(infos[0])))
|
|
xml_desc.appendChild(status.createTextNode(u"Description pas compatible unicode/ascii"))
|
|
xml_borne.appendChild(xml_desc)
|
|
|
|
xml_mac=status.createElement(u"mac")
|
|
xml_mac.appendChild(status.createTextNode(unicode(b.mac2())))
|
|
xml_borne.appendChild(xml_mac)
|
|
|
|
# Certains résultats (ragnarok) n'ont pas tous les champs.
|
|
if (canaux.has_key(nom)):
|
|
xml_canal=status.createElement(u"canal")
|
|
xml_canal.appendChild(status.createTextNode(unicode(int(canaux[nom]))))
|
|
xml_borne.appendChild(xml_canal)
|
|
|
|
if (clients.has_key(nom)):
|
|
xml_clients=status.createElement(u"clients")
|
|
xml_clients.appendChild(status.createTextNode(unicode(int(clients[nom]))))
|
|
xml_borne.appendChild(xml_clients)
|
|
|
|
if (uptimes.has_key(nom)):
|
|
xml_uptime=status.createElement(u"uptime")
|
|
xml_uptime.appendChild(status.createTextNode(unicode(uptimes[nom])))
|
|
xml_borne.appendChild(xml_uptime)
|
|
|
|
|
|
position = b.position()
|
|
if position:
|
|
xml_position=status.createElement(u"position")
|
|
xml_position.setAttribute(u"x",unicode(position[1]))
|
|
xml_position.setAttribute(u"y",unicode(position[0]))
|
|
xml_borne.appendChild(xml_position)
|
|
|
|
xml_bornes.appendChild(xml_borne)
|
|
|
|
print (status.toxml())
|