aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2012-12-12 15:25:52 +0000
committerBryn M. Reeves <bmr@redhat.com>2012-12-12 15:25:52 +0000
commit653ad8f21452a4d73ebe1664ae761e296690a0e9 (patch)
treee2595e90062dbc7a97a07e7ec23fe54a06648714
parent5a792dd1829449f9bfa74734150b5dd43cd02578 (diff)
downloadsos-653ad8f21452a4d73ebe1664ae761e296690a0e9.tar.gz
Add logging to regex subsitution methods
Currently we don't log anything when applying file or command output regex substitutions and any errors are silently discarded. This could cause a user to think that passwords etc. have been obscured when in fact they have not. Log our intent to substitute at debug level and log any exception at error level along with the path or glob, module and exception text. Fixes Issue #84
-rw-r--r--sos/plugins/__init__.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 3a1b6c32..c7def677 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -176,10 +176,13 @@ class Plugin(object):
This function returns the number of replacements made.
'''
globstr = '*' + cmd + '*'
+ self.soslog.debug("substituting '%s' for '%s' in commands matching %s"
+ % (subst, regexp, globstr))
try:
for called in self.executedCommands:
if fnmatch.fnmatch(called['exe'], globstr):
path = os.path.join(self.cInfo['cmddir'], called['file'])
+ self.soslog.debug("applying substitution to %s" % path)
readable = self.archive.open_file(path)
result, replacements = re.subn(
regexp, subst, readable.read())
@@ -189,6 +192,8 @@ class Plugin(object):
else:
return 0
except Exception, e:
+ msg = 'regex substitution failed for %s in plugin %s with: "%s"'
+ self.soslog.error(msg % (path, self.name(), e))
return 0
def doFileSub(self, srcpath, regexp, subst):
@@ -201,6 +206,8 @@ class Plugin(object):
'''
try:
path = self._get_dest_for_srcpath(srcpath)
+ self.soslog.debug("substituting '%s' for '%s' in %s"
+ % (subst, regexp, path))
if not path:
return 0
readable = self.archive.open_file(path)
@@ -211,6 +218,8 @@ class Plugin(object):
else:
return 0
except Exception, e:
+ msg = 'regex substitution failed for %s in plugin %s with: "%s"'
+ self.soslog.error(msg % (path, self.name(), e))
return 0
def doRegexFindAll(self, regex, fname):