Search in sources :

Example 1 with IndexRangeSummary

use of org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary in project graylog2-server by Graylog2.

the class IndexRangesResource method show.

@GET
@Path("/{index: [a-z_0-9]+}")
@Timed
@ApiOperation(value = "Show single index range")
@Produces(MediaType.APPLICATION_JSON)
public IndexRangeSummary show(@ApiParam(name = "index", value = "The name of the Graylog-managed Elasticsearch index", required = true) @PathParam("index") @NotEmpty String index) throws NotFoundException {
    if (!indexSetRegistry.isManagedIndex(index)) {
        throw new BadRequestException(index + " is not a Graylog-managed Elasticsearch index.");
    }
    checkPermission(RestPermissions.INDEXRANGES_READ, index);
    final IndexRange indexRange = indexRangeService.get(index);
    return IndexRangeSummary.create(indexRange.indexName(), indexRange.begin(), indexRange.end(), indexRange.calculatedAt(), indexRange.calculationDuration());
}
Also used : IndexRange(org.graylog2.indexer.ranges.IndexRange) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with IndexRangeSummary

use of org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary 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 IndexRangeSummary

use of org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary 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 IndexRangeSummary

use of org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary 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 IndexRangeSummary

use of org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary in project graylog2-server by Graylog2.

the class IndexerOverviewResource method getIndexerOverview.

private IndexerOverview getIndexerOverview(IndexSet indexSet) throws TooManyAliasesException {
    final String indexSetId = indexSet.getConfig().id();
    final DeflectorSummary deflectorSummary = deflectorResource.deflector(indexSetId);
    final List<IndexRangeSummary> indexRanges = indexRangesResource.list().ranges();
    final JsonNode indexStats = indices.getIndexStats(indexSet);
    final List<String> indexNames = new ArrayList<>();
    indexStats.fieldNames().forEachRemaining(indexNames::add);
    final Map<String, Boolean> areReopened = indices.areReopened(indexNames);
    final Map<String, IndexSummary> indicesSummaries = buildIndexSummaries(deflectorSummary, indexSet, indexRanges, indexStats, areReopened);
    return IndexerOverview.create(deflectorSummary, IndexerClusterOverview.create(indexerClusterResource.clusterHealth(), indexerClusterResource.clusterName().name()), MessageCountResponse.create(counts.total(indexSet)), indicesSummaries);
}
Also used : DeflectorSummary(org.graylog2.rest.models.system.deflector.responses.DeflectorSummary) IndexRangeSummary(org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IndexSummary(org.graylog2.rest.models.system.indexer.responses.IndexSummary)

Aggregations

IndexRangeSummary (org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary)6 Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 ResultMessageSummary (org.graylog2.rest.models.messages.responses.ResultMessageSummary)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2 Path (javax.ws.rs.Path)2 IndexRange (org.graylog2.indexer.ranges.IndexRange)2 DeflectorSummary (org.graylog2.rest.models.system.deflector.responses.DeflectorSummary)2 IndexSummary (org.graylog2.rest.models.system.indexer.responses.IndexSummary)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Range (com.google.common.collect.Range)1 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1