Search in sources :

Example 66 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class V20161116172200_CreateDefaultStreamMigration method createDefaultStream.

private void createDefaultStream() {
    final IndexSet indexSet = indexSetRegistry.getDefault();
    final ObjectId id = new ObjectId(Stream.DEFAULT_STREAM_ID);
    final Map<String, Object> fields = ImmutableMap.<String, Object>builder().put(StreamImpl.FIELD_TITLE, "All messages").put(StreamImpl.FIELD_DESCRIPTION, "Stream containing all messages").put(StreamImpl.FIELD_DISABLED, false).put(StreamImpl.FIELD_CREATED_AT, DateTime.now(DateTimeZone.UTC)).put(StreamImpl.FIELD_CREATOR_USER_ID, "local:admin").put(StreamImpl.FIELD_MATCHING_TYPE, StreamImpl.MatchingType.DEFAULT.name()).put(StreamImpl.FIELD_REMOVE_MATCHES_FROM_DEFAULT_STREAM, false).put(StreamImpl.FIELD_DEFAULT_STREAM, true).put(StreamImpl.FIELD_INDEX_SET_ID, indexSet.getConfig().id()).build();
    final Stream stream = new StreamImpl(id, fields, Collections.emptyList(), Collections.emptySet(), indexSet);
    try {
        streamService.save(stream);
        LOG.info("Successfully created default stream: {}", stream.getTitle());
    } catch (ValidationException e) {
        LOG.error("Couldn't create default stream! This is a bug!");
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) ObjectId(org.bson.types.ObjectId) StreamImpl(org.graylog2.streams.StreamImpl) Stream(org.graylog2.plugin.streams.Stream) IndexSet(org.graylog2.indexer.IndexSet)

Example 67 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class AbsoluteSearchResource method searchAbsolute.

@GET
@Timed
@ApiOperation(value = "Message search with absolute timerange.", notes = "Search for messages using an absolute timerange, specified as from/to " + "with format yyyy-MM-ddTHH:mm:ss.SSSZ (e.g. 2014-01-23T15:34:49.000Z) or yyyy-MM-dd HH:mm:ss.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timerange parameters provided.") })
public SearchResponse searchAbsolute(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "from", value = "Timerange start. See description for date format", required = true) @QueryParam("from") @NotEmpty String from, @ApiParam(name = "to", value = "Timerange end. See description for date format", required = true) @QueryParam("to") @NotEmpty String to, @ApiParam(name = "limit", value = "Maximum number of messages to return.") @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset") @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter") @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return") @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)") @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result") @QueryParam("decorate") @DefaultValue("true") boolean decorate, @Context SearchUser searchUser) {
    checkSearchPermission(filter, RestPermissions.SEARCHES_ABSOLUTE);
    final Sort sorting = buildSortOrder(sort);
    final List<String> fieldList = parseOptionalFields(fields);
    final TimeRange timeRange = buildAbsoluteTimeRange(from, to);
    return search(query, limit, filter, decorate, searchUser, fieldList, sorting, timeRange);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Sort(org.graylog.plugins.views.search.searchtypes.Sort) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 68 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class KeywordSearchResource method searchKeyword.

@GET
@Timed
@ApiOperation(value = "Message search with keyword as timerange.", notes = "Search for messages in a timerange defined by a keyword like \"yesterday\" or \"2 weeks ago to wednesday\".")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid keyword provided.") })
public SearchResponse searchKeyword(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "keyword", value = "Range keyword", required = true) @QueryParam("keyword") @NotEmpty String keyword, @QueryParam("timezone") @NotEmpty String timezone, @ApiParam(name = "limit", value = "Maximum number of messages to return.") @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset") @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter") @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return") @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)") @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result") @QueryParam("decorate") @DefaultValue("true") boolean decorate, @Context SearchUser searchUser) {
    checkSearchPermission(filter, RestPermissions.SEARCHES_KEYWORD);
    final Sort sorting = buildSortOrder(sort);
    final List<String> fieldList = parseOptionalFields(fields);
    final TimeRange timeRange = buildKeywordTimeRange(keyword, timezone);
    return search(query, limit, filter, decorate, searchUser, fieldList, sorting, timeRange);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Sort(org.graylog.plugins.views.search.searchtypes.Sort) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 69 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class RelativeSearchResource method searchRelative.

@GET
@Timed
@ApiOperation(value = "Message search with relative timerange.", notes = "Search for messages in a relative timerange, specified as seconds from now. " + "Example: 300 means search from 5 minutes ago to now.")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timerange parameters provided.") })
@Produces(MediaType.APPLICATION_JSON)
public SearchResponse searchRelative(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "range", value = "Relative timeframe to search in. See method description.", required = true) @QueryParam("range") @PositiveOrZero int range, @ApiParam(name = "limit", value = "Maximum number of messages to return.") @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset") @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter") @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return") @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)") @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result") @QueryParam("decorate") @DefaultValue("true") boolean decorate, @Context SearchUser searchUser) {
    checkSearchPermission(filter, RestPermissions.SEARCHES_RELATIVE);
    final List<String> fieldList = parseOptionalFields(fields);
    final Sort sorting = buildSortOrder(sort);
    final TimeRange timeRange = buildRelativeTimeRange(range);
    return search(query, limit, filter, decorate, searchUser, fieldList, sorting, timeRange);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Sort(org.graylog.plugins.views.search.searchtypes.Sort) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 70 with Messages

use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.

the class RelativeSearchResource method searchRelativeChunked.

@GET
@Timed
@ApiOperation(value = "Message search with relative timerange.", notes = "Search for messages in a relative timerange, specified as seconds from now. " + "Example: 300 means search from 5 minutes ago to now.")
@Produces(MoreMediaTypes.TEXT_CSV)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timerange parameters provided.") })
public ChunkedOutput<ScrollResult.ScrollChunk> searchRelativeChunked(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "range", value = "Relative timeframe to search in. See method description.", required = true) @QueryParam("range") @PositiveOrZero int range, @ApiParam(name = "limit", value = "Maximum number of messages to return.", required = false) @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset", required = false) @QueryParam("offset") int offset, @ApiParam(name = "batch_size", value = "Batch size for the backend storage export request.", required = false) @QueryParam("batch_size") @DefaultValue(DEFAULT_SCROLL_BATCH_SIZE) int batchSize, @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return", required = true) @QueryParam("fields") @NotEmpty String fields) {
    checkSearchPermission(filter, RestPermissions.SEARCHES_RELATIVE);
    final List<String> fieldList = parseFields(fields);
    final TimeRange timeRange = buildRelativeTimeRange(range);
    final ScrollResult scroll = searches.scroll(query, timeRange, limit, offset, fieldList, filter, batchSize);
    return buildChunkedOutput(scroll);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) ScrollResult(org.graylog2.indexer.results.ScrollResult) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Message (org.graylog2.plugin.Message)41 Test (org.junit.Test)31 DateTime (org.joda.time.DateTime)17 Map (java.util.Map)15 ApiOperation (io.swagger.annotations.ApiOperation)14 Produces (javax.ws.rs.Produces)14 Timed (com.codahale.metrics.annotation.Timed)13 ApiResponses (io.swagger.annotations.ApiResponses)12 Messages (org.graylog2.plugin.Messages)12 List (java.util.List)11 GET (javax.ws.rs.GET)11 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)11 ResultMessage (org.graylog2.indexer.results.ResultMessage)10 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)10 ArrayList (java.util.ArrayList)9 Collectors (java.util.stream.Collectors)9 ResultMessageSummary (org.graylog2.rest.models.messages.responses.ResultMessageSummary)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 IOException (java.io.IOException)8 Inject (javax.inject.Inject)8