diff options
-rw-r--r-- | src/lib/sos/plugintools.py | 19 | ||||
-rwxr-xr-x | src/sosreport | 71 |
2 files changed, 60 insertions, 30 deletions
diff --git a/src/lib/sos/plugintools.py b/src/lib/sos/plugintools.py index 1fed8b22..3d80df44 100644 --- a/src/lib/sos/plugintools.py +++ b/src/lib/sos/plugintools.py @@ -288,11 +288,11 @@ class PluginBase: sys.stderr.write("the collectExtOutput() function.\n") pass - def collectExtOutput(self, exe): + def collectExtOutput(self, exe, suggest_filename = None, root_symlink = None): """ Run a program and collect the output """ - self.collectProgs.append(exe) + self.collectProgs.append( (exe,suggest_filename,root_symlink) ) def makeCommandFilename(self, exe): """ The internal function to build up a filename based on a command """ @@ -311,7 +311,7 @@ class PluginBase: return outfn - def collectOutputNow(self, exe): + def collectOutputNow(self, exe, suggest_filename = None, root_symlink = False): """ Execute a command and save the output to a file for inclusion in the report """ @@ -323,11 +323,18 @@ class PluginBase: # pylint: disable-msg = W0612 status, shout, sherr, runtime = sosGetCommandOutput(exe) - outfn = self.makeCommandFilename(exe) + if suggest_filename: + outfn = self.makeCommandFilename(suggest_filename) + else: + outfn = self.makeCommandFilename(exe) outfd = open(outfn, "w") outfd.write(shout) outfd.close() + + if root_symlink: + os.system('cd "%s" && ln -s "%s" "%s"' % (self.cInfo['dstroot'], outfn[len(self.cInfo['dstroot'])+1:], root_symlink)) + if len(sherr) > 0: errfn = outfn + ".err" outfd = open(errfn, "w") @@ -404,10 +411,10 @@ class PluginBase: raise KeyboardInterrupt except Exception, e: self.cInfo['soslog'].log(logging.VERBOSE, "Error copying from pathspec %s (%s)" % (path,e)) - for prog in self.collectProgs: + for (prog,suggest_filename,root_symlink) in self.collectProgs: self.cInfo['soslog'].debug("collecting output of '%s'" % prog) try: - self.collectOutputNow(prog) + self.collectOutputNow(prog, suggest_filename, root_symlink) except SystemExit: raise SystemExit except KeyboardInterrupt: diff --git a/src/sosreport b/src/sosreport index 10cab38a..dbfd368d 100755 --- a/src/sosreport +++ b/src/sosreport @@ -115,6 +115,9 @@ __cmdParser__.add_option("-n", "--noplugin", action="extend", \ __cmdParser__.add_option("-o", "--onlyplugin", action="extend", \ dest="onlyplugins", type="string", \ help="list of plugins to load") +__cmdParser__.add_option("-e", "--enableplugin", action="extend", \ + dest="enableplugins", type="string", \ + help="list of plugins to enable") __cmdParser__.add_option("-k", "--pluginopts", action="extend", \ dest="plugopts", type="string", \ help="plugin options in plugin_name.option=value format") @@ -374,40 +377,60 @@ def sosreport(): for plug in plugins: try: if ((plug[-3:] == '.py') and (plug != "__init__.py")): - sys.stdout.write(plug[:-3] + " ") + 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 - print sys.exit() # validate and load plugins for plug in plugins: - if ((plug[-3:] == '.py') and (plug != "__init__.py") and (not __cmdLineOpts__.noplugins or (plug[:-3] not in __cmdLineOpts__.noplugins)) and (not __cmdLineOpts__.onlyplugins or (plug[:-3] in __cmdLineOpts__.onlyplugins)) ): + 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: - plugbase = plug[:-3] - pidot = "sos.plugins." + plugbase - #print "importing plugin: %s" % plugbase - try: - if policy.validatePlugin(pluginpath + plug): - pluginClass = importPlugin(pidot, plugbase) + if policy.validatePlugin(pluginpath + plug): + pluginClass = importPlugin("sos.plugins." + plugbase, plugbase) + else: + soslog.warning("Plugin %s does not validate, skipping" % plug) + 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.warning("Plugin %s does not validate, skipping" % plug) - continue - if not __cmdLineOpts__.onlyplugins and not pluginClass(plugbase, commons).defaultenabled(): - 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) - continue - loadedplugins.append((plugbase, pluginClass(plugbase, commons))) - except: - soslog.warning("Plugin %s does not install, skipping" % plug) - raise + 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) + continue + loadedplugins.append((plugbase, pluginClass(plugbase, commons))) except: - if __raisePlugins__: - raise - soslog.warning("plugin load failed for %s" % plug) + soslog.warning("Plugin %s does not install, skipping" % plug) + raise + except: + if __raisePlugins__: + raise + soslog.warning("plugin load failed for %s" % plug) if not len(loadedplugins): soslog.error("no valid plugins were enabled") |