Search in sources :

Example 6 with AlarmCallbackConfigurationException

use of org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException 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)

Aggregations

AlarmCallback (org.graylog2.plugin.alarms.callbacks.AlarmCallback)4 AlarmCallbackConfigurationException (org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException)4 Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 BadRequestException (javax.ws.rs.BadRequestException)3 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)3 ConfigurationException (org.graylog2.plugin.configuration.ConfigurationException)3 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2 AlarmCallbackException (org.graylog2.plugin.alarms.callbacks.AlarmCallbackException)2 Configuration (org.graylog2.plugin.configuration.Configuration)2 ValidationException (org.graylog2.plugin.database.ValidationException)2 Stream (org.graylog2.plugin.streams.Stream)2 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1