From 6ab2ea76a8f95df6d2852617f6980fcac22b5cc7 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Wed, 9 Feb 2011 00:11:10 +0100 Subject: [PATCH] =?UTF-8?q?[bcfg2/statistics-summary]=20Affiche=20les=20h?= =?UTF-8?q?=C3=B4tes=20tr=C3=A8s=20sales=20en=20premier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit darcs-hash:20110208231110-ffbb2-28997823827beaf1233c35f850c8a3b1a060052b.gz --- bcfg2/statistics-summary.py | 63 ++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/bcfg2/statistics-summary.py b/bcfg2/statistics-summary.py index b3f170a3..0fbdb939 100644 --- a/bcfg2/statistics-summary.py +++ b/bcfg2/statistics-summary.py @@ -53,6 +53,8 @@ def processHost(node, ignore): state = 'clean' lines = [u' * %s - %s - clean' % (node.getAttribute('name'), stats.getAttribute('time'))] + nbbad = 0 + ignored = 0 else: # On récupère les différents points pas à jour bad = stats.getElementsByTagName('Bad')[0] @@ -133,7 +135,7 @@ def processHost(node, ignore): lines.append('') - return (time.time() - curtime > daysold * 24 * 60 * 60, state, lines) + return (time.time() - curtime > daysold * 24 * 60 * 60, state, lines, nbbad - ignored) def deleteHosts(hostslist, writeback): @@ -185,49 +187,68 @@ def genStats(ignore): # On traite le fichier de statistiques doc = xml.dom.minidom.parse(statsfile) - oldlines = [] - finallines = [u'', u'*** Clean hosts (or with ignored dirtyness) :'] + oldhosts = [] + dirtyhosts = [] + cleanhosts = [] oldnb = 0 badnb = 0 - goodnb = 0 + cleannb = 0 # On récupère les informations des différents hôtes for curnode in doc.getElementsByTagName('Node'): - (isold, state, hostlines) = processHost(curnode, ignore) + (isold, state, hostlines, urgency) = processHost(curnode, ignore) if isold: oldnb += 1 if state in ['clean', 'ignored']: - oldlines += hostlines + oldhosts.append((0, hostlines)) else: - oldlines = hostlines + oldlines + oldhosts.append((urgency, hostlines)) else: if state in ['clean', 'ignored']: - finallines += hostlines - goodnb += 1 + cleanhosts.append((0, hostlines)) + cleannb += 1 else: - finallines = hostlines + finallines + dirtyhosts.append((urgency, hostlines)) badnb += 1 + + # Get the dirtier hosts first. + dirtyhosts.sort() + dirtyhosts.reverse() + oldhosts.sort() + oldhosts.reverse() + # Header print (u'*** Bcfg2 Statistics on %s, for %d hosts ***' - % (time.strftime("%c"), oldnb + badnb + goodnb)) + % (time.strftime("%c"), oldnb + badnb + cleannb)) print u' * Old hosts : %d' % oldnb print u' * Bad hosts : %d' % badnb - print u' * Clean hosts : %d' % goodnb - print '' + print u' * Clean hosts : %d' % cleannb + print # Hôtes vieux - print u'*** Old hosts (more than %s days) :' % daysold - for line in oldlines: - print line - print '' + if oldnb: + print u'*** Old hosts (more than %s days) :' % daysold + for host in oldhosts: + for line in host[1]: + print line + print - # Hôtes à jour - print u'*** Bad hosts :' - for line in finallines: - print line + # Hôtes sales + if badnb: + print u'*** Bad hosts :' + for host in dirtyhosts: + for line in host[1]: + print line + print + # Hôtes propres + if cleannb: + print u'*** Clean hosts (or with ignored dirtyness) :' + for host in cleanhosts: + for line in host[1]: + print line if __name__ == '__main__': if '-h' in sys.argv: