Пример #1
0
    def get_temp_lm_sensors(self):
        """ try to get temperature from lm_sensors file
        example outputs:
coretemp-isa-0000
Core 0:      +81.0 C  (high = +100.0 C, crit = +100.0 C)  

coretemp-isa-0001
Core 1:      +82.0 C  (high = +100.0 C, crit = +100.0 C)       
        """
        self.logger.debug("getting cpu temp from lm_sensors")
        try:
            n = 0
            tot_temp = 0.0
            #temp_re = re.compile('(\d+.\d+) C')
            temp_re = re.compile('^Core [0-9]+: +\+([0-9]+(\.[0-9]+)?)')
            cmd = 'sensors -A'
            for l in popen(cmd, self.logger)[1].split("\n"):
                self.logger.debug("lm_sensors line: %s" % (l, ))
                temps = temp_re.findall(l)
                self.logger.debug("temps = %s" % (temps, ))
                if temps:
                    temp = float(temps[0][0])
                    tot_temp += temp
                    n+=1
            if n == 0:
                return None
            return tot_temp/n
        except Exception, e:
            self.logger.debug("failed: %s" % (str(e), ))
            return None
Пример #2
0
    def get_temp_lm_sensors(self):
        """ try to get temperature from lm_sensors file
        example outputs:
coretemp-isa-0000
Core 0:      +81.0 C  (high = +100.0 C, crit = +100.0 C)

coretemp-isa-0001
Core 1:      +82.0 C  (high = +100.0 C, crit = +100.0 C)
        """
        self.logger.debug("getting cpu temp from lm_sensors")
        try:
            n = 0
            tot_temp = 0.0
            #temp_re = re.compile('(\d+.\d+) C')
            temp_re = re.compile('^Core [0-9]+: +\+([0-9]+(\.[0-9]+)?)')
            cmd = 'sensors -A'
            for l in popen(cmd, self.logger)[1].split("\n"):
                self.logger.debug("lm_sensors line: %s" % (l, ))
                temps = temp_re.findall(l)
                self.logger.debug("temps = %s" % (temps, ))
                if temps:
                    temp = float(temps[0][0])
                    tot_temp += temp
                    n += 1
            if n == 0:
                return None
            return tot_temp / n
        # pylint: disable=W0703
        except Exception, e:
            self.logger.debug("failed: %s" % (str(e), ))
            return None
Пример #3
0
    def icmpping(self, host):
        """Performs icmp ping using ping command

        Native python solution is possible, but would require it to run
        under root user. ping is suid on most systems, so no root required

        Args:
            host: string - hostname (or ip address)

        Returns:
            float - time to ping in seconds,
            int - 0 if failed"""
        cmd = "/bin/ping %s -c 1 -U -W 5" % host
        retcode, ret = popen(cmd, self.logger)
        if retcode == 0:
            # ping succeed
            ret = ret.strip().split("\n")[-1]  # pylint: disable-msg=E1103
            # ret is something like
            # rtt min/avg/max/mdev = 33.843/33.843/33.843/0.000 ms
            ret = ret.split('=')[1]
            ret = ret.strip()
            ret = float(ret.split('/')[0])
            return ret / 1000
        else:
            # ping unsuccessful
            return 0
Пример #4
0
 def _read_tw_status(self, c=0, u=0, cmd='status'):
     key = (c, u, cmd)
     if key in self._tw_out:
         # already executed
         return self._tw_out[key]
     else:
         command = "%s info c%i u%i %s" \
             % (self.config.get('tw_cli_path', '/opt/3ware/tw_cli'),
                 c,
                 u,
                 cmd)
         # pylint: disable=W0612
         retcode, ret = popen(command, self.logger)  # @UnusedVariable
         self._tw_out[key] = ret
         return ret
Пример #5
0
 def _read_tw_status(self, c=0, u=0, cmd='status'):
     key = (c, u, cmd)
     if key in self._tw_out:
         # already executed
         return self._tw_out[key]
     else:
         command = "%s info c%i u%i %s" \
             % (self.config.get('tw_cli_path', '/opt/3ware/tw_cli'),
                 c,
                 u,
                 cmd)
         # pylint: disable=W0612
         retcode, ret = popen(command, self.logger)  # @UnusedVariable
         self._tw_out[key] = ret
         return ret
Пример #6
0
 def icmpping(self, host):
     """ Does icmp ping using ping command
     Native python solution possible, but would require it to run
     under root user. ping is suid on most systems
     
     @returns: (float)time to ping in seconds, (int)0 if failed
     """
     cmd = "/bin/ping %s -c 1 -U -W 5" % host
     retcode, ret = popen(cmd, self.logger)
     if retcode == 0:
         # ping succeed
         ret = ret.strip().split("\n")[-1]
         # ret is something like
         # rtt min/avg/max/mdev = 33.843/33.843/33.843/0.000 ms
         ret = ret.split('=')[1].strip()
         ret = float(ret.split('/')[0])
         return ret / 1000
     else:
         # ping unsuccessful
         return 0
Пример #7
0
    def get_prop(self, mbean_name, attribute_name):
        """ get custom JMX bean property """

        # escape spaces in mbean_name
        mbean_name = mbean_name.replace(' ', '\ ')

        popen_cmd = "java -Djava.endorsed.dirs=/opt/ztc/lib/ -jar " + \
            "/opt/ztc/lib/jmxterm-1.0-alpha-4-uber.jar -l %s -e -n " + \
            "-v silent" % (self.jmx_url,)
        jmxterm_cmd = "get -b %s %s -s" % (mbean_name, attribute_name)
        self.logger.debug("Executing jmxterm command %s" % jmxterm_cmd)
        self.logger.debug("Jmxterm executable: %s" % popen_cmd)
        try:
            code, ret = popen(popen_cmd, self.logger, jmxterm_cmd)
        except IOError:
            self.logger.exception("Failed to run popen")
            raise CheckFail("jmxterm call failed")
        if code != 0:
            self.logger.error('jmxterm returned non-zero status')
            raise CheckFail('unable to get jmx propery %s %s' %
                            (mbean_name, attribute_name))
        return ret.strip()
Пример #8
0
 def get_status(self, c=0, u=0):
     cmd = "%s info c%i u%i status" % (self.config.get('tw_cli_path', '/opt/3ware/tw_cli'), c, u)
     retcide, ret = popen(cmd, self.logger)
     return ret.splitlines()[0].split()[3]