Search in sources :

Example 1 with AlertConditionSummary

use of org.graylog2.rest.models.streams.alerts.AlertConditionSummary 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());
}
Also used : AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Stream(org.graylog2.plugin.streams.Stream) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with AlertConditionSummary

use of org.graylog2.rest.models.streams.alerts.AlertConditionSummary 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);
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) AlertService(org.graylog2.alerts.AlertService) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) AlertConditionSummary(org.graylog2.rest.models.streams.alerts.AlertConditionSummary) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Map(java.util.Map) AuditEvent(org.graylog2.audit.jersey.AuditEvent) BadRequestException(javax.ws.rs.BadRequestException) Api(io.swagger.annotations.Api) URI(java.net.URI) NotFoundException(org.graylog2.database.NotFoundException) DELETE(javax.ws.rs.DELETE) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) POST(javax.ws.rs.POST) ConfigurationMapConverter(org.graylog2.utilities.ConfigurationMapConverter) ImmutableMap(com.google.common.collect.ImmutableMap) AlertConditionListSummary(org.graylog2.rest.models.streams.alerts.AlertConditionListSummary) RestResource(org.graylog2.shared.rest.resources.RestResource) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Response(javax.ws.rs.core.Response) Stream(org.graylog2.plugin.streams.Stream) ApiResponse(io.swagger.annotations.ApiResponse) AuditEventTypes(org.graylog2.audit.AuditEventTypes) ValidationException(org.graylog2.plugin.database.ValidationException) RestPermissions(org.graylog2.shared.security.RestPermissions) StreamService(org.graylog2.streams.StreamService) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) CreateConditionRequest(org.graylog2.rest.models.streams.alerts.requests.CreateConditionRequest) PUT(javax.ws.rs.PUT) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Stream(org.graylog2.plugin.streams.Stream) AlertConditionSummary(org.graylog2.rest.models.streams.alerts.AlertConditionSummary) 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)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)2 Stream (org.graylog2.plugin.streams.Stream)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 URI (java.net.URI)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Valid (javax.validation.Valid)1 NotNull (javax.validation.constraints.NotNull)1 BadRequestException (javax.ws.rs.BadRequestException)1