use of org.graylog2.rest.models.streams.alerts.AlertSummary in project graylog2-server by Graylog2.
the class StreamAlertResource method list.
@GET
@Timed
@ApiOperation(value = "Get the most recent alarms of this stream.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary list(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "since", value = "Optional parameter to define a lower date boundary. (UNIX timestamp)") @QueryParam("since") @DefaultValue("0") @Min(0) int sinceTs, @ApiParam(name = "limit", value = "Maximum number of alerts to return.") @QueryParam("limit") @DefaultValue("300") @Min(1) int limit) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamId);
final DateTime since = new DateTime(sinceTs * 1000L, DateTimeZone.UTC);
final Stream stream = streamService.load(streamId);
final List<AlertSummary> conditions = toSummaryList(alertService.loadRecentOfStream(stream.getId(), since, limit));
return AlertListSummary.create(alertService.totalCountForStream(streamId), conditions);
}
use of org.graylog2.rest.models.streams.alerts.AlertSummary in project graylog2-server by Graylog2.
the class StreamAlertResource method listPaginated.
@GET
@Timed
@Path("paginated")
@ApiOperation(value = "Get the alarms of this stream, filtered by specifying limit and offset parameters.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary listPaginated(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("300") int limit) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamId);
final Stream stream = streamService.load(streamId);
final List<AlertSummary> conditions = toSummaryList(alertService.listForStreamId(stream.getId(), skip, limit));
return AlertListSummary.create(alertService.totalCountForStream(streamId), conditions);
}
use of org.graylog2.rest.models.streams.alerts.AlertSummary in project graylog2-server by Graylog2.
the class AlertResource method listPaginated.
@GET
@Timed
@Path("paginated")
@ApiOperation(value = "Get alarms of all streams, filtered by specifying limit and offset parameters.")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary listPaginated(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("300") int limit, @ApiParam(name = "state", value = "Alert state (resolved/unresolved)", required = false) @QueryParam("state") String state) throws NotFoundException {
final List<String> allowedStreamIds = getAllowedStreamIds();
AlertState alertState;
try {
alertState = AlertState.fromString(state);
} catch (IllegalArgumentException e) {
alertState = AlertState.ANY;
}
final Stream<Alert> alertsStream = alertService.listForStreamIds(allowedStreamIds, alertState, skip, limit).stream();
final List<AlertSummary> alerts = getAlertSummaries(alertsStream);
return AlertListSummary.create(alertService.totalCountForStreams(allowedStreamIds, alertState), alerts);
}
use of org.graylog2.rest.models.streams.alerts.AlertSummary in project graylog2-server by Graylog2.
the class AlertResource method listRecent.
@GET
@Timed
@ApiOperation(value = "Get the most recent alarms of all streams.")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertListSummary listRecent(@ApiParam(name = "since", value = "Optional parameter to define a lower date boundary. (UNIX timestamp)", required = false) @QueryParam("since") @DefaultValue("0") @Min(0) int sinceTs, @ApiParam(name = "limit", value = "Maximum number of alerts to return.", required = false) @QueryParam("limit") @DefaultValue("300") @Min(1) int limit) throws NotFoundException {
final DateTime since = new DateTime(sinceTs * 1000L, DateTimeZone.UTC);
final List<AlertSummary> alerts = getAlertSummaries(alertService.loadRecentOfStreams(getAllowedStreamIds(), since, limit).stream());
return AlertListSummary.create(alerts.size(), alerts);
}
use of org.graylog2.rest.models.streams.alerts.AlertSummary in project graylog2-server by Graylog2.
the class AlertResource method get.
@GET
@Timed
@Path("{alertId}")
@ApiOperation(value = "Get an alert by ID.")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Alert not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
public AlertSummary get(@ApiParam(name = "alertId", value = "The alert ID to retrieve.", required = true) @PathParam("alertId") String alertId) throws NotFoundException {
final Alert alert = alertService.load(alertId, "");
checkPermission(STREAMS_READ, alert.getStreamId());
return AlertSummary.create(alert.getId(), alert.getConditionId(), alert.getStreamId(), alert.getDescription(), alert.getConditionParameters(), alert.getTriggeredAt(), alert.getResolvedAt(), alert.isInterval());
}
Aggregations