Search in sources :

Example 1 with AlertSummary

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);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) DateTime(org.joda.time.DateTime) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with AlertSummary

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);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with AlertSummary

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);
}
Also used : Alert(org.graylog2.alerts.Alert) AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) AlertState(org.graylog2.alerts.Alert.AlertState) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with AlertSummary

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);
}
Also used : AlertSummary(org.graylog2.rest.models.streams.alerts.AlertSummary) DateTime(org.joda.time.DateTime) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with AlertSummary

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());
}
Also used : Alert(org.graylog2.alerts.Alert) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 GET (javax.ws.rs.GET)5 AlertSummary (org.graylog2.rest.models.streams.alerts.AlertSummary)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)2 Alert (org.graylog2.alerts.Alert)2 Stream (org.graylog2.plugin.streams.Stream)2 DateTime (org.joda.time.DateTime)2 AlertState (org.graylog2.alerts.Alert.AlertState)1