From 9a4383c72388c351d2d02e9666cb93e26f1bda2b Mon Sep 17 00:00:00 2001 From: Antoine Durand-Gasselin Date: Mon, 17 Nov 2008 11:40:06 +0100 Subject: [PATCH] [wiki/macro/HostStatus.py] Gros hack pour afficher par categories darcs-hash:20081117104006-bd074-56aa15fe8b04d319066a756d7881a7b569e5c093.gz --- wiki/macro/HostStatus.py | 70 +++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/wiki/macro/HostStatus.py b/wiki/macro/HostStatus.py index e7088335..bbe2bfab 100644 --- a/wiki/macro/HostStatus.py +++ b/wiki/macro/HostStatus.py @@ -1,5 +1,6 @@ # -*- coding: iso-8859-1 -*- +import re from commands import getstatusoutput,getoutput def Cellule(texte, couleur, f) : @@ -16,37 +17,48 @@ def Cellule(texte, couleur, f) : return code def execute(macro, text) : - - status = getstatusoutput('grep -v " 0 " /etc/autostatus/local.status') - - if status[0] and status[0] != 256 : - return Cellule(u'Impossible d\'analyser le fichier de status.','yellow',macro.formatter) - - if not status[1].strip() : - return Cellule(u'Toutes les machines importantes sont up.','lime',macro.formatter) - - lines = status[1].split('\n') - + + lines = open('/etc/autostatus/local.status').readlines() + +# if status[0] and status[0] != 256 : +# return Cellule(u'Impossible d\'analyser le fichier de status.','yellow',macro.formatter) +# +# if not status[1].strip() : +# return Cellule(u'Toutes les machines importantes sont up.','lime',macro.formatter) +# +# lines = status[1].split('\n') + f = macro.formatter code = '' + code += f.heading(1,3) + code += 'Autostatus des machines' + code += f.heading(0,3) code += f.table(1) - - for line in lines : - line = line.split(' ') - code += f.table_row(1) - code += f.table_cell(1,{'style':'background-color:silver'}) - code += unicode(f.text('%s (%s)' % (line [0], getoutput("grep '^%s[^a-zA-Z]' /etc/autostatus/hosts | cut -d ' ' -f 5-" % line [0])) ), "iso-8859-15") - code += f.table_cell(0) - # nombre de non réponse au ping - if int(line[1]) > 2 : - code += f.table_cell(1,{'style':'background-color:red'}) - code += f.text(u'down') - else : - code += f.table_cell(1,{'style':'background-color:blue'}) - code += f.text(u'état incertain') - code += f.table_cell(0) - code += f.table_row(0) - + + for line in lines: + if re.match('dummy_host_\d+ 0 \n', line): + if line == 'dummy_host_9 0 \n': + code += f.table(0) + code += f.heading(1,3) + code += 'Autostatus des bornes wifi' + code += f.heading(0,3) + code += f.table(1) + if not re.search(' 0 ', line): + line = line.split(' ') + code += f.table_row(1) + code += f.table_cell(1,{'style':'background-color:silver'}) + code += unicode(f.text('%s (%s)' % (line [0], getoutput("grep '^%s[^a-zA-Z]' /etc/autostatus/hosts | cut -d ' ' -f 5-" % line [0])) ), "iso-8859-15") + code += f.table_cell(0) + # nombre de non réponse au ping + if int(line[1]) > 2 : + code += f.table_cell(1,{'style':'background-color:red'}) + code += f.text(u'down') + else : + code += f.table_cell(1,{'style':'background-color:blue'}) + code += f.text(u'état incertain') + code += f.table_cell(0) + code += f.table_row(0) + code += f.table(0) - + return code