diff options
-rw-r--r-- | src/README | 1 | ||||
-rw-r--r-- | src/lib/sos/plugins/general.py | 3 | ||||
-rw-r--r-- | src/lib/sos/plugintools.py | 25 |
3 files changed, 28 insertions, 1 deletions
@@ -17,3 +17,4 @@ Contributors: Steve Conklin <sconklin@redhat.com> Pierre Amadio <pamadio@redhat.com> John Berninger <jwb@redhat.com> +Navid Sheikhol-Eslami <navid@redhat.com> diff --git a/src/lib/sos/plugins/general.py b/src/lib/sos/plugins/general.py index 7488cc2c..d3cfa9a0 100644 --- a/src/lib/sos/plugins/general.py +++ b/src/lib/sos/plugins/general.py @@ -33,3 +33,6 @@ class general(sos.plugintools.PluginBase): self.collectExtOutput("/usr/bin/uptime") return + def postproc(self): + self.doRegexSub("/etc/sysconfig/rhn/up2date", r"(\s*proxyPassword\s*=\s*)\S+", r"\1***") + return diff --git a/src/lib/sos/plugintools.py b/src/lib/sos/plugintools.py index f6b9e40b..8f8de4d8 100644 --- a/src/lib/sos/plugintools.py +++ b/src/lib/sos/plugintools.py @@ -30,7 +30,7 @@ This is the base class for sosreport plugins """ from sos.helpers import * from threading import Thread -import os, os.path, sys, string, itertools, glob +import os, os.path, sys, string, itertools, glob, re class PluginBase: """ @@ -62,6 +62,29 @@ class PluginBase: self.optNames.append(opt[0]) self.optParms.append({'desc':opt[1], 'speed':opt[2], 'enabled':opt[3]}) + # Method for applying regexp substitutions + def doRegexSub(self, srcpath, regexp, subst): + '''Apply a regexp substitution to a file archived by sosreport. + ''' + if len(self.copiedFiles): + for afile in self.copiedFiles: + if afile['srcpath'] == srcpath: + abspath = os.path.join(self.cInfo['dstroot'], srcpath.lstrip(os.path.sep)) + try: + fp = open(abspath, 'r') + tmpout, occurs = re.subn( regexp, subst, fp.read() ) + fp.close() + if occurs > 0: + fp = open(abspath,'w') + fp.write(tmpout) + fp.close() + return occurs + except: + sys.stderr.write("Problem at path %s\n" % abspath) + sys.stderr.flush() + break + return False + # Methods for copying files and shelling out def doCopyFileOrDir(self, srcpath): # pylint: disable-msg = R0912 |