Search in sources :

Example 1 with ConfigurationException

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

the class CsvConverterTest method assertConfigException.

private void assertConfigException(Map<String, Object> configMap) {
    ConfigurationException configurationException = null;
    try {
        new CsvConverter(configMap);
    } catch (ConfigurationException e) {
        configurationException = e;
    }
    assertNotNull("Config exception expected", configurationException);
}
Also used : ConfigurationException(org.graylog2.ConfigurationException)

Example 2 with ConfigurationException

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

the class StreamResource method cloneStream.

@POST
@Path("/{streamId}/clone")
@Timed
@ApiOperation(value = "Clone a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid or missing Stream id.") })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_CREATE)
public Response cloneStream(@ApiParam(name = "streamId", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CloneStreamRequest cr) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.STREAMS_CREATE);
    checkPermission(RestPermissions.STREAMS_READ, streamId);
    checkNotDefaultStream(streamId, "The default stream cannot be cloned.");
    final Stream sourceStream = streamService.load(streamId);
    final String creatorUser = getCurrentUser().getName();
    // Create stream.
    final Map<String, Object> streamData = Maps.newHashMap();
    streamData.put(StreamImpl.FIELD_TITLE, cr.title());
    streamData.put(StreamImpl.FIELD_DESCRIPTION, cr.description());
    streamData.put(StreamImpl.FIELD_CREATOR_USER_ID, creatorUser);
    streamData.put(StreamImpl.FIELD_CREATED_AT, Tools.nowUTC());
    streamData.put(StreamImpl.FIELD_MATCHING_TYPE, sourceStream.getMatchingType().toString());
    streamData.put(StreamImpl.FIELD_REMOVE_MATCHES_FROM_DEFAULT_STREAM, cr.removeMatchesFromDefaultStream());
    streamData.put(StreamImpl.FIELD_INDEX_SET_ID, cr.indexSetId());
    final Stream stream = streamService.create(streamData);
    streamService.pause(stream);
    final String id = streamService.save(stream);
    final List<StreamRule> sourceStreamRules = streamRuleService.loadForStream(sourceStream);
    for (StreamRule streamRule : sourceStreamRules) {
        final Map<String, Object> streamRuleData = Maps.newHashMapWithExpectedSize(6);
        streamRuleData.put(StreamRuleImpl.FIELD_TYPE, streamRule.getType().toInteger());
        streamRuleData.put(StreamRuleImpl.FIELD_FIELD, streamRule.getField());
        streamRuleData.put(StreamRuleImpl.FIELD_VALUE, streamRule.getValue());
        streamRuleData.put(StreamRuleImpl.FIELD_INVERTED, streamRule.getInverted());
        streamRuleData.put(StreamRuleImpl.FIELD_STREAM_ID, new ObjectId(id));
        streamRuleData.put(StreamRuleImpl.FIELD_DESCRIPTION, streamRule.getDescription());
        final StreamRule newStreamRule = streamRuleService.create(streamRuleData);
        streamRuleService.save(newStreamRule);
    }
    for (AlertCondition alertCondition : streamService.getAlertConditions(sourceStream)) {
        try {
            final AlertCondition clonedAlertCondition = alertService.fromRequest(CreateConditionRequest.create(alertCondition.getType(), alertCondition.getTitle(), alertCondition.getParameters()), stream, creatorUser);
            streamService.addAlertCondition(stream, clonedAlertCondition);
        } catch (ConfigurationException e) {
            LOG.warn("Unable to clone alert condition <" + alertCondition + "> - skipping: ", e);
        }
    }
    for (AlarmCallbackConfiguration alarmCallbackConfiguration : alarmCallbackConfigurationService.getForStream(sourceStream)) {
        final CreateAlarmCallbackRequest request = CreateAlarmCallbackRequest.create(alarmCallbackConfiguration);
        final AlarmCallbackConfiguration alarmCallback = alarmCallbackConfigurationService.create(stream.getId(), request, getCurrentUser().getName());
        alarmCallbackConfigurationService.save(alarmCallback);
    }
    for (Output output : sourceStream.getOutputs()) {
        streamService.addOutput(stream, output);
    }
    clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
    final Map<String, String> result = ImmutableMap.of("stream_id", id);
    final URI streamUri = getUriBuilderToSelf().path(StreamResource.class).path("{streamId}").build(id);
    return Response.created(streamUri).entity(result).build();
}
Also used : ObjectId(org.bson.types.ObjectId) StreamRule(org.graylog2.plugin.streams.StreamRule) URI(java.net.URI) CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Output(org.graylog2.plugin.streams.Output) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Stream(org.graylog2.plugin.streams.Stream) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with ConfigurationException

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

the class BundleImporter method createInputs.

private void createInputs(final String bundleId, final Set<Input> inputs, final String userName) throws org.graylog2.plugin.inputs.Extractor.ReservedFieldException, org.graylog2.ConfigurationException, NoSuchInputTypeException, ValidationException, ExtractorFactory.NoSuchExtractorException, NotFoundException, ConfigurationException {
    for (final Input input : inputs) {
        final MessageInput messageInput = createMessageInput(bundleId, input, userName);
        createdInputs.put(messageInput.getId(), messageInput);
        // Launch input. (this will run async and clean up itself in case of an error.)
        inputLauncher.launch(messageInput);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 4 with ConfigurationException

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

the class BundleImporter method createMessageInput.

private MessageInput createMessageInput(final String bundleId, final Input inputDescription, final String userName) throws NoSuchInputTypeException, ConfigurationException, ValidationException, NotFoundException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, org.graylog2.plugin.inputs.Extractor.ReservedFieldException {
    final Configuration inputConfig = new Configuration(inputDescription.getConfiguration());
    final DateTime createdAt = Tools.nowUTC();
    final MessageInput messageInput = messageInputFactory.create(inputDescription.getType(), inputConfig);
    messageInput.setTitle(inputDescription.getTitle());
    messageInput.setGlobal(inputDescription.isGlobal());
    messageInput.setCreatorUserId(userName);
    messageInput.setCreatedAt(createdAt);
    messageInput.setContentPack(bundleId);
    messageInput.checkConfiguration();
    // Don't run if exclusive and another instance is already running.
    if (messageInput.isExclusive() && inputRegistry.hasTypeRunning(messageInput.getClass())) {
        LOG.error("Input type <{}> of input <{}> is exclusive and already has input running.", messageInput.getClass(), messageInput.getTitle());
    }
    final String id = inputDescription.getId();
    final org.graylog2.inputs.Input mongoInput;
    if (id == null) {
        mongoInput = inputService.create(buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
    } else {
        mongoInput = inputService.create(id, buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
    }
    // Persist input.
    final String persistId = inputService.save(mongoInput);
    messageInput.setPersistId(persistId);
    messageInput.initialize();
    addStaticFields(messageInput, inputDescription.getStaticFields());
    addExtractors(messageInput, inputDescription.getExtractors(), userName);
    return messageInput;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) DateTime(org.joda.time.DateTime)

Example 5 with ConfigurationException

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

the class InputFacade method createConverters.

private List<Converter> createConverters(final List<ConverterEntity> requestedConverters, final Map<String, ValueReference> parameters) {
    final ImmutableList.Builder<Converter> converters = ImmutableList.builder();
    for (final ConverterEntity converterEntity : requestedConverters) {
        try {
            final Converter converter = converterFactory.create(converterEntity.type().asEnum(parameters, Converter.Type.class), toValueMap(converterEntity.configuration(), parameters));
            converters.add(converter);
        } catch (ConverterFactory.NoSuchConverterException e) {
            LOG.warn("No such converter [" + converterEntity.type() + "]. Skipping.", e);
        } catch (org.graylog2.ConfigurationException e) {
            LOG.warn("Missing configuration for [" + converterEntity.type() + "]. Skipping.", e);
        }
    }
    return converters.build();
}
Also used : ModelType(org.graylog2.contentpacks.model.ModelType) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) ImmutableList(com.google.common.collect.ImmutableList) Converter(org.graylog2.plugin.inputs.Converter) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory)

Aggregations

ConfigurationException (org.graylog2.plugin.configuration.ConfigurationException)11 Timed (com.codahale.metrics.annotation.Timed)9 ApiOperation (io.swagger.annotations.ApiOperation)9 BadRequestException (javax.ws.rs.BadRequestException)8 AuditEvent (org.graylog2.audit.jersey.AuditEvent)8 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)7 Stream (org.graylog2.plugin.streams.Stream)7 ApiResponses (io.swagger.annotations.ApiResponses)6 URI (java.net.URI)6 Path (javax.ws.rs.Path)6 POST (javax.ws.rs.POST)5 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)5 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)5 Consumes (javax.ws.rs.Consumes)4 Produces (javax.ws.rs.Produces)4 ConfigurationException (org.graylog2.ConfigurationException)4 Extractor (org.graylog2.plugin.inputs.Extractor)4 MessageInput (org.graylog2.plugin.inputs.MessageInput)4 CreateAlarmCallbackRequest (org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest)4 PUT (javax.ws.rs.PUT)3