use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamAlertConditionResource method list.
@GET
@Timed
@ApiOperation(value = "Get all alert conditions of this stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertConditionListSummary list(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamid) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamid);
final Stream stream = streamService.load(streamid);
final List<AlertCondition> alertConditions = streamService.getAlertConditions(stream);
final List<AlertConditionSummary> conditionSummaries = alertConditions.stream().map((condition) -> AlertConditionSummary.create(condition.getId(), condition.getType(), condition.getCreatorUserId(), condition.getCreatedAt().toDate(), condition.getParameters(), alertService.inGracePeriod(condition), condition.getTitle())).collect(Collectors.toList());
return AlertConditionListSummary.create(conditionSummaries);
}
use of org.graylog2.database.NotFoundException 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);
}
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamOutputResource method add.
@POST
@Timed
@ApiOperation(value = "Associate outputs with a stream")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid output specification in input.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_CREATE)
public Response add(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) @Valid @NotNull AddOutputRequest aor) throws ValidationException, NotFoundException {
final Stream stream = streamService.load(streamid);
for (String outputId : aor.outputs()) {
final Output output = outputService.load(outputId);
streamService.addOutput(stream, output);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
return Response.accepted().build();
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamOutputResource method remove.
@DELETE
@Path("/{outputId}")
@Timed
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_DELETE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete output of a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_DELETE)
public void remove(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws NotFoundException {
final Stream stream = streamService.load(streamid);
final Output output = outputService.load(outputId);
streamService.removeOutput(stream, output);
outputRegistry.removeOutput(output);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
use of org.graylog2.database.NotFoundException 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