Search in sources :

Example 1 with ResultMessageSummary

use of org.graylog2.rest.models.messages.responses.ResultMessageSummary in project graylog2-server by Graylog2.

the class LegacyChunkDecoratorTest method setsMessagesOnSearchResponse.

@Test
void setsMessagesOnSearchResponse() {
    SimpleMessageChunk undecoratedChunk = simpleMessageChunkWithIndexNames("field-1,field-2", new Object[] { "index-1", "1", "a" }, new Object[] { "index-2", "2", "b" });
    SearchResponse builtLegacyResponse = captureLegacyResponse(undecoratedChunk, validCommand());
    assertThat(builtLegacyResponse.messages()).extracting(ResultMessageSummary::index, m -> m.message().get("field-1"), m -> m.message().get("field-2")).containsExactly(Tuple.tuple("index-1", "1", "a"), Tuple.tuple("index-2", "2", "b"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Tuple(org.assertj.core.groups.Tuple) DateTimeZone(org.joda.time.DateTimeZone) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DateTime(org.joda.time.DateTime) SearchResponse(org.graylog2.rest.resources.search.responses.SearchResponse) Mockito.when(org.mockito.Mockito.when) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Test(org.junit.jupiter.api.Test) ArgumentCaptor(org.mockito.ArgumentCaptor) LinkedHashSetUtil.linkedHashSetOf(org.graylog.plugins.views.search.export.LinkedHashSetUtil.linkedHashSetOf) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) LegacyDecoratorProcessor(org.graylog.plugins.views.search.LegacyDecoratorProcessor) TestData.simpleMessageChunkWithIndexNames(org.graylog.plugins.views.search.export.TestData.simpleMessageChunkWithIndexNames) Mockito.mock(org.mockito.Mockito.mock) SearchResponse(org.graylog2.rest.resources.search.responses.SearchResponse) Test(org.junit.jupiter.api.Test)

Example 2 with ResultMessageSummary

use of org.graylog2.rest.models.messages.responses.ResultMessageSummary in project graylog2-server by Graylog2.

the class LinkFieldDecoratorTest method createSearchResponse.

private SearchResponse createSearchResponse(String urlFieldValue) {
    final List<ResultMessageSummary> messages = ImmutableList.of(ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "a", TEST_FIELD, urlFieldValue), "graylog_0"));
    final IndexRangeSummary indexRangeSummary = IndexRangeSummary.create("graylog_0", Tools.nowUTC().minusDays(1), Tools.nowUTC(), null, 100);
    return SearchResponse.builder().query("foo").builtQuery("foo").usedIndices(ImmutableSet.of(indexRangeSummary)).messages(messages).fields(ImmutableSet.of(TEST_FIELD)).time(100L).totalResults(messages.size()).from(Tools.nowUTC().minusHours(1)).to(Tools.nowUTC()).build();
}
Also used : IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary)

Example 3 with ResultMessageSummary

use of org.graylog2.rest.models.messages.responses.ResultMessageSummary in project graylog2-server by Graylog2.

the class SyslogSeverityMapperDecoratorTest method testDecorator.

@Test
public void testDecorator() throws Exception {
    final DecoratorImpl decorator = DecoratorImpl.create("id", SyslogSeverityMapperDecorator.class.getCanonicalName(), ImmutableMap.of("source_field", "level", "target_field", "severity"), Optional.empty(), 1);
    final SyslogSeverityMapperDecorator mapperDecorator = new SyslogSeverityMapperDecorator(decorator);
    final IndexRangeSummary indexRangeSummary = IndexRangeSummary.create("graylog_0", Tools.nowUTC().minusDays(1), Tools.nowUTC(), null, 100);
    final List<ResultMessageSummary> messages = ImmutableList.of(ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "h", "level", "80"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "a", "level", "0"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "b", "level", "1"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "c", "level", "2"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "d", "level", "3"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "e", "level", "4"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "f", "level", "5"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "g", "level", "6"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "h", "level", "7"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "i", "foo", "1"), "graylog_0"));
    final SearchResponse searchResponse = SearchResponse.builder().query("foo").builtQuery("foo").usedIndices(ImmutableSet.of(indexRangeSummary)).messages(messages).fields(ImmutableSet.of("level")).time(100L).totalResults(messages.size()).from(Tools.nowUTC().minusHours(1)).to(Tools.nowUTC()).build();
    final SearchResponse response = mapperDecorator.apply(searchResponse);
    // Returns the value if the value cannot be mapped to a Syslog severity
    Assertions.assertThat(response.messages().get(0).message().get("level")).isEqualTo("80");
    Assertions.assertThat(response.messages().get(0).message().get("severity")).isNull();
    // Check that the mapping works correctly
    Assertions.assertThat(response.messages().get(1).message().get("level")).isEqualTo("0");
    Assertions.assertThat(response.messages().get(1).message().get("severity")).isEqualTo("Emergency (0)");
    Assertions.assertThat(response.messages().get(2).message().get("level")).isEqualTo("1");
    Assertions.assertThat(response.messages().get(2).message().get("severity")).isEqualTo("Alert (1)");
    Assertions.assertThat(response.messages().get(3).message().get("level")).isEqualTo("2");
    Assertions.assertThat(response.messages().get(3).message().get("severity")).isEqualTo("Critical (2)");
    Assertions.assertThat(response.messages().get(4).message().get("level")).isEqualTo("3");
    Assertions.assertThat(response.messages().get(4).message().get("severity")).isEqualTo("Error (3)");
    Assertions.assertThat(response.messages().get(5).message().get("level")).isEqualTo("4");
    Assertions.assertThat(response.messages().get(5).message().get("severity")).isEqualTo("Warning (4)");
    Assertions.assertThat(response.messages().get(6).message().get("level")).isEqualTo("5");
    Assertions.assertThat(response.messages().get(6).message().get("severity")).isEqualTo("Notice (5)");
    Assertions.assertThat(response.messages().get(7).message().get("level")).isEqualTo("6");
    Assertions.assertThat(response.messages().get(7).message().get("severity")).isEqualTo("Informational (6)");
    Assertions.assertThat(response.messages().get(8).message().get("level")).isEqualTo("7");
    Assertions.assertThat(response.messages().get(8).message().get("severity")).isEqualTo("Debug (7)");
    // If the message does not have a source field, we do not touch it
    Assertions.assertThat(response.messages().get(9).message().get("level")).isNull();
    Assertions.assertThat(response.messages().get(9).message().get("severity")).isNull();
    Assertions.assertThat(response.messages().get(9).message().get("foo")).isEqualTo("1");
}
Also used : IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary) SearchResponse(org.graylog2.rest.resources.search.responses.SearchResponse) Test(org.junit.Test)

Example 4 with ResultMessageSummary

use of org.graylog2.rest.models.messages.responses.ResultMessageSummary in project graylog2-server by Graylog2.

the class FormatStringDecoratorTest method getSearchResponse.

private SearchResponse getSearchResponse() {
    final IndexRangeSummary indexRangeSummary = IndexRangeSummary.create("graylog_0", Tools.nowUTC().minusDays(1), Tools.nowUTC(), null, 100);
    final ImmutableMultimap<String, Range<Integer>> hlRanges = ImmutableMultimap.of();
    final List<ResultMessageSummary> messages = ImmutableList.of(create(hlRanges, ImmutableMap.of("_id", "h", "field_a", "1", "field_b", "b"), "graylog_0"), create(hlRanges, ImmutableMap.of("_id", "h", "field_a", "1"), "graylog_0"), create(hlRanges, ImmutableMap.of("_id", "h", "field_b", "b"), "graylog_0"), create(hlRanges, ImmutableMap.of("_id", "i", "foo", "1"), "graylog_0"));
    return SearchResponse.builder().query("foo").builtQuery("foo").usedIndices(ImmutableSet.of(indexRangeSummary)).messages(messages).fields(ImmutableSet.of("field_a", "field_b", "foo")).time(100L).totalResults(messages.size()).from(Tools.nowUTC().minusHours(1)).to(Tools.nowUTC()).build();
}
Also used : IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) Range(com.google.common.collect.Range) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary)

Example 5 with ResultMessageSummary

use of org.graylog2.rest.models.messages.responses.ResultMessageSummary in project graylog2-server by Graylog2.

the class LookupTableDecoratorTest method decorate.

@Test
public void decorate() throws Exception {
    final String sourceField = "source";
    final String targetField = "source_decorated";
    final String lookupTableName = "test";
    final Decorator decorator = createDecorator(sourceField, targetField, lookupTableName);
    final Pair<LookupTableDecorator, LookupTableService.Function> lookupTableDecoratorPair = createLookupTableDecorator(decorator);
    final LookupTableDecorator lookupTableDecorator = lookupTableDecoratorPair.getLeft();
    final LookupTableService.Function function = lookupTableDecoratorPair.getRight();
    final List<ResultMessageSummary> messages = ImmutableList.of(ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "a", sourceField, "0"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "b", sourceField, "1"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "c", sourceField, "2"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "d", sourceField, "3"), "graylog_0"), ResultMessageSummary.create(ImmutableMultimap.of(), ImmutableMap.of("_id", "e", "invalid", "4"), "graylog_0"));
    final SearchResponse searchResponse = createSearchResponse(messages);
    when(function.lookup("0")).thenReturn(LookupResult.single("zero"));
    when(function.lookup("1")).thenReturn(LookupResult.single("one"));
    when(function.lookup("2")).thenReturn(LookupResult.empty());
    when(function.lookup("3")).thenReturn(null);
    final SearchResponse response = lookupTableDecorator.apply(searchResponse);
    assertThat(response.messages().get(0).message().get(sourceField)).isEqualTo("0");
    assertThat(response.messages().get(0).message().get(targetField)).isEqualTo("zero");
    assertThat(response.messages().get(1).message().get(sourceField)).isEqualTo("1");
    assertThat(response.messages().get(1).message().get(targetField)).isEqualTo("one");
    assertThat(response.messages().get(2).message().get(sourceField)).isEqualTo("2");
    assertThat(response.messages().get(2).message()).doesNotContainKey(targetField);
    assertThat(response.messages().get(3).message().get(sourceField)).isEqualTo("3");
    assertThat(response.messages().get(3).message()).doesNotContainKey(targetField);
    assertThat(response.messages().get(4).message().get("invalid")).isEqualTo("4");
    assertThat(response.messages().get(4).message()).doesNotContainKey(targetField);
}
Also used : LookupTableService(org.graylog2.lookup.LookupTableService) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary) SearchResponse(org.graylog2.rest.resources.search.responses.SearchResponse) Test(org.junit.Test)

Aggregations

ResultMessageSummary (org.graylog2.rest.models.messages.responses.ResultMessageSummary)13 SearchResponse (org.graylog2.rest.resources.search.responses.SearchResponse)7 Message (org.graylog2.plugin.Message)6 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 DecorationStats (org.graylog2.rest.models.messages.responses.DecorationStats)4 HashSet (java.util.HashSet)3 LegacyDecoratorProcessor (org.graylog.plugins.views.search.LegacyDecoratorProcessor)3 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)3 IndexRangeSummary (org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary)3 SearchDecorationStats (org.graylog2.rest.resources.search.responses.SearchDecorationStats)3 DateTime (org.joda.time.DateTime)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 Named (com.google.inject.name.Named)2 ArrayList (java.util.ArrayList)2