Пример #1
0
 def test_prompt_for_kibana_saved_search_selection_if_necessary_negative_2(
         self, mock_prompt):
     config = deepcopy(TEST_CONFIG)
     config.kibana.saved_search = None
     config.select_kibana_saved_search = None
     reader = LogstashReader(config)
     # test
     reader._prompt_for_kibana_saved_search_selection_if_necessary()
     # check
     mock_prompt.assert_not_called()
Пример #2
0
 def test_prompt_for_kibana_saved_search_selection_if_necessary_positive_1(
         self, mock_prompt):
     config = deepcopy(TEST_CONFIG)
     config.kibana.saved_search = 'test'
     config.select_kibana_saved_search = True
     reader = LogstashReader(config)
     # test
     reader._prompt_for_kibana_saved_search_selection_if_necessary()
     # check
     mock_prompt.assert_called_once()
Пример #3
0
    def test_list_kibana_saved_searches_negative_no_hits(
            self, mock_handler, mock_es_detection):
        # load test data
        test_response = self._get_test_data('saved_searches_empty')
        mock_es_detection.return_value = ELASTICSEARCH_MAJOR_VERSION_6
        mock_handler.return_value = test_response

        reader = LogstashReader(TEST_CONFIG)
        reader.list_kibana_saved_searches()

        # check
        expected_output = 'No saved searches found in Kibana'
        output = sys.stdout.getvalue().strip()  # pylint: disable=no-member
        self.assertEqual(output, expected_output)
Пример #4
0
    def test_list_kibana_saved_searches_positive_v4(self, mock_handler,
                                                    mock_es_detection):
        # load test data
        test_response_kibana4 = self._get_test_data('saved_searches_kibana4')
        mock_es_detection.return_value = ELASTICSEARCH_MAJOR_VERSION_2
        mock_handler.return_value = test_response_kibana4

        reader = LogstashReader(TEST_CONFIG)
        reader.list_kibana_saved_searches()

        # check
        expected_output = u'Kibana Saved Search 2 (fromhost, programname)\nKibana saved ' + \
            u'search 1 (fromhost, requestHost, vHostPort, requestUrl)\nSüslogging ' + \
            u'(fromhost, programname, severity, message)'
        output = sys.stdout.getvalue().strip()  # pylint: disable=no-member
        self.assertEqual(output, expected_output)
Пример #5
0
    def test_list_kibana_saved_searches_positive_v6(self, mock_handler,
                                                    mock_es_detection):
        # load test data
        test_response_kibana6 = self._get_test_data('saved_searches_kibana6')
        mock_es_detection.return_value = ELASTICSEARCH_MAJOR_VERSION_6
        mock_handler.return_value = test_response_kibana6

        reader = LogstashReader(TEST_CONFIG)
        reader.list_kibana_saved_searches()

        # check
        expected_output = u'Dummy saved search 1 (host, program, log_level, _id, ' + \
            u'log_level_no_orig, message)\nParse Errors (tags, logsource, program, message)\n' + \
            u'Syslog (host, program, message)'
        output = sys.stdout.getvalue().strip()  # pylint: disable=no-member
        self.assertEqual(output, expected_output)
Пример #6
0
def main():
    options = _setup_options()
    try:
        config = _setup_config(options)
        reader = LogstashReader(config)
        if options.kibana_list_saved_searches:
            reader.list_kibana_saved_searches()
        elif options.version:
            reader.show_version()
        else:
            reader.read()
    except Exception as exc:  # pylint: disable=broad-except
        if options.debug:
            raise
        else:
            print(exc, file=sys.stderr)
            sys.exit(1)
Пример #7
0
    def test_setup_initial_time_range(self):
        config = deepcopy(TEST_CONFIG)
        end_date_time = datetime(2018, 2, 22, 22, 22, 42)
        with freeze_time(end_date_time):
            # test with config.initial_time_range being set (42d)
            config.initial_time_range = '42d'
            reader = LogstashReader(config)
            reader._setup_initial_time_range()
            # check
            expected_end_date_time = end_date_time - timedelta(days=42)
            self.assertEqual(reader._last_timestamp, expected_end_date_time)

            # test with config.initial_time_range being set (7m)
            config.initial_time_range = '7m'
            reader = LogstashReader(config)
            reader._setup_initial_time_range()
            # check
            expected_end_date_time = end_date_time - timedelta(seconds=7 * 60)
            self.assertEqual(reader._last_timestamp, expected_end_date_time)

            # test without config.initial_time_range being set
            config.initial_time_range = None
            reader = LogstashReader(config)
            reader._setup_initial_time_range()
            # check
            # days=1 is the default if the config setting is missing
            expected_end_date_time = end_date_time - timedelta(days=1)
            self.assertEqual(reader._last_timestamp, expected_end_date_time)