Search in sources :

Example 56 with Extractor

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

the class InputServiceImpl method getConvertersOfExtractor.

@SuppressWarnings("unchecked")
private List<Converter> getConvertersOfExtractor(DBObject extractor) {
    final ImmutableList.Builder<Converter> listBuilder = ImmutableList.builder();
    final BasicDBList converters = (BasicDBList) extractor.get(Extractor.FIELD_CONVERTERS);
    for (final Object element : converters) {
        final DBObject c = (BasicDBObject) element;
        try {
            listBuilder.add(converterFactory.create(Converter.Type.valueOf(((String) c.get(Extractor.FIELD_CONVERTER_TYPE)).toUpperCase(Locale.ENGLISH)), (Map<String, Object>) c.get(Extractor.FIELD_CONVERTER_CONFIG)));
        } catch (ConverterFactory.NoSuchConverterException e1) {
            LOG.error("Cannot build converter from persisted data. No such converter.", e1);
        } catch (Exception e) {
            LOG.error("Cannot build converter from persisted data.", e);
        }
    }
    return listBuilder.build();
}
Also used : BasicDBList(com.mongodb.BasicDBList) BasicDBObject(com.mongodb.BasicDBObject) ImmutableList(com.google.common.collect.ImmutableList) Converter(org.graylog2.plugin.inputs.Converter) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) NotFoundException(org.graylog2.database.NotFoundException) ValidationException(org.graylog2.plugin.database.ValidationException)

Example 57 with Extractor

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

the class ExtractorsResource method update.

@PUT
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an extractor")
@Path("/{extractorId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 404, message = "No such extractor on this input."), @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_UPDATE)
public ExtractorSummary update(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "extractorId", required = true) @PathParam("extractorId") String extractorId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    final Input mongoInput = inputService.find(inputId);
    final Extractor originalExtractor = inputService.getExtractor(mongoInput, extractorId);
    final Extractor extractor = buildExtractorFromRequest(cer, originalExtractor.getId());
    try {
        inputService.updateExtractor(mongoInput, extractor);
    } catch (ValidationException e) {
        LOG.error("Extractor persist validation failed.", e);
        throw new BadRequestException(e);
    }
    final String msg = "Updated extractor <" + originalExtractor.getId() + "> of type [" + cer.extractorType() + "] in input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, ExtractorsResource.class));
    return toSummary(extractor);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) BadRequestException(javax.ws.rs.BadRequestException) Activity(org.graylog2.shared.system.activities.Activity) Extractor(org.graylog2.plugin.inputs.Extractor) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 58 with Extractor

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

the class ExtractorsResource method list.

@GET
@Timed
@ApiOperation(value = "List all extractors of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@Produces(MediaType.APPLICATION_JSON)
public ExtractorSummaryList list(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_READ, inputId);
    final Input input = inputService.find(inputId);
    final List<ExtractorSummary> extractors = Lists.newArrayList();
    for (Extractor extractor : inputService.getExtractors(input)) {
        extractors.add(toSummary(extractor));
    }
    return ExtractorSummaryList.create(extractors);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) Extractor(org.graylog2.plugin.inputs.Extractor) ExtractorSummary(org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorSummary) 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

Test (org.junit.Test)40 Message (org.graylog2.plugin.Message)39 Result (org.graylog2.plugin.inputs.Extractor.Result)29 Callable (java.util.concurrent.Callable)27 Extractor (org.graylog2.plugin.inputs.Extractor)18 Input (org.graylog2.inputs.Input)10 DateConverter (org.graylog2.inputs.converters.DateConverter)9 MessageInput (org.graylog2.plugin.inputs.MessageInput)9 Function (com.google.common.base.Function)8 NotFoundException (org.graylog2.database.NotFoundException)7 ValidationException (org.graylog2.plugin.database.ValidationException)7 Timed (com.codahale.metrics.annotation.Timed)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)5 BadRequestException (javax.ws.rs.BadRequestException)4 Path (javax.ws.rs.Path)4 LookupTableExtractor (org.graylog2.inputs.extractors.LookupTableExtractor)4 Converter (org.graylog2.plugin.inputs.Converter)4 ImmutableList (com.google.common.collect.ImmutableList)3