コード例 #1
0
def test_uptime_1():
    uptime_text = """
    12:34:35 up 58 days, 10:18,  5 users,  load average: 0.76, 1.28, 1.19  
    """
    expected = {
        'load_1': 0.76,
        'load_15': 1.19,
        'load_5': 1.28,
        'uptime_as_seconds': 5048280,
        'uptime_days': 58,
        'uptime_hours': 10,
        'uptime_minutes': 18,
        'users': 5
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
コード例 #2
0
def test_uptime_2():
    uptime_text = """
    23:11:40 up  8:16,  1 user,  load average: 2.71, 2.30, 2.01 
    """
    expected = {
        'load_1': 2.71,
        'load_15': 2.01,
        'load_5': 2.3,
        'uptime_as_seconds': 29760,
        'uptime_days': 0,
        'uptime_hours': 8,
        'uptime_minutes': 16,
        'users': 1
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
コード例 #3
0
def test_uptime_4():
    uptime_text = """
    20:19:54 up 54 min,  4 users,  load average: 1.69, 1.96, 1.92
    """

    expected = {
        'load_1': 1.69,
        'load_15': 1.92,
        'load_5': 1.96,
        'uptime_as_seconds': 3240,
        'uptime_days': 0,
        'uptime_hours': 0,
        'uptime_minutes': 54,
        'users': 4
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
コード例 #4
0
def test_uptime_3():
    uptime_text = """
    02:25:02 up 73 days, 40 min,  1 user,  load average: 2.01, 1.56, 1.60
    """

    expected = {
        'load_1': 2.01,
        'load_15': 1.6,
        'load_5': 1.56,
        'uptime_as_seconds': 6309600,
        'uptime_days': 73,
        'uptime_hours': 0,
        'uptime_minutes': 40,
        'users': 1
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
コード例 #5
0
    def run(self, local_info, router_context, gql_token, fp):
        """
      """
        test_info = self.test_info(local_info, router_context)
        self.output.test_start(test_info, status=Output.Status.OK)
        params = self.get_params()

        if self.check_user("root") != Output.Status.OK:
            return self.output.test_end(fp)

        self.output.progress_start(fp)
        router_context.query_node_info()

        uptime_data = {}
        service_data = {}
        cores_data = []

        # Ugly....
        self.fp = fp
        error_lines = []
        uptime = Linux.Uptime(self.debug, progobj=self)
        shell_status = uptime.run_linux_args(local_info, router_context,
                                             params['node_type'], error_lines,
                                             uptime_data)

        if len(error_lines) > 0:
            # Ugly...
            self.fp = None
            self.output.proc_run_linux_error(shell_status, error_lines[0])
            return self.output.test_end(fp)

        if self.debug:
            print('........ uptime flattened list ..........')
            pprint.pprint(uptime_data)

        error_lines = []
        sys_status = Linux.SystemctlStatus(self.debug, progobj=self)
        shell_status = sys_status.run_linux_args(local_info, router_context,
                                                 params['node_type'],
                                                 params['service'],
                                                 error_lines, service_data)

        if len(error_lines) > 0:
            # Ugly...
            self.fp = None
            self.output.proc_run_linux_error(shell_status, error_lines[0])
            return self.output.test_end(fp)

        if self.debug:
            print('........ systemctl flattened list ..........')
            pprint.pprint(service_data)

        error_lines = []
        cores = Linux.Coredumpctl(self.debug, progobj=self)
        shell_status = cores.run_linux_args(local_info, router_context,
                                            params['node_type'], error_lines,
                                            cores_data)
        # Ugly...
        self.fp = None

        if len(error_lines) > 0:
            self.output.proc_run_linux_error(shell_status, error_lines[0])
            return self.output.test_end(fp)

        if self.debug:
            print('........ cores flattened list ..........')
            pprint.pprint(cores_data)

        status = Output.Status.OK
        uptime_cores = cores.cores_newer_than_secs(
            uptime_data['uptime_as_seconds'])
        if len(uptime_cores) > 0:
            self.output.proc_uptime_match(uptime_cores)
            status = Output.Status.WARN

        # TODO -- add error if epoch_time does not exist???
        service_cores = []
        if 'epoch_time' in service_data:
            service_cores = cores.cores_newer_than_epoch(
                service_data['epoch_time'])
        if len(service_cores) > 0:
            self.output.proc_service_match(params['service'], service_cores)
            status = Output.Status.WARN

        node_name = router_context.get_node_by_type(params['node_type'])
        message = f"{node_name}:  Uptime OS: {uptime_data['uptime_days']}d " + \
                  f"{uptime_data['uptime_hours']}h {uptime_data['uptime_minutes']}m  " + \
                  " 128T: "
        if service_data["uptime_days"] > 0:
            message += f"{service_data['uptime_days']}d "
        message += f"{service_data['uptime_hours']}h "
        message += f"{service_data['uptime_minutes']}m"
        if service_data["uptime_days"] == 0:
            message += f" {service_data['uptime_seconds']}s"

        self.output.proc_test_result(message, status)
        self.output.test_end(fp)