From 112f43046c63a2cc475989fb4bb316b8cc6c1402 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Mon, 10 Mar 2014 15:33:14 +0100 Subject: [PATCH] wiki: AutoStatus en utf-8 --- wiki/macro/HostStatus.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wiki/macro/HostStatus.py b/wiki/macro/HostStatus.py index 14cee386..dda609c8 100644 --- a/wiki/macro/HostStatus.py +++ b/wiki/macro/HostStatus.py @@ -6,6 +6,18 @@ from commands import getstatusoutput,getoutput def execute(macro, text) : + descriptions = {} + with open('/usr/scripts/var/autostatus/hosts', 'r') as f: + for line in f.readlines(): + line = line.split(' ', 4) + host = line[0] + try: + dec = line[4].decode('utf-8', errors='ignore') + except IndexError: + dec = u"N/A" + dec = dec.strip() + descriptions[host] = u'%s (%s)' % (host, dec) + lines = open('/usr/scripts/var/local.status').readlines() f = macro.formatter @@ -22,7 +34,7 @@ def execute(macro, text) : 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.text(descriptions.get(line[0], line[0])) trucsdown += f.table_cell(0) # nombre de non réponse au ping if int(line[1]) > 2 :