Commit 5415b53a authored by Michel Blockelet's avatar Michel Blockelet

Script de stats bcfg2 : ajout noeuds et options

darcs-hash:20080801172718-ddb99-279f4d579cd2b1fe5a1068bade71dcfa2b17e7d5.gz
parent acd29358
......@@ -7,10 +7,10 @@
'''Outil pour créer un résumé des statistiques de bcfg2.'''
import os
import os, sys
import xml.dom.minidom
def processHost(node):
def processHost(node, ignore):
stamps = node.getElementsByTagName('OpStamps')
curtime = 0
for stamp in stamps:
......@@ -19,45 +19,97 @@ def processHost(node):
stats = stamp.parentNode
if stats.getAttribute('state') == 'clean':
return u' * %s - %s' % (node.getAttribute('name'), stats.getAttribute('time'))
return u' * %s - %s - clean' % (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')))
nbbad = 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'))
services = bad.getElementsByTagName('Service')
actions = bad.getElementsByTagName('Action')
ignored = 0
ignorestr = u''
if 'config' in ignore and len(cfgfiles) > 0:
ignored += len(cfgfiles)
ignorestr += u' %d configfiles' % len(cfgfiles)
if 'packages' in ignore and len(packages) > 0:
ignored += len(packages)
ignorestr += u' %d packages' % len(packages)
if 'actions' in ignore and len(actions) > 0:
ignored += len(actions)
ignorestr += u' %d actions' % len(actions)
if 'services' in ignore and len(services) > 0:
ignored += len(services)
ignorestr += u' %d services' % len(services)
if ignored > 0:
ignorestr = u' - %d ignored :%s' % (ignored, ignorestr)
if ignored == nbbad:
return u' * %s - %s%s' % (node.getAttribute('name'), stats.getAttribute('time'), ignorestr)
else:
print u' * %s - %s' % (node.getAttribute('name'), stats.getAttribute('time'))
print u' State : %s - %d bad%s' % (stats.getAttribute('state'), nbbad, ignorestr)
if len(cfgfiles) > 0 and 'config' not in ignore:
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')
if len(packages) > 0 and 'packages' not in ignore:
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 len(actions) > 0 and 'actions' not in ignore:
print u' * Actions :'
for action in actions:
print u' * %s' % action.getAttribute('name')
if len(services) > 0 and 'services' not in ignore:
print u' * Services :'
for service in services:
print u' * %s' % service.getAttribute('name')
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
if '-h' in sys.argv:
print u'Outil pour créer un résumé des statistiques de bcfg2.'
print u''
print u'Usage :'
print u' -c ou --no-config pour ignorer les ConfigFiles'
print u' -p ou --no-packages pour ignorer les Packages'
print u' -a ou --no-actions pour ignorer les Actions'
print u' -s ou --no-services pour ignorer les Services'
else:
print u'Impossible d\'accéder au fichier de statistiques : %s !' % statsfile
ignore = []
if '-c' in sys.argv or '--no-config' in sys.argv:
ignore.append('config')
if '-p' in sys.argv or '--no-packages' in sys.argv:
ignore.append('packages')
if '-a' in sys.argv or '--no-actions' in sys.argv:
ignore.append('actions')
if '-s' in sys.argv or '--no-services' in sys.argv:
ignore.append('services')
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, ignore))
print u'* Clean hosts (or with ignored dirtyness) :'
for clean in cleans:
if clean != '':
print clean
else:
print u'Impossible d\'accéder au fichier de statistiques : %s !' % statsfile
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