[bcfg2/statistics-summary] Affiche les hôtes très sales en premier
darcs-hash:20110208231110-ffbb2-28997823827beaf1233c35f850c8a3b1a060052b.gz
This commit is contained in:
parent
cb44cf542d
commit
6ab2ea76a8
1 changed files with 42 additions and 21 deletions
|
@ -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):
|
||||||
|
|
||||||
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):
|
||||||
# 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
|
||||||
|
print
|
||||||
|
|
||||||
# Hôtes à jour
|
# Hôtes sales
|
||||||
print u'*** Bad hosts :'
|
if badnb:
|
||||||
for line in finallines:
|
print u'*** Bad hosts :'
|
||||||
print line
|
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:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue