use of org.graylog2.database.NotFoundException 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.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamAlertConditionResource method get.
@GET
@Timed
@Path("{conditionId}")
@ApiOperation(value = "Get an alert condition")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.ALERT_CONDITION_DELETE)
public AlertConditionSummary get(@ApiParam(name = "streamId", value = "The stream id this alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "conditionId", value = "The alert condition id to be fetched", required = true) @PathParam("conditionId") String conditionId) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamId);
final Stream stream = streamService.load(streamId);
final AlertCondition condition = streamService.getAlertCondition(stream, conditionId);
return AlertConditionSummary.create(condition.getId(), condition.getType(), condition.getCreatorUserId(), condition.getCreatedAt().toDate(), condition.getParameters(), alertService.inGracePeriod(condition), condition.getTitle());
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamAlertConditionResource method delete.
@DELETE
@Timed
@Path("{conditionId}")
@ApiOperation(value = "Delete an alert condition")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.ALERT_CONDITION_DELETE)
public void delete(@ApiParam(name = "streamId", value = "The stream id this alert condition belongs to.", required = true) @PathParam("streamId") String streamid, @ApiParam(name = "conditionId", value = "The alert condition id to be deleted", required = true) @PathParam("conditionId") String conditionId) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamid);
final Stream stream = streamService.load(streamid);
streamService.removeAlertCondition(stream, conditionId);
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamAlertResource method removeReceiver.
@DELETE
@Timed
@Path("receivers")
@ApiOperation(value = "Remove an alert receiver")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 400, message = "Stream has no email alarm callbacks.") })
@AuditEvent(type = AuditEventTypes.ALERT_RECEIVER_DELETE)
@Deprecated
public void removeReceiver(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "entity", value = "Name/ID of user or email address to remove from alert receivers.", required = true) @QueryParam("entity") String entity, @ApiParam(name = "type", value = "Type: users or emails", required = true) @QueryParam("type") String type) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_EDIT, streamId);
if (!"users".equals(type) && !"emails".equals(type)) {
final String msg = "No such type: [" + type + "]";
LOG.warn(msg);
throw new BadRequestException(msg);
}
final Stream stream = streamService.load(streamId);
streamService.removeAlertReceiver(stream, type, entity);
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamAlertResource method checkConditions.
@GET
@Timed
@Path("check")
@ApiOperation(value = "Check for triggered alert conditions of this streams. Results cached for " + REST_CHECK_CACHE_SECONDS + " seconds.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public Map<String, Object> checkConditions(@ApiParam(name = "streamId", value = "The ID of the stream to check.", required = true) @PathParam("streamId") String streamId) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamId);
final Stream stream = streamService.load(streamId);
final Map<String, Object> result;
try {
result = CACHE.get(CACHE_KEY_BASE + stream.getId(), () -> {
final List<AlertCondition> alertConditions = streamService.getAlertConditions(stream);
int triggered = 0;
final List<Map<String, Object>> results = new ArrayList<>(alertConditions.size());
for (AlertCondition alertCondition : alertConditions) {
final Map<String, Object> conditionResult = new HashMap<>();
conditionResult.put("condition", alertCondition);
final AlertCondition.CheckResult checkResult = alertCondition.runCheck();
conditionResult.put("triggered", checkResult.isTriggered());
if (checkResult.isTriggered()) {
triggered++;
conditionResult.put("alert_description", checkResult.getResultDescription());
}
results.add(conditionResult);
}
return ImmutableMap.of("results", results, "calculated_at", Tools.getISO8601String(Tools.nowUTC()), "total_triggered", triggered);
});
} catch (ExecutionException e) {
final Throwable rootCause = Throwables.getRootCause(e);
LOG.error("Could not check for alerts.", rootCause);
throw new InternalServerErrorException(rootCause);
}
return result;
}
Aggregations