Esempio n. 1
0
    def get_freebsd_total_mem(self, pagesize):

        (exit_code, stdout, stderr) = Command.run(self, ["sysctl", "-n", "vm.stats.vm.v_page_count"]) 
        if exit_code == 0:
            return pagesize * int(stdout)

        return 0
Esempio n. 2
0
    def run_freebsd(self, result):

        pagesize = self.get_freebsd_page_size()

        # update result
        result['mem']['total']   = self.get_freebsd_total_mem(pagesize)
        result['mem']['free']    = self.get_freebsd_free_mem(pagesize)
        result['mem']['used']    = result['mem']['total'] - result['mem']['free']

        used  = float(result['mem']['used'])
        total = float(result['mem']['total'])
        result['mem']['percent'] = int(100 * (used/total))

        # and for memory and swap [total, used, free] array
        swaptotal = 0
        swapfree  = 0
        swapused  = 0
        
        # run for swap
        (exit_code, stdout, stderr) = Command.run(self, ["swapinfo", "-k", "1K"]) 
        if exit_code == 0:

            (swaptotal, swapused, swapfree) = self.parse_freebsd_swap(stdout)

            result['swap']['total']   = swaptotal
            result['swap']['free']    = swapfree
            result['swap']['used']    = swapused
            
            used  = float(result['swap']['used'])
            total = float(result['swap']['total'])
            result['swap']['percent'] = int(100 * (used/total))
Esempio n. 3
0
    def run_linux(self):

        try:
            # run this command
            (exit_code, stdout, stderr) = Command.run(self, ["ip", "addr"])

            # empty result by default
            res = []

            # split the stdout into lines
            lines = stdout.split('\n')
            for line in lines:
                line = line.strip()
                if not line.startswith("inet"):
                    continue

                pos = line.find(' ')
                if pos != -1:
                    line = line[pos + 1:]
                    pos = line.find(' ')
                    if pos != -1:
                        line = line[:pos]

                if line.startswith("127.0.0.1/") or line.startswith("::1/"):
                    continue

                res.append(line)

            return res

        except Exception as e:
            return [str(e)]
Esempio n. 4
0
    def get_freebsd_page_size(self):

        pagesize = 0
        (exit_code, stdout, stderr) = Command.run(self, ["sysctl", "-n", "hw.pagesize"]) 
        if exit_code == 0:
            pagesize = int(stdout)
        
        return pagesize
Esempio n. 5
0
 def run(self):
     (exit_code, stdout, stderr) = Command.run(self, ["df", "-k", Paths.var_dir()]) 
     if exit_code == 0:
         line = filter(None, stdout.split('\n')[1:2])
         rows = line.split(' ')
         for row in rows:
             if row.find('%') != -1:
                 return row
     return '0%'
Esempio n. 6
0
    def run(self):
        try:
            # run this command
            (exit_code, stdout, stderr) = Command.run(self, ["uptime"])

            # and convert
            return stdout
        except Exception as e:
            return str(e)
Esempio n. 7
0
    def run(self, file):

        name = "ldap"
        if System.name() == System.WS_WINDOWS:
            name += ".exe"

        args = [os.path.join(Paths.bin_dir(), name), "--file=" + file]

        # run this command
        (exit_code, stdout, stderr) = Command.run(self, args)

        # and convert
        return {'exit_code': exit_code, 'stdout': stdout, 'stderr': stderr}
Esempio n. 8
0
    def run(self, folder):

        # assume failure
        success = False
        exit_code = -1
        stdout = ""
        stderr = ""

        try:
            # run this command
            (exit_code, stdout,
             stderr) = Command.run(self, ["df", "-h", "-l", folder])

            # and mark success
            success = True
        except Exception as e:
            stderr = str(e)

        # the data
        data = {
            'error': stderr,
            'size': '',
            'used': '',
            'avail': '',
            'ratio': ''
        }

        # check if we were successful
        try:
            if success:

                # get the most valud
                array = self.parse(stdout)

                data['size'] = array[1]
                data['used'] = array[2]
                data['avail'] = array[3]
                data['ratio'] = array[4]

        except Exception as e:
            success = False
            data['error'] = str(e)

        return (success, data)
Esempio n. 9
0
    def run(self):

        try:
            args = ["top", "-d", "0.5", "-b", "-n2"]
            if System.WS_FREEBSD == System.name():
                args = ["top", "-d", "2", "-b"]

            # run top command twice (it gives correct output only second time)
            (exit_code, stdout, stderr) = Command.run(self, args)
            if exit_code != 0:
                raise Exception(
                    "Cannot run top command, exit code: %d, stdout: %s, stderr: %s"
                    % (exit_code, stdout, stderr))

            # parse it
            return self.parse(stdout)

        except Exception as e:
            return 0
Esempio n. 10
0
    def run(self):
        if System.WS_FREEBSD == System.name():
            args = [
                "ps", "-U", self.username, "-o",
                "pid,user,cputime,pcpu,rss,pmem,command"
            ]
        else:
            args = [
                "ps", "-U", self.username, "-u", self.username, "-o",
                "pid,user,cputime,pcpu,rss,pmem,command"
            ]

        # run this command
        (exit_code, stdout, stderr) = Command.run(self, args)

        # and convert
        if exit_code == 0:
            return self.parse_output(stdout)
        else:
            return {}
Esempio n. 11
0
    def run(self, icap_port="1344"):

        if System.WS_FREEBSD == System.name():
            args = ["netstat", "-an", "-p", "tcp"]
        else:
            args = [
                "netstat", "--tcp", "--all", "--numeric", "--program",
                "--verbose"
            ]

        # run this command
        (exit_code, stdout, stderr) = Command.run(self, args)

        # and convert
        if exit_code == 0:
            if System.WS_FREEBSD == System.name():
                return self.parse_freebsd_output(stdout, icap_port)
            else:
                return self.parse_linux_output(stdout, icap_port)
        else:
            return []
Esempio n. 12
0
    def run_freebsd(self):

        try:
            # run this command
            (exit_code, stdout, stderr) = Command.run(self, ["ifconfig"])

            # empty result by default
            res = []

            # split the stdout into lines
            lines = stdout.split('\n')
            for line in lines:
                line = line.strip()

                interesting = False
                if line.startswith("inet ") or line.startswith("inet6 "):
                    interesting = True
                if not interesting:
                    continue

                pos = line.find(' ')
                if pos != -1:
                    line = line[pos + 1:]
                    pos = line.find(' ')
                    if pos != -1:
                        line = line[:pos]

                if line.startswith("127.0.0.1") or line.startswith("::1"):
                    continue

                if line.find("%lo") != -1:
                    continue
                res.append(line)

            return res

        except Exception as e:
            return [str(e)]
Esempio n. 13
0
    def run(self, params):

        name = "database"
        if System.name() == System.WS_WINDOWS:
            name += ".exe"

        exe = os.path.join(Paths.bin_dir(), name)
        args = [exe]
        args.extend(params)

        (exit_code, stdout, stderr) = Command.run(self, args)
        if exit_code != 0:
            logging.error("ERROR: ")
            logging.error("ERROR: Cannot switch database, error: %d",
                          exit_code)
            logging.error("ERROR: ")

            logging.error("STDOUT: ")
            logging.error(stdout)

            logging.error("STDERR: ")
            logging.error(stderr)

            raise Exception("FAILURE!!!")