Search in sources :

Example 1 with AlarmCallbackConfigurationException

use of org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException in project graylog2-server by Graylog2.

the class LegacyAlarmCallbackFactory method create.

public AlarmCallback create(String type, Map<String, Object> configuration) throws ClassNotFoundException, AlarmCallbackConfigurationException {
    AlarmCallback alarmCallback = create(type);
    alarmCallback.initialize(new Configuration(configuration));
    return alarmCallback;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback)

Example 2 with AlarmCallbackConfigurationException

use of org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException in project graylog2-server by Graylog2.

the class LegacyAlarmCallbackSender method send.

public void send(LegacyAlarmCallbackEventNotificationConfig config, EventDefinition eventDefinition, EventDto event, List<MessageSummary> backlog) throws Exception {
    final String callbackType = config.callbackType();
    final Stream stream = findStream(eventDefinition.config());
    final AbstractAlertCondition alertCondition = new LegacyAlertCondition(stream, eventDefinition, event);
    final AbstractAlertCondition.CheckResult checkResult = new AbstractAlertCondition.CheckResult(true, alertCondition, event.message(), event.processingTimestamp(), backlog);
    try {
        final AlarmCallback callback = alarmCallbackFactory.create(callbackType, config.configuration());
        callback.checkConfiguration();
        callback.call(stream, checkResult);
    } catch (ClassNotFoundException e) {
        LOG.error("Couldn't find implementation class for type <{}>", callbackType);
        throw e;
    } catch (AlarmCallbackConfigurationException e) {
        LOG.error("Invalid legacy alarm callback configuration", e);
        throw e;
    } catch (ConfigurationException e) {
        LOG.error("Invalid configuration for legacy alarm callback <{}>", callbackType, e);
        throw e;
    } catch (AlarmCallbackException e) {
        LOG.error("Couldn't execute legacy alarm callback <{}>", callbackType, e);
        throw e;
    }
}
Also used : AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Stream(org.graylog2.plugin.streams.Stream) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException)

Example 3 with AlarmCallbackConfigurationException

use of org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException in project graylog2-server by Graylog2.

the class StreamAlertResource method sendDummyAlert.

@POST
@Timed
@Path("sendDummyAlert")
@ApiOperation(value = "Send a test mail for a given stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 400, message = "Stream has no alarm callbacks") })
@NoAuditEvent("only used to test alert emails")
public void sendDummyAlert(@ApiParam(name = "streamId", value = "The stream id the test alert should be sent for.", required = true) @PathParam("streamId") String streamId) throws TransportConfigurationException, EmailException, NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamId);
    final Stream stream = streamService.load(streamId);
    final DummyAlertCondition dummyAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
    try {
        AbstractAlertCondition.CheckResult checkResult = dummyAlertCondition.runCheck();
        List<AlarmCallbackConfiguration> callConfigurations = alarmCallbackConfigurationService.getForStream(stream);
        if (callConfigurations.size() == 0) {
            final String message = "Stream has no alarm callbacks, cannot send test alert.";
            LOG.warn(message);
            throw new BadRequestException(message);
        }
        for (AlarmCallbackConfiguration configuration : callConfigurations) {
            AlarmCallback alarmCallback = alarmCallbackFactory.create(configuration);
            alarmCallback.call(stream, checkResult);
        }
    } catch (AlarmCallbackException | ClassNotFoundException | AlarmCallbackConfigurationException e) {
        throw new InternalServerErrorException(e.getMessage(), e);
    }
}
Also used : AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 4 with AlarmCallbackConfigurationException

use of org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException in project graylog2-server by Graylog2.

the class StreamAlarmCallbackResource method update.

@PUT
@Path("/{alarmCallbackId}")
@Timed
@ApiOperation(value = "Update an alarm callback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_UPDATE)
public void update(@ApiParam(name = "streamid", value = "The stream id this alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "alarmCallbackId", required = true) @PathParam("alarmCallbackId") String alarmCallbackId, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest alarmCallbackRequest) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    final AlarmCallbackConfiguration callbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
    if (callbackConfiguration == null) {
        throw new NotFoundException("Unable to find alarm callback configuration " + alarmCallbackId);
    }
    final Map<String, Object> configuration = convertConfigurationValues(alarmCallbackRequest);
    final AlarmCallbackConfiguration updatedConfig = ((AlarmCallbackConfigurationImpl) callbackConfiguration).toBuilder().setTitle(alarmCallbackRequest.title()).setConfiguration(configuration).build();
    try {
        alarmCallbackFactory.create(updatedConfig).checkConfiguration();
        alarmCallbackConfigurationService.save(updatedConfig);
    } 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);
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) 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)

Example 5 with AlarmCallbackConfigurationException

use of org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException in project graylog2-server by Graylog2.

the class AlarmCallbackFactory method create.

public AlarmCallback create(AlarmCallbackConfiguration configuration) throws ClassNotFoundException, AlarmCallbackConfigurationException {
    AlarmCallback alarmCallback = create(configuration.getType());
    alarmCallback.initialize(new Configuration(configuration.getConfiguration()));
    return alarmCallback;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback)

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