scripts/wiki/macro/HostStatus.py
Antoine Durand-Gasselin e8ce8b1e01 [wiki/hoststatus] allez l'iso, allez, allez!
darcs-hash:20100630091703-bd074-92cdb0ad1bd7f781b041a9723d5030da6aae5d4a.gz
2010-06-30 11:17:03 +02: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; color: black;'})
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])) ), "iso-8859-15")
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; color: black;'})
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; color: black;'})
code += f.text(u'Autostatus des '+typ)
code += f.table_cell(0)
code += f.table_cell(1, {'style':'background-color:lime; color: black;'})
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; color:black;', '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