use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class OutputResource method delete.
@DELETE
@Path("/{outputId}")
@Timed
@ApiOperation(value = "Delete output")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_OUTPUT_DELETE)
public void delete(@ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws org.graylog2.database.NotFoundException {
checkPermission(RestPermissions.OUTPUTS_TERMINATE);
final Output output = outputService.load(outputId);
outputService.destroy(output);
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class JsonTesterResource method testJsonExtractor.
private JsonTesterResponse testJsonExtractor(String testString, boolean flatten, String listSeparator, String keySeparator, String kvSeparator, boolean replaceKeyWhitespace, String keyWhitespaceReplacement, String keyPrefix) {
final Map<String, Object> config = ImmutableMap.<String, Object>builder().put("flatten", flatten).put("list_separator", listSeparator).put("key_separator", keySeparator).put("kv_separator", kvSeparator).put("replace_key_whitespace", replaceKeyWhitespace).put("key_whitespace_replacement", keyWhitespaceReplacement).put("key_prefix", keyPrefix).build();
final JsonExtractor extractor;
try {
extractor = new JsonExtractor(new MetricRegistry(), "test", "Test", 0L, Extractor.CursorStrategy.COPY, "test", "test", config, getCurrentUser().getName(), Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
} catch (Extractor.ReservedFieldException e) {
throw new BadRequestException("Trying to overwrite a reserved message field", e);
} catch (ConfigurationException e) {
throw new BadRequestException("Invalid extractor configuration", e);
}
final Map<String, Object> result;
try {
result = extractor.extractJson(testString);
} catch (IOException e) {
throw new BadRequestException("Failure running JSON extractor: " + e.getMessage(), e);
}
return JsonTesterResponse.create(result, flatten, listSeparator, keySeparator, kvSeparator, testString);
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class LookupTableFieldValueProviderTest method testWithMessageContext.
@Test
public void testWithMessageContext() {
final String fieldValueString = "world";
final String expectedLookupValue = "lookup-world";
final TestEvent event = new TestEvent();
final Message message = newMessage(ImmutableMap.of("hello", fieldValueString));
final EventWithContext eventWithContext = EventWithContext.create(event, message);
final LookupTableFieldValueProvider.Config config = newConfig("test", "hello");
setupMocks("test");
when(lookupTableFunction.lookup("world")).thenReturn(LookupResult.single("lookup-" + message.getField("hello")));
final FieldValue fieldValue = newProvider(config).doGet("test", eventWithContext);
assertThat(fieldValue.value()).isEqualTo(expectedLookupValue);
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class SearchesAdapterES7 method count.
@Override
public CountResult count(Set<String> affectedIndices, String query, TimeRange range, String filter) {
final SearchesConfig config = SearchesConfig.builder().query(query).range(range).filter(filter).limit(0).offset(0).build();
final SearchSourceBuilder searchSourceBuilder = searchRequestFactory.create(config);
final SearchRequest searchRequest = new SearchRequest(affectedIndices.toArray(new String[0])).source(searchSourceBuilder);
final SearchResponse result = client.search(searchRequest, "Fetching message count failed for indices ");
return CountResult.create(result.getHits().getTotalHits().value, result.getTook().getMillis());
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class CreateMessage method evaluate.
@Override
public Message evaluate(FunctionArgs args, EvaluationContext context) {
final Optional<String> optMessage = messageParam.optional(args, context);
final String message = optMessage.isPresent() ? optMessage.get() : context.currentMessage().getMessage();
final Optional<String> optSource = sourceParam.optional(args, context);
final String source = optSource.isPresent() ? optSource.get() : context.currentMessage().getSource();
final Optional<DateTime> optTimestamp = timestampParam.optional(args, context);
final DateTime timestamp = optTimestamp.isPresent() ? optTimestamp.get() : Tools.nowUTC();
final Message newMessage = new Message(message, source, timestamp);
// register in context so the processor can inject it later on
context.addCreatedMessage(newMessage);
return newMessage;
}
Aggregations