use of org.graylog2.rest.models.streams.alerts.requests.CreateConditionRequest in project graylog2-server by Graylog2.
the class StreamAlertConditionResource method update.
@PUT
@Timed
@Path("{conditionId}")
@ApiOperation(value = "Modify an alert condition")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.ALERT_CONDITION_UPDATE)
public void update(@ApiParam(name = "streamId", value = "The stream id the alert condition belongs to.", required = true) @PathParam("streamId") String streamid, @ApiParam(name = "conditionId", value = "The alert condition id.", required = true) @PathParam("conditionId") String conditionid, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateConditionRequest ccr) throws NotFoundException, ValidationException {
checkPermission(RestPermissions.STREAMS_EDIT, streamid);
final Stream stream = streamService.load(streamid);
AlertCondition alertCondition = streamService.getAlertCondition(stream, conditionid);
try {
final AlertCondition updatedCondition = alertService.updateFromRequest(alertCondition, convertConfigurationInRequest(ccr));
streamService.updateAlertCondition(stream, updatedCondition);
} catch (ConfigurationException e) {
throw new BadRequestException("Invalid alert condition parameters", e);
}
}
use of org.graylog2.rest.models.streams.alerts.requests.CreateConditionRequest in project graylog2-server by Graylog2.
the class StreamAlertConditionResource method convertConfigurationInRequest.
private CreateConditionRequest convertConfigurationInRequest(final CreateConditionRequest request) {
final AlertCondition.Factory factory = alertConditionMap.get(request.type());
if (factory == null) {
throw new BadRequestException("Unable to load alert condition of type " + request.type());
}
final ConfigurationRequest requestedConfiguration = factory.config().getRequestedConfiguration();
// coerce the configuration to their correct types according to the condition's requested config
final Map<String, Object> parameters;
try {
parameters = ConfigurationMapConverter.convertValues(request.parameters(), requestedConfiguration);
} catch (ValidationException e) {
throw new BadRequestException("Invalid alert condition parameters", e);
}
return request.toBuilder().setParameters(parameters).build();
}
use of org.graylog2.rest.models.streams.alerts.requests.CreateConditionRequest 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);
}
}
Aggregations