Script de resume des stats de bcfg2
Script qui lit le fichier statistics.xml de bcfg2-server et en fait un super resume, afin d'avoir une vue globale sur les fichiers/paquets pas a jour sur les serveurs ... (On s'ennuie comme on peut la nuit ...) darcs-hash:20080801061901-ddb99-7ef253cc41e85a173292ae519d31a3dfaa78025f.gz
This commit is contained in:
parent
6ee0684911
commit
acd2935860
1 changed files with 63 additions and 0 deletions
63
bcfg2/statistics-summary.py
Executable file
63
bcfg2/statistics-summary.py
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# statistics-summary.py
|
||||
# ------------------
|
||||
# Copyright (C) 2008 Michel Blockelet <blockelet@crans.org>
|
||||
|
||||
'''Outil pour créer un résumé des statistiques de bcfg2.'''
|
||||
|
||||
import os
|
||||
import xml.dom.minidom
|
||||
|
||||
def processHost(node):
|
||||
stamps = node.getElementsByTagName('OpStamps')
|
||||
curtime = 0
|
||||
for stamp in stamps:
|
||||
if float(stamp.getAttribute('start')) > curtime:
|
||||
curtime = float(stamp.getAttribute('start'))
|
||||
stats = stamp.parentNode
|
||||
|
||||
if stats.getAttribute('state') == 'clean':
|
||||
return u' * %s - %s' % (node.getAttribute('name'), stats.getAttribute('time'))
|
||||
else:
|
||||
print u' * %s - %s' % (node.getAttribute('name'), stats.getAttribute('time'))
|
||||
bad = stats.getElementsByTagName('Bad')[0]
|
||||
print u' State : %s - %d bad' % (stats.getAttribute('state'), int(stats.getAttribute('total')) - int(stats.getAttribute('good')))
|
||||
|
||||
cfgfiles = bad.getElementsByTagName('ConfigFile')
|
||||
if len(cfgfiles) > 0:
|
||||
print u' * Config files :'
|
||||
for cfgfile in cfgfiles:
|
||||
if cfgfile.getAttribute('current_exists') == 'false':
|
||||
print u' + %s' % cfgfile.getAttribute('name')
|
||||
else:
|
||||
print u' * %s' % cfgfile.getAttribute('name')
|
||||
|
||||
packages = bad.getElementsByTagName('Package')
|
||||
if len(packages) > 0:
|
||||
print u' * Packages :'
|
||||
for package in packages:
|
||||
if package.getAttribute('current_version') == '':
|
||||
print u' + %s :: %s' % (package.getAttribute('name'), package.getAttribute('version'))
|
||||
else:
|
||||
print u' * %s :: %s -> %s' % (package.getAttribute('name'), package.getAttribute('current_version'), package.getAttribute('version'))
|
||||
|
||||
print ''
|
||||
return ''
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
statsfile = '/var/lib/bcfg2/etc/statistics.xml'
|
||||
if os.access(statsfile, os.F_OK):
|
||||
doc = xml.dom.minidom.parse(statsfile)
|
||||
cleans = []
|
||||
print u'* Bad hosts :'
|
||||
for node in doc.getElementsByTagName('Node'):
|
||||
cleans.append(processHost(node))
|
||||
print u'* Clean hosts :'
|
||||
for clean in cleans:
|
||||
if clean != '':
|
||||
print clean
|
||||
else:
|
||||
print u'Impossible d\'accéder au fichier de statistiques : %s !' % statsfile
|
Loading…
Add table
Add a link
Reference in a new issue