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):
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 ''
# Hôtes à jour
print u'*** Bad hosts :'
for line in finallines:
print line
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 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:
......
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