scripts/wiki-lenny/local/macro/HostStatus.py
Antoine Durand-Gasselin 1b50b6226f [wiki-lenny] L'autostatus est en utf-8 maintenant
darcs-hash:20081215231203-bd074-357b818550e3992bc11835eebd5db9cc0005ae6c.gz
2008-12-16 00:12:03 +01:00

61 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
import re
from commands import getstatusoutput,getoutput
def execute(macro, text) :
lines = open('/usr/scripts/var/local.status').readlines()
f = macro.formatter
code = f.table(1)
typlist = ['routes', 'serveurs', 'serveurs de la ferme', 'switches', 'bornes', u'services extérieurs au crans']
for typ in typlist:
lines = lines [1:]
trucsdown = ''
while lines and not re.match('dummy_host_\d+ 0 \n', lines[0]):
if not re.search(' 0 ', lines[0]):
line = lines[0].split(' ')
trucsdown += f.table_row(1)
trucsdown += f.table_cell(1,{'style':'background-color:lightgrey;'})
trucsdown += unicode(f.text('%s (%s)' % (line [0], getoutput("grep '^%s[^-.a-zA-Z]' /usr/scripts/var/autostatus/hosts | cut -d ' ' -f 5-" % line [0])) ), "utf-8")
trucsdown += f.table_cell(0)
# nombre de non réponse au ping
if int(line[1]) > 2 :
trucsdown += f.table_cell(1,{'style':'background-color:red;'})
trucsdown += f.text(u'down')
else :
trucsdown += f.table_cell(1,{'style':'background-color:blue;'})
trucsdown += f.text(u'état incertain')
trucsdown += f.table_cell(0)
trucsdown += f.table_row(0)
lines = lines [1:]
if trucsdown == '':
code += f.table_row(1)
code += f.table_cell(1, {'style':'background-color:silver;'})
code += f.text(u'Autostatus des '+typ)
code += f.table_cell(0)
code += f.table_cell(1, {'style':'background-color:lime;'})
code += f.text(u'OK')
code += f.table_cell(0)
code += f.table_row(0)
else:
code += f.table_row(1)
code += f.table_cell(1, {'style':'background-color:silver', 'colspan':'2'})
code += f.text(u'Autostatus des '+typ)
code += f.table_cell(0)
code += f.table_row(0)
code += f.table_row(1)
code += f.table_cell(1, {'style':'background-color:aliceblue', 'colspan':'2'})
code += f.table(1) + trucsdown + f.table(0)
code += f.table_cell(0)
code += f.table_row(0)
trucsdown = ''
code += f.table(0)
return code