From 0f40c7cbaefa33e282d7d73e0ccae67be309fe56 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Fri, 7 Dec 2012 13:07:24 +0000 Subject: 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. --- sos/plugins/sar.py | 34 +++++++++++++++++++++++++++------- 1 file 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) -- cgit