[bornes.py] corrections

* échappement correct des commandes
 * possibilité d'utiliser des areas

darcs-hash:20091018233758-bd074-8601fa332e20a74b01df218afa6283d50673c4d3.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-10-19 01:37:58 +02:00
parent d98b44e915
commit af51c9177f

View file

@ -38,7 +38,7 @@ def bornes():
def ssh_exec(host, cmd): def ssh_exec(host, cmd):
"""Execute une commande en ssh sur une machine et renvoie le résultat""" """Execute une commande en ssh sur une machine et renvoie le résultat"""
(stdin, stdout, stderr) = os.popen3("ssh -T -x -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no %(host)s exec %(cmd)s" % locals()) (stdin, stdout, stderr) = os.popen3("ssh -T -x -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no %(host)s %(cmd)s" % locals())
stdin.close() stdin.close()
stderr.close() stderr.close()
return stdout return stdout
@ -110,7 +110,7 @@ def bornes_uptime():
output.close() output.close()
return results return results
def munin(config, cmd=None, process=(lambda x: x), results=None, buckets=None): def munin(config, cmd=None, process=(lambda x: x), results=None, buckets=None, stack=None):
"""plugin munin""" """plugin munin"""
if 'autoconf' in sys.argv: if 'autoconf' in sys.argv:
@ -122,11 +122,17 @@ def munin(config, cmd=None, process=(lambda x: x), results=None, buckets=None):
if 'config' in sys.argv: if 'config' in sys.argv:
print config print config
if buckets: if buckets:
for val, lbl in buckets.iteritems(): for i, (val, lbl) in enumerate(buckets.items()):
print "%s.label %s" % (lbl, val) print "%s.label %s" % (lbl, val)
if stack:
if i == 0: print "%s.draw %s" % (lbl, stack)
else: print "%s.draw STACK" % lbl
else: else:
for borne in names: for i, borne in enumerate(names):
print "%s.label %s" % (borne, borne) print "%s.label %s" % (borne, borne)
if stack:
if i == 0: print "%s.draw %s" % (borne, stack)
else: print "%s.draw STACK" % borne
sys.exit(0) sys.exit(0)
if not results: if not results:
@ -162,7 +168,7 @@ def main():
names = bornes() names = bornes()
outputs = {} outputs = {}
for name in names: for name in names:
outputs[name] = ssh_exec(name+".wifi", options.cmd) outputs[name] = ssh_exec(name+".wifi", commands.mkarg(options.cmd))
# On attend que tous les fils qu'on a lancé terminent, avec une petite # On attend que tous les fils qu'on a lancé terminent, avec une petite
# animation si la sortie est un terminal: # animation si la sortie est un terminal:
@ -215,12 +221,12 @@ graph_vlabel uptime in days"""
config = """graph_title Clients connectés config = """graph_title Clients connectés
graph_args --base 1000 -l 0 graph_args --base 1000 -l 0
graph_vlabel Clients connectés""" graph_vlabel Clients connectés"""
munin(config, results=bornes_clients()) munin(config, results=bornes_clients(), stack="AREA")
elif plugin == 'canal': elif plugin == 'canal':
config = """graph_title Canaux utilisés config = """graph_title Canaux utilisés
graph_args --base 1000 -l 0""" graph_args --base 1000 -l 0"""
buckets = {'1': 'un', '2': 'deux', '3': 'trois', '4': 'quatre', buckets = {'1': 'un', '2': 'deux', '3': 'trois', '4': 'quatre',
'5': 'cinq', '6': 'siz', '7': 'sept', '8': 'huit', '5': 'cinq', '6': 'six', '7': 'sept', '8': 'huit',
'9': 'neuf', '10': 'dix', '11': 'onze', '12': 'douze', '9': 'neuf', '10': 'dix', '11': 'onze', '12': 'douze',
'13': 'treize', '14': 'quatorze', '0': 'echec' } '13': 'treize', '14': 'quatorze', '0': 'echec' }
munin(config, results=bornes_canal(), buckets= buckets) munin(config, results=bornes_canal(), buckets= buckets)