aboutsummaryrefslogtreecommitdiffstats
path: root/src/sosreport
diff options
context:
space:
mode:
Diffstat (limited to 'src/sosreport')
-rwxr-xr-xsrc/sosreport166
1 files changed, 95 insertions, 71 deletions
diff --git a/src/sosreport b/src/sosreport
index 34f6172f..ae8d6609 100755
--- a/src/sosreport
+++ b/src/sosreport
@@ -39,6 +39,8 @@ from stat import *
from time import strftime, localtime
from pwd import getpwuid
+__version__ = 1.7
+
__breakHits__ = 0 # Use this to track how many times we enter the exit routine
## Set up routines to be linked to signals for termination handling
@@ -106,13 +108,13 @@ __cmdParser__.add_option("-l", "--list-plugins", action="store_true", \
help="list existing plugins")
__cmdParser__.add_option("-n", "--noplugin", action="extend", \
dest="noplugins", type="string", \
- help="list of plugins _not_ to load")
+ help="list of plugins _not_ to load", default = [])
__cmdParser__.add_option("-o", "--onlyplugin", action="extend", \
dest="onlyplugins", type="string", \
- help="list of plugins to load")
+ help="list of plugins to load", default = [])
__cmdParser__.add_option("-e", "--enableplugin", action="extend", \
dest="enableplugins", type="string", \
- help="list of plugins to enable")
+ help="list of plugins to enable", default = [])
__cmdParser__.add_option("-k", "--pluginopts", action="extend", \
dest="plugopts", type="string", \
help="plugin options in plugin_name.option=value format")
@@ -122,6 +124,9 @@ __cmdParser__.add_option("-v", "--verbose", action="count", \
__cmdParser__.add_option("-b", "--no-progressbar", action="store_false", \
dest="progressbar", default=True, \
help="Do not display a progress bar.")
+__cmdParser__.add_option("-c", "--curses", action="store_false", \
+ dest="use_curses", default=False, \
+ help="Do not display a progress bar.")
__cmdParser__.add_option("-m", "--multithreaded", action="store_true", \
dest="multithread", \
help="Use the multithreaded information gathering mode to speed up the report (experimental)")
@@ -304,6 +309,7 @@ def sosreport():
This is the top-level function that gathers and processes all sosreport information
"""
loadedplugins = []
+ skippedplugins = []
alloptions = []
# perhaps we should automatically locate the policy module??
@@ -363,121 +369,139 @@ def sosreport():
# Make policy aware of the commons
policy.setCommons(commons)
+
+ sys.stdout.write("\n")
+ soslog.info("sosreport (version %s)" % (__version__) )
+ sys.stdout.write("\n")
- # print list of available plugins
+ # generate list of available plugins
plugins = os.listdir(pluginpath)
- if __cmdLineOpts__.listPlugins:
- print "Available plugins:"
- print
- for plug in plugins:
- try:
- if ((plug[-3:] == '.py') and (plug != "__init__.py")):
- plugbase = plug[:-3]
- if policy.validatePlugin(pluginpath + plug):
- pluginClass = importPlugin("sos.plugins." + plugbase, plugbase)
- else:
- soslog.warning("plugin %s does not validate, skipping" % plug)
- continue
- if not pluginClass(plugbase, commons).checkenabled():
- print "* %s (inactive)" % plugbase
- continue
- if not pluginClass(plugbase, commons).defaultenabled():
- print "* %s (disabled by default)" % plugbase
- continue
- print " " + plugbase
- except:
- print "ouch"
- print
- sys.exit()
-
- # to go anywhere further than listing the plugins we will need root permissions.
- #
- if os.getuid() != 0:
- print 'You must run sosreport as root!'
- sys.exit(1)
+ plugins.sort()
# validate and load plugins
for plug in plugins:
plugbase = plug[:-3]
if not plug[-3:] == '.py' or plugbase == "__init__":
continue
- if __cmdLineOpts__.noplugins and plugbase not in __cmdLineOpts__.noplugins:
- soslog.log(logging.VERBOSE, "plug %s skipped" % plugbase)
- continue
- if __cmdLineOpts__.onlyplugins and not plugbase in __cmdLineOpts__.onlyplugins:
- soslog.log(logging.VERBOSE, "plug %s skipped" % plugbase)
- continue
try:
#print "importing plugin: %s" % plugbase
try:
if policy.validatePlugin(pluginpath + plug):
pluginClass = importPlugin("sos.plugins." + plugbase, plugbase)
else:
- soslog.warning("Plugin %s does not validate, skipping" % plug)
+ soslog.warning("plugin %s does not validate, skipping" % plug)
+ skippedplugins.append((plugbase, pluginClass(plugbase, commons)))
+ continue
+ if plugbase in __cmdLineOpts__.noplugins:
+ soslog.log(logging.VERBOSE, "plug %s skipped (noplugins)" % plugbase)
+ skippedplugins.append((plugbase, pluginClass(plugbase, commons)))
continue
- if not __cmdLineOpts__.onlyplugins and not pluginClass(plugbase, commons).defaultenabled():
- if __cmdLineOpts__.enableplugins and plugbase in __cmdLineOpts__.enableplugins:
- soslog.log(logging.VERBOSE, "plugin %s manually activated" % plugbase)
- else:
- soslog.log(logging.VERBOSE, "Plugin %s not loaded by default." % plug)
- continue
- if not pluginClass(plugbase, commons).checkenabled():
- soslog.log(logging.VERBOSE, "Plugin %s is inactive." % plug)
+ if not pluginClass(plugbase, commons).checkenabled() and not plugbase in __cmdLineOpts__.enableplugins and not plugbase in __cmdLineOpts__.onlyplugins:
+ soslog.log(logging.VERBOSE, "plugin %s is inactive (use -e or -o to enable)." % plug)
+ skippedplugins.append((plugbase, pluginClass(plugbase, commons)))
+ continue
+ if not pluginClass(plugbase, commons).defaultenabled() and not plugbase in __cmdLineOpts__.enableplugins and not plugbase in __cmdLineOpts__.onlyplugins:
+ soslog.log(logging.VERBOSE, "plugin %s not loaded by default (use -e or -o to enable)." % plug)
+ skippedplugins.append((plugbase, pluginClass(plugbase, commons)))
+ continue
+ if __cmdLineOpts__.onlyplugins and not plugbase in __cmdLineOpts__.onlyplugins:
+ soslog.log(logging.VERBOSE, "plugin %s not specified in --onlyplugin list" % plug)
+ skippedplugins.append((plugbase, pluginClass(plugbase, commons)))
continue
loadedplugins.append((plugbase, pluginClass(plugbase, commons)))
except:
soslog.warning("Plugin %s does not install, skipping" % plug)
raise
except:
+ soslog.warning("plugin load failed for %s" % plug)
if __raisePlugins__:
raise
- soslog.warning("plugin load failed for %s" % plug)
+
+ # First, gather and process options
+ for plugname, plug in loadedplugins:
+ soslog.log(logging.VERBOSE3, "processing options from plugin: %s" % plugname)
+ names, parms = plug.getAllOptions()
+ for optname, optparm in zip(names, parms):
+ alloptions.append((plug, plugname, optname, optparm))
+
+ if __cmdLineOpts__.listPlugins:
+ if not len(loadedplugins) and not len(skippedplugins):
+ soslog.error("no valid plugins found")
+ sys.exit(1)
+
+ print "The following plugins are currently enabled:"
+ print
+ for (plugname,plug) in loadedplugins:
+ print " %-15s %s" % (plugname,plug.get_description())
+
+ print
+ print "The following plugin options are available:"
+ print
+ for (plug, plugname, optname, optparm) in alloptions:
+ print " %-15s %s [%d]" % (plugname + "." + optname, optparm["desc"], optparm["enabled"])
+
+ print
+ print "The following plugins are currently disabled:"
+ print
+ for (plugname,plugclass) in skippedplugins:
+ print " %-15s %s" % (plugname,plugclass.get_description())
+
+ print
+ sys.exit()
+
+ # to go anywhere further than listing the plugins we will need root permissions.
+ #
+ if os.getuid() != 0:
+ print 'sosreport requires root permissions to run.'
+ sys.exit(1)
+
+ # we don't need to keep in memory plugins we are not going to use
+ del skippedplugins
if not len(loadedplugins):
soslog.error("no valid plugins were enabled")
sys.exit(1)
- sys.stdout.write("\n")
- soslog.info("Welcome to sosreport (%d plugins loaded)" % (len(loadedplugins)))
- sys.stdout.write("\n")
+ try:
+ raw_input("""This utility will collect some detailed information about the
+hardware and setup of your Red Hat Enterprise Linux system.
+This information will be used to diagnose problems with your
+system and will be considered confidential information.
+Red Hat will use this information for diagnostic purposes ONLY.
- # Iterate over plugins for each stage
+This process may take a while to complete.
+No changes will be made to your system.
- # First, gather and process options
- for plugname, plug in loadedplugins:
- soslog.log(logging.VERBOSE3, "processing options from plugin: %s" % plugname)
- try:
- len(__cmdLineOpts__.noplugins)
- if plugname not in __cmdLineOpts__.noplugins:
- names, parms = plug.getAllOptions()
- for optname, optparm in zip(names, parms):
- alloptions.append((plug, plugname, optname, optparm))
- except:
- names, parms = plug.getAllOptions()
- for optname, optparm in zip(names, parms):
- alloptions.append((plug, plugname, optname, optparm))
+Press ENTER to continue, or CTRL-C to quit.
+""")
+ except KeyboardInterrupt:
+ print
+ sys.exit(0)
+ # Iterate over plugins for each stage
if __cmdLineOpts__.plugopts:
opts = {}
for opt in __cmdLineOpts__.plugopts:
try: opt, val = opt.split("=")
except: val=1
plug, opt = opt.split(".")
+ try: val = int(val) # try to convert string "val" to int()
+ except: pass
try: opts[plug]
except KeyError: opts[plug] = []
opts[plug].append( (opt,val) )
for plugname, plug in loadedplugins:
if opts.has_key(plugname):
for opt,val in opts[plugname]:
+ soslog.log(logging.VERBOSE, "setting option %s for plugin %s to %s" % (plugname,opt,val))
plug.setOption(opt,val)
+ del opt,opts,val
elif not __cmdLineOpts__.fastoptions and not __cmdLineOpts__.usealloptions:
- if len(alloptions):
+ if len(alloptions) and __cmdLineOpts__.use_curses:
try:
get_curse_options(alloptions)
except "Cancelled":
sys.exit("Exiting.")
- else:
- soslog.info("no options available for selected plugins")
elif __cmdLineOpts__.fastoptions:
for i in range(len(alloptions)):
for plug, plugname, optname, optparm in alloptions:
@@ -492,7 +516,7 @@ def sosreport():
# Setup the progress bar
if __cmdLineOpts__.progressbar:
- pbar = progressBar(0, len(loadedplugins) * 33, 40)
+ pbar = progressBar(0, len(loadedplugins) * 33, totalWidth = 60)
# Call the setup method for each plugin
for plugname, plug in loadedplugins:
@@ -613,7 +637,7 @@ def sosreport():
# package up the results for the support organization
policy.packageResults()
# delete gathered files
- os.system("rm -rf %s" % dstroot)
+ os.system("/bin/rm -rf %s" % dstroot)
# automated submission will go here
# Close all log files and perform any cleanup