scripts/wiki/macro/HostStatus.py
bernat fcbf4c4755 En fait, cela marche, j'avais pas vu le .encode tratre la fin...
darcs-hash:20051011104526-d1718-0a4fc6accad5f803001fd0b22361c7ddfde83466.gz
2005-10-11 12:45:26 +02:00

52 lines
1.6 KiB
Python

# -*- coding: iso-8859-1 -*-
from commands import getstatusoutput,getoutput
def Cellule(texte, couleur, f) :
"""
Retourne le code HTML d'une cellule formattée aver le formatter f
"""
code = f.table(1)
code += f.table_row(1)
code += f.table_cell(1,{'style':'background-color:%s' % couleur })
code += f.text(texte)
code += f.table_cell(0)
code += f.table_row(0)
code += f.table(0)
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')
f = macro.formatter
code = ''
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 += f.text('%s (%s)' % (line [0], getoutput("grep '^%s' /etc/autostatus/hosts | cut -d ' ' -f 5-" % line [0])) )
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