use of org.graylog2.alarmcallbacks.AlarmCallbackConfiguration 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;
}
use of org.graylog2.alarmcallbacks.AlarmCallbackConfiguration in project graylog2-server by Graylog2.
the class V20161125142400_EmailAlarmCallbackMigration method migrateStream.
private Optional<String> migrateStream(Stream stream) {
final Map<String, Object> defaultConfig = this.getDefaultEmailAlarmCallbackConfig();
LOG.debug("Creating email alarm callback for stream <" + stream.getId() + ">");
final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackService.create(stream.getId(), CreateAlarmCallbackRequest.create(EmailAlarmCallback.class.getCanonicalName(), "Email Alert Notification", defaultConfig), "local:admin");
try {
final String callbackId = this.alarmCallbackService.save(alarmCallbackConfiguration);
LOG.debug("Successfully created email alarm callback <" + callbackId + "> for stream <" + stream.getId() + ">.");
return Optional.of(callbackId);
} catch (ValidationException e) {
LOG.error("Unable to create email alarm callback for stream <" + stream.getId() + ">: ", e);
}
return Optional.empty();
}
use of org.graylog2.alarmcallbacks.AlarmCallbackConfiguration in project graylog2-server by Graylog2.
the class V20161125161400_AlertReceiversMigration method migrateStream.
private Optional<String> migrateStream(Stream stream) {
final List<AlarmCallbackConfiguration> alarmCallbacks = alarmCallbackService.getForStream(stream);
final List<Optional<String>> updatedConfigurations = alarmCallbacks.stream().filter(callbackConfiguration -> callbackConfiguration.getType().equals(EmailAlarmCallback.class.getCanonicalName())).map(callbackConfiguration -> this.updateConfiguration(stream, callbackConfiguration)).collect(Collectors.toList());
if (!updatedConfigurations.stream().allMatch(Optional::isPresent)) {
final long errors = updatedConfigurations.stream().filter(streamId -> !streamId.isPresent()).count();
LOG.error("Failed moving alert receivers in " + errors + " email alarm callbacks.");
return Optional.empty();
}
this.dbCollection.update(new BasicDBObject("_id", new ObjectId(stream.getId())), new BasicDBObject("$unset", new BasicDBObject(StreamImpl.FIELD_ALERT_RECEIVERS, "")));
LOG.debug("Successfully removed alert receivers from stream <" + stream.getId() + ">.");
return Optional.of(updatedConfigurations.stream().map(Optional::get).collect(Collectors.joining(", ")));
}
use of org.graylog2.alarmcallbacks.AlarmCallbackConfiguration in project graylog2-server by Graylog2.
the class AlarmCallbacksResource method test.
@POST
@Timed
@Path("/{alarmCallbackId}/test")
@ApiOperation(value = "Send a test alert for a given alarm callback")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Alarm callback not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 500, message = "Error while testing alarm callback") })
@NoAuditEvent("only used to test alert notifications")
public Response test(@ApiParam(name = "alarmCallbackId", value = "The alarm callback id to send a test alert for.", required = true) @PathParam("alarmCallbackId") String alarmCallbackId) throws TransportConfigurationException, EmailException, NotFoundException {
final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
final String streamId = alarmCallbackConfiguration.getStreamId();
checkPermission(RestPermissions.STREAMS_EDIT, streamId);
final Stream stream = streamService.load(streamId);
final DummyAlertCondition testAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
try {
AbstractAlertCondition.CheckResult checkResult = testAlertCondition.runCheck();
AlarmCallback alarmCallback = alarmCallbackFactory.create(alarmCallbackConfiguration);
alarmCallback.call(stream, checkResult);
} catch (Exception e) {
throw new InternalServerErrorException(e.getMessage(), e);
}
return Response.ok().build();
}
use of org.graylog2.alarmcallbacks.AlarmCallbackConfiguration in project graylog2-server by Graylog2.
the class StreamAlarmCallbackResource method get.
@GET
@Timed
@ApiOperation(value = "Get a list of all alarm callbacks for this stream")
@Produces(MediaType.APPLICATION_JSON)
public AlarmCallbackListSummary get(@ApiParam(name = "streamid", value = "The id of the stream whose alarm callbacks we want.", required = true) @PathParam("streamid") String streamid) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamid);
final Stream stream = streamService.load(streamid);
final List<AlarmCallbackSummary> alarmCallbacks = Lists.newArrayList();
for (AlarmCallbackConfiguration callback : alarmCallbackConfigurationService.getForStream(stream)) {
alarmCallbacks.add(AlarmCallbackSummary.create(callback.getId(), callback.getStreamId(), callback.getType(), callback.getTitle(), callback.getConfiguration(), callback.getCreatedAt(), callback.getCreatorUserId()));
}
return AlarmCallbackListSummary.create(alarmCallbacks);
}
Aggregations