[wifi/{bornes.py,status.py}] légères modifications maintenant que gordon est le routeur wifi

darcs-hash:20091109025242-bd074-2a7b80e68944e1a6e949eedfac93dd94a01ab4ef.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-11-09 03:52:42 +01:00
parent 61d31e04a0
commit c541996784
2 changed files with 21 additions and 14 deletions

View file

@ -23,7 +23,7 @@ def bornes():
Moyen rapide, mais peut-être un peu crade pour récupérer la liste des bornes:
on regarde les machines présentes dans 138.231.148.1/24"""
names = []
for line in commands.getoutput("host -l wifi.crans.org").splitlines():
for line in commands.getoutput("host -l wifi.crans.org sable.crans.org").splitlines()[5:]:
# Chaque ligne est de la forme:
# "truc.wifi.crans.org has address 138.231.148.42"
fields = line.split()
@ -123,6 +123,7 @@ def munin(config, cmd=None, process=(lambda x: x), results=None, buckets=None, s
if 'config' in sys.argv:
print config
print "graph_category wifi"
if buckets:
for i, (val, lbl) in enumerate(buckets.items()):
print "%s.label %s" % (lbl, val)
@ -164,6 +165,10 @@ def main():
action='store_const', const='uname -v', dest='cmd', default='uname -v')
parser.add_option('-u', '--uptime', help=u"renvoie l'uptime",
action='store_const', const='uptime', dest='cmd')
parser.add_option('-w', '--mac-wifi',
help=u"renvoie l'addresse MAC de l'access point",
action='store_const', dest='cmd',
const="iwconfig wl0 | sed -n 's/^.*00:/00:/p'")
parser.add_option('-c', '--custom', help=u'exécute une commande custom',
action='store', dest='cmd')

View file

@ -1,5 +1,5 @@
#! /usr/bin/env python
# -*- encoding: iso-8859-15 -*-
# -*- coding: iso-8859-15 -*-
# Génération d'un fichier XML indiquant le status des bornes
@ -25,6 +25,7 @@ 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']
bornes.sort(cmp=(lambda x, y: cmp(x.nom(), y.nom())))
canaux = bornes_canal()
clients = bornes_clients()
@ -32,7 +33,6 @@ uptimes = bornes_uptime()
for b in bornes:
infos = filter(lambda x: not x.startswith("<"), b.info())
if not infos or b.nom().split('.')[0]=="non-configure":
# Rien à propos de cette borne...
continue
@ -40,7 +40,7 @@ for b in bornes:
# 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:
if os.system("/usr/sbin/fping -q %s 2> /dev/null" % b.nom()) == 0:
up = 1
else:
up = 0
@ -55,35 +55,37 @@ for b in bornes:
xml_desc.appendChild(status.createTextNode(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(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('0' + canaux[nom]))))
try: canal = unicode(int(canaux[nom]))
except TypeError: canal = u'Inconnu'
xml_canal.appendChild(status.createTextNode(canal))
xml_borne.appendChild(xml_canal)
if (clients.has_key(nom)):
xml_clients=status.createElement(u"clients")
xml_clients.appendChild(status.createTextNode(unicode(int('0' + clients[nom]))))
try: client = unicode(int(clients[nom]))
except TypeError: client = u'Inconnu'
xml_clients.appendChild(status.createTextNode(client))
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().encode("UTF-8"))