use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class RegexReplaceTesterResource method testRegexReplaceExtractor.
private RegexReplaceTesterResponse testRegexReplaceExtractor(String example, String regex, String replacement, boolean replaceAll) {
final Map<String, Object> config = ImmutableMap.<String, Object>of("regex", regex, "replacement", replacement, "replace_all", replaceAll);
final RegexReplaceExtractor extractor;
try {
extractor = new RegexReplaceExtractor(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 Extractor.Result result = extractor.runExtractor(example);
final RegexReplaceTesterResponse.Match match = result == null ? null : RegexReplaceTesterResponse.Match.create(String.valueOf(result.getValue()), result.getBeginIndex(), result.getEndIndex());
return RegexReplaceTesterResponse.create(result != null, match, regex, replacement, replaceAll, example);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class InputStatesResource method start.
@PUT
@Path("/{inputId}")
@Timed
@ApiOperation(value = "(Re-)Start specified input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_START)
public InputCreated start(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
inputService.find(inputId);
final InputCreated result = InputCreated.create(inputId);
this.serverEventBus.post(result);
return result;
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorsResource method create.
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add an extractor to an input", response = ExtractorCreated.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "No such extractor type."), @ApiResponse(code = 400, message = "Field the extractor should write on is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.EXTRACTOR_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer) throws NotFoundException {
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
final Input mongoInput = inputService.find(inputId);
final String id = new com.eaio.uuid.UUID().toString();
final Extractor extractor = buildExtractorFromRequest(cer, id);
try {
inputService.addExtractor(mongoInput, extractor);
} catch (ValidationException e) {
final String msg = "Extractor persist validation failed.";
LOG.error(msg, e);
throw new BadRequestException(msg, e);
}
final String msg = "Added extractor <" + id + "> of type [" + cer.extractorType() + "] to input <" + inputId + ">.";
LOG.info(msg);
activityWriter.write(new Activity(msg, ExtractorsResource.class));
final ExtractorCreated result = ExtractorCreated.create(id);
final URI extractorUri = getUriBuilderToSelf().path(ExtractorsResource.class).path("{inputId}").build(mongoInput.getId());
return Response.created(extractorUri).entity(result).build();
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorTest method testConvertersWithMultipleFieldsAndNull.
@Test
public void testConvertersWithMultipleFieldsAndNull() throws Exception {
final Converter converter = new TestConverter.Builder().multiple(true).callback(new Function<Object, Object>() {
@Nullable
@Override
public Object apply(Object input) {
return null;
}
}).build();
final TestExtractor extractor = new TestExtractor.Builder().converters(Collections.singletonList(converter)).callback(() -> new Result[] { new Result("1", -1, -1) }).build();
final Message msg = createMessage("the message");
extractor.runExtractor(msg);
assertThat(msg.getField("message")).isEqualTo("the message");
assertThat(extractor.getConverterExceptionCount()).isEqualTo(0L);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class ExtractorTest method testCursorStrategyCutWithAllTextCut.
@Test
public void testCursorStrategyCutWithAllTextCut() throws Exception {
final TestExtractor extractor = new TestExtractor.Builder().cursorStrategy(CUT).sourceField("msg").callback(new Callable<Result[]>() {
@Override
public Result[] call() throws Exception {
return new Result[] { new Result("the hello", 0, 9) };
}
}).build();
final Message msg = createMessage("message");
msg.addField("msg", "the hello");
extractor.runExtractor(msg);
// If all data is cut from the source field, the "fullyCutByExtractor" string gets inserted.
assertThat(msg.getField("msg")).isEqualTo("fullyCutByExtractor");
}
Aggregations