Script de stats bcfg2 : ajout noeuds et options
darcs-hash:20080801172718-ddb99-279f4d579cd2b1fe5a1068bade71dcfa2b17e7d5.gz
This commit is contained in:
parent
acd2935860
commit
5415b53a36
1 changed files with 87 additions and 35 deletions
|
@ -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,14 +19,39 @@ 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:
|
||||
bad = stats.getElementsByTagName('Bad')[0]
|
||||
nbbad = int(stats.getAttribute('total')) - int(stats.getAttribute('good'))
|
||||
cfgfiles = bad.getElementsByTagName('ConfigFile')
|
||||
packages = bad.getElementsByTagName('Package')
|
||||
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'))
|
||||
bad = stats.getElementsByTagName('Bad')[0]
|
||||
print u' State : %s - %d bad' % (stats.getAttribute('state'), int(stats.getAttribute('total')) - int(stats.getAttribute('good')))
|
||||
print u' State : %s - %d bad%s' % (stats.getAttribute('state'), nbbad, ignorestr)
|
||||
|
||||
cfgfiles = bad.getElementsByTagName('ConfigFile')
|
||||
if len(cfgfiles) > 0:
|
||||
if len(cfgfiles) > 0 and 'config' not in ignore:
|
||||
print u' * Config files :'
|
||||
for cfgfile in cfgfiles:
|
||||
if cfgfile.getAttribute('current_exists') == 'false':
|
||||
|
@ -34,8 +59,7 @@ def processHost(node):
|
|||
else:
|
||||
print u' * %s' % cfgfile.getAttribute('name')
|
||||
|
||||
packages = bad.getElementsByTagName('Package')
|
||||
if len(packages) > 0:
|
||||
if len(packages) > 0 and 'packages' not in ignore:
|
||||
print u' * Packages :'
|
||||
for package in packages:
|
||||
if package.getAttribute('current_version') == '':
|
||||
|
@ -43,19 +67,47 @@ def processHost(node):
|
|||
else:
|
||||
print u' * %s :: %s -> %s' % (package.getAttribute('name'), package.getAttribute('current_version'), package.getAttribute('version'))
|
||||
|
||||
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__':
|
||||
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:
|
||||
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))
|
||||
print u'* Clean hosts :'
|
||||
cleans.append(processHost(node, ignore))
|
||||
print u'* Clean hosts (or with ignored dirtyness) :'
|
||||
for clean in cleans:
|
||||
if clean != '':
|
||||
print clean
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue