Search in sources :

Example 11 with ConfigurationException

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

the class MessageInput method checkConfiguration.

public void checkConfiguration() throws ConfigurationException {
    final ConfigurationRequest cr = getRequestedConfiguration();
    cr.check(getConfiguration());
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest)

Example 12 with ConfigurationException

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

the class StreamAlertConditionResource method create.

@POST
@Timed
@ApiOperation(value = "Create an alert condition")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.ALERT_CONDITION_CREATE)
public Response create(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamid, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateConditionRequest ccr) throws NotFoundException, ValidationException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    final Stream stream = streamService.load(streamid);
    try {
        final AlertCondition alertCondition = alertService.fromRequest(convertConfigurationInRequest(ccr), stream, getCurrentUser().getName());
        streamService.addAlertCondition(stream, alertCondition);
        final Map<String, String> result = ImmutableMap.of("alert_condition_id", alertCondition.getId());
        final URI alertConditionUri = getUriBuilderToSelf().path(StreamAlertConditionResource.class).path("{conditionId}").build(stream.getId(), alertCondition.getId());
        return Response.created(alertConditionUri).entity(result).build();
    } catch (ConfigurationException e) {
        throw new BadRequestException("Invalid alert condition parameters", e);
    }
}
Also used : ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) BadRequestException(javax.ws.rs.BadRequestException) Stream(org.graylog2.plugin.streams.Stream) URI(java.net.URI) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with ConfigurationException

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

the class StreamAlarmCallbackResource method create.

@POST
@Timed
@ApiOperation(value = "Create an alarm callback", response = CreateAlarmCallbackResponse.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_CREATE)
public Response create(@ApiParam(name = "streamid", value = "The stream id this new alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest originalCr) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    // make sure the values are correctly converted to the declared configuration types
    final CreateAlarmCallbackRequest cr = CreateAlarmCallbackRequest.create(originalCr.type(), originalCr.title(), convertConfigurationValues(originalCr));
    final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.create(streamid, cr, getCurrentUser().getName());
    final String id;
    try {
        alarmCallbackFactory.create(alarmCallbackConfiguration).checkConfiguration();
        id = alarmCallbackConfigurationService.save(alarmCallbackConfiguration);
    } catch (ValidationException | AlarmCallbackConfigurationException | ConfigurationException e) {
        LOG.error("Invalid alarm callback configuration.", e);
        throw new BadRequestException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        LOG.error("Invalid alarm callback type.", e);
        throw new BadRequestException("Invalid alarm callback type.", e);
    }
    final URI alarmCallbackUri = getUriBuilderToSelf().path(StreamAlarmCallbackResource.class).path("{alarmCallbackId}").build(streamid, id);
    return Response.created(alarmCallbackUri).entity(CreateAlarmCallbackResponse.create(id)).build();
}
Also used : CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) 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) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 14 with ConfigurationException

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

the class CopyInputExtractorTest method testCopy.

@Test
public void testCopy() throws Extractor.ReservedFieldException, ConfigurationException {
    Message msg = new Message("The short message", "TestUnit", Tools.nowUTC());
    msg.addField("somefield", "foo");
    CopyInputExtractor x = new CopyInputExtractor(metricRegistry, "bar", "bar", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", noConfig(), "foo", noConverters(), Extractor.ConditionType.NONE, null);
    x.runExtractor(msg);
    assertEquals("foo", msg.getField("our_result"));
    assertEquals("foo", msg.getField("somefield"));
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 15 with ConfigurationException

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

the class AlertConditionFactory method createAlertCondition.

public AlertCondition createAlertCondition(String type, Stream stream, String id, DateTime createdAt, String creatorId, Map<String, Object> parameters, String title) throws ConfigurationException {
    final AlertCondition.Factory factory = this.alertConditionMap.get(type);
    checkArgument(factory != null, "Unknown alert condition type: " + type);
    /*
         * Ensure the given parameters fulfill the requested configuration preconditions.
         * Here we strictly use the Configuration object to verify the configuration and don't pass it down to
         * the factory. The reason for this is that Configuration only support int values, but at least an
         * alert condition expects a double.
         */
    try {
        final ConfigurationRequest requestedConfiguration = factory.config().getRequestedConfiguration();
        final Configuration configuration = new Configuration(parameters);
        requestedConfiguration.check(configuration);
    } catch (ConfigurationException e) {
        final String conditionTitle = isNullOrEmpty(title) ? "" : "'" + title + "' ";
        LOG.error("Could not load alert condition " + conditionTitle + "<" + id + ">, invalid configuration detected.");
        throw e;
    }
    return factory.create(stream, id, createdAt, creatorId, parameters, title);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) AlertCondition(org.graylog2.plugin.alarms.AlertCondition)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 BadRequestException (javax.ws.rs.BadRequestException)7 AuditEvent (org.graylog2.audit.jersey.AuditEvent)7 ConfigurationException (org.graylog2.plugin.configuration.ConfigurationException)7 ApiResponses (io.swagger.annotations.ApiResponses)5 URI (java.net.URI)5 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)4 MessageInput (org.graylog2.plugin.inputs.MessageInput)4 Consumes (javax.ws.rs.Consumes)3 PUT (javax.ws.rs.PUT)3 Produces (javax.ws.rs.Produces)3 ConfigurationException (org.graylog2.ConfigurationException)3 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)3 Stream (org.graylog2.plugin.streams.Stream)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Input (org.graylog2.inputs.Input)2 AlarmCallbackConfigurationException (org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException)2