Commit 6ab2ea76 authored by Nicolas Dandrimont's avatar Nicolas Dandrimont

[bcfg2/statistics-summary] Affiche les hôtes très sales en premier

darcs-hash:20110208231110-ffbb2-28997823827beaf1233c35f850c8a3b1a060052b.gz
parent cb44cf54
...@@ -53,6 +53,8 @@ def processHost(node, ignore): ...@@ -53,6 +53,8 @@ def processHost(node, ignore):
state = 'clean' state = 'clean'
lines = [u' * %s - %s - clean' % (node.getAttribute('name'), lines = [u' * %s - %s - clean' % (node.getAttribute('name'),
stats.getAttribute('time'))] stats.getAttribute('time'))]
nbbad = 0
ignored = 0
else: else:
# On récupère les différents points pas à jour # On récupère les différents points pas à jour
bad = stats.getElementsByTagName('Bad')[0] bad = stats.getElementsByTagName('Bad')[0]
...@@ -133,7 +135,7 @@ def processHost(node, ignore): ...@@ -133,7 +135,7 @@ def processHost(node, ignore):
lines.append('') 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): def deleteHosts(hostslist, writeback):
...@@ -185,49 +187,68 @@ def genStats(ignore): ...@@ -185,49 +187,68 @@ def genStats(ignore):
# On traite le fichier de statistiques # On traite le fichier de statistiques
doc = xml.dom.minidom.parse(statsfile) doc = xml.dom.minidom.parse(statsfile)
oldlines = [] oldhosts = []
finallines = [u'', u'*** Clean hosts (or with ignored dirtyness) :'] dirtyhosts = []
cleanhosts = []
oldnb = 0 oldnb = 0
badnb = 0 badnb = 0
goodnb = 0 cleannb = 0
# On récupère les informations des différents hôtes # On récupère les informations des différents hôtes
for curnode in doc.getElementsByTagName('Node'): for curnode in doc.getElementsByTagName('Node'):
(isold, state, hostlines) = processHost(curnode, ignore) (isold, state, hostlines, urgency) = processHost(curnode, ignore)
if isold: if isold:
oldnb += 1 oldnb += 1
if state in ['clean', 'ignored']: if state in ['clean', 'ignored']:
oldlines += hostlines oldhosts.append((0, hostlines))
else: else:
oldlines = hostlines + oldlines oldhosts.append((urgency, hostlines))
else: else:
if state in ['clean', 'ignored']: if state in ['clean', 'ignored']:
finallines += hostlines cleanhosts.append((0, hostlines))
goodnb += 1 cleannb += 1
else: else:
finallines = hostlines + finallines dirtyhosts.append((urgency, hostlines))
badnb += 1 badnb += 1
# Get the dirtier hosts first.
dirtyhosts.sort()
dirtyhosts.reverse()
oldhosts.sort()
oldhosts.reverse()
# Header # Header
print (u'*** Bcfg2 Statistics on %s, for %d hosts ***' 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' * Old hosts : %d' % oldnb
print u' * Bad hosts : %d' % badnb print u' * Bad hosts : %d' % badnb
print u' * Clean hosts : %d' % goodnb print u' * Clean hosts : %d' % cleannb
print '' print
# Hôtes vieux # Hôtes vieux
print u'*** Old hosts (more than %s days) :' % daysold if oldnb:
for line in oldlines: print u'*** Old hosts (more than %s days) :' % daysold
print line for host in oldhosts:
print '' for line in host[1]:
print line
# Hôtes à jour print
print u'*** Bad hosts :'
for line in finallines: # Hôtes sales
print line 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 __name__ == '__main__':
if '-h' in sys.argv: if '-h' in sys.argv:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment