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;
}
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;
}
}
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);
}
}
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);
}
}
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;
}
Aggregations