diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2012-12-07 13:07:24 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2012-12-07 13:07:24 +0000 |
commit | 0f40c7cbaefa33e282d7d73e0ccae67be309fe56 (patch) | |
tree | fa7ffd9a500de555ac246505298c0b128e7e230e | |
parent | 98129045313ccf8bafbad067a28cb527fb1ad2c4 (diff) | |
download | sos-0f40c7cbaefa33e282d7d73e0ccae67be309fe56.tar.gz |
Make sar module more robust
Make the sar module more tolerant of broken environments and users
force-enabling the module when its own enabled check fails.
-rw-r--r-- | sos/plugins/sar.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/sos/plugins/sar.py b/sos/plugins/sar.py index 687ae4e8..11b5b12b 100644 --- a/sos/plugins/sar.py +++ b/sos/plugins/sar.py @@ -19,18 +19,38 @@ class sar(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): """Generate the sar file from /var/log/sa/saXX files """ - files = ('/var/log/sa', '/usr/bin/sar') + sapath='/var/log/sa' + sarcmd='/usr/bin/sar' + files = (sapath, sarcmd) def setup(self): - sapath="/var/log/sa" - if not os.path.exists(sapath): + # check to see if we are force-enabled with no sar installation + if not os.path.exists(self.sapath) or not os.path.isdir(self.sapath): + self.soslog.error( + "sar directory %s does not exist or is not a directory" + % self.sapath) return - dirList=listdir(sapath) + + if not os.path.exists(self.sarcmd) \ + or not os.access(self.sarcmd, os.X_OK): + self.soslog.error( + "sar command %s does not exist or is not runnable" + % self.sarcmd) + return + + # catch exceptions here to avoid races + try: + dirList=listdir(self.sapath) + except: + self.soslog.error("sar directory %s cannot be read") + return + # find all the sa file that don't have an existing sar file for fname in dirList: if fname[0:2] == 'sa' and fname[2] != 'r': sar_filename = 'sar' + fname[2:4] if sar_filename not in dirList: - sar_command = "/bin/sh -c \"LANG=C /usr/bin/sar -A -f /var/log/sa/" + fname + "\"" - self.collectOutputNow(sar_command, sar_filename, root_symlink=sar_filename) - + sar_command = "/bin/sh -c \"LANG=C /usr/bin/sar " \ + + "-A -f /var/log/sa/" + fname + "\"" + self.collectExtOutput(sar_command, sar_filename, + root_symlink=sar_filename) |