Ejemplo n.º 1
0
    def test_collect_metrics_when_all_metrics_is_true(
        self, mock_exists, mock_connect):
        args = nagios_exporter.parse_args(
            ['--path', '/not-a-real/path', '--all_metrics', '--perf_data'])
        expected_status = [
            'nagios_livestatus_available 1',
            'nagios_thing_a 1',
            'nagios_thing_b 0'
        ]
        # Setup fake get_status response.
        json_response = json.dumps([['thing_a', 'thing_b'], [1, 0]])
        fixed16_header = fixed16('200', len(json_response))
        fake_status_sock = FakeSocketIO(fixed16_header + json_response)
        expected_services = [
            'nagios_check_load_exec_time{hostname="localhost", service="Current Load"} 0.011084',
            'nagios_check_load_latency{hostname="localhost", service="Current Load"} 0.078',
            'nagios_check_load_state{hostname="localhost", service="Current Load"} 0',
            'nagios_check_load_flapping{hostname="localhost", service="Current Load"} 0',
            'nagios_check_load_acknowledged{hostname="localhost", service="Current Load"} 0',
            'nagios_check_load_perf_data_value{hostname="localhost", key="load1", service="Current Load"} 0.560'
        ]
        # Setup fake get_services response.
        json_response = json.dumps(self.services)
        fixed16_header = fixed16('200', len(json_response))
        fake_service_sock = FakeSocketIO(fixed16_header + json_response)
        mock_exists.return_value = True
        mock_connect.side_effect = [fake_status_sock, fake_service_sock]

        values = []
        nagios_exporter.collect_metrics(args, values)

        self.assertItemsEqual(values, expected_status + expected_services)
Ejemplo n.º 2
0
    def test_collect_metrics_when_whitelist(
        self, mock_exists, mock_connect):
        args = nagios_exporter.parse_args(
            ['--path=/not-a-real/path', '--whitelist=nagios_check_load_state'])
        expected_status = [
            'nagios_livestatus_available 1',
            'nagios_thing_a 1',
            'nagios_thing_b 0'
        ]
        # Setup fake get_status response.
        json_response = json.dumps([['thing_a', 'thing_b'], [1, 0]])
        fixed16_header = fixed16('200', len(json_response))
        fake_status_sock = FakeSocketIO(fixed16_header + json_response)
        expected_services = [
            'nagios_check_load_state{hostname="localhost", service="Current Load"} 0',
        ]
        # Setup fake get_services response.
        json_response = json.dumps(self.services)
        fixed16_header = fixed16('200', len(json_response))
        fake_service_sock = FakeSocketIO(fixed16_header + json_response)
        mock_exists.return_value = True
        mock_connect.side_effect = [fake_status_sock, fake_service_sock]

        values = []
        nagios_exporter.collect_metrics(args, values)

        self.assertItemsEqual(values, expected_status + expected_services)
Ejemplo n.º 3
0
    def test_collect_metrics_with_bad_path(self):
        args = nagios_exporter.parse_args(['--path', '/not-a-real/path'])

        lines = []
        nagios_exporter.collect_metrics(args, lines)

        self.assertIn('nagios_livestatus_available 0', lines)