Search in sources :

Example 26 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class MessageResource method parse.

@POST
@Path("/parse")
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Parse a raw message")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Specified codec does not exist."), @ApiResponse(code = 400, message = "Could not decode message.") })
@NoAuditEvent("only used to parse a test message")
public ResultMessage parse(@ApiParam(name = "JSON body", required = true) MessageParseRequest request) {
    Codec codec;
    try {
        final Configuration configuration = new Configuration(request.configuration());
        codec = codecFactory.create(request.codec(), configuration);
    } catch (IllegalArgumentException e) {
        throw new NotFoundException(e);
    }
    final ResolvableInetSocketAddress remoteAddress = ResolvableInetSocketAddress.wrap(new InetSocketAddress(request.remoteAddress(), 1234));
    final RawMessage rawMessage = new RawMessage(0, new UUID(), Tools.nowUTC(), remoteAddress, request.message().getBytes(StandardCharsets.UTF_8));
    final Message message = decodeMessage(codec, remoteAddress, rawMessage);
    return ResultMessage.createFromMessage(message);
}
Also used : Codec(org.graylog2.plugin.inputs.codecs.Codec) ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) Configuration(org.graylog2.plugin.configuration.Configuration) ResultMessage(org.graylog2.indexer.results.ResultMessage) RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) NotFoundException(javax.ws.rs.NotFoundException) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) RawMessage(org.graylog2.plugin.journal.RawMessage) UUID(com.eaio.uuid.UUID) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 27 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class ClusterLoadBalancerStatusResource method override.

@PUT
@Timed
@RequiresAuthentication
@RequiresPermissions(RestPermissions.LBSTATUS_CHANGE)
@ApiOperation(value = "Override load balancer status of this graylog-server node. Next lifecycle " + "change will override it again to its default. Set to ALIVE, DEAD, or THROTTLED.")
@Path("/override/{status}")
@NoAuditEvent("this is a proxy resource, the audit event will be emitted on the target node")
public void override(@ApiParam(name = "nodeId", value = "The id of the node whose LB status will be changed", required = true) @PathParam("nodeId") String nodeId, @ApiParam(name = "status") @PathParam("status") String status) throws IOException, NodeNotFoundException {
    final Node targetNode = nodeService.byNodeId(nodeId);
    RemoteLoadBalancerStatusResource remoteLoadBalancerStatusResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteLoadBalancerStatusResource.class);
    final Response response = remoteLoadBalancerStatusResource.override(status).execute();
    if (!response.isSuccessful()) {
        LOG.warn("Unable to override load balancer status on node {}: {}", nodeId, response.message());
        throw new WebApplicationException(response.message(), BAD_GATEWAY);
    }
}
Also used : Response(retrofit2.Response) WebApplicationException(javax.ws.rs.WebApplicationException) RemoteLoadBalancerStatusResource(org.graylog2.shared.rest.resources.system.RemoteLoadBalancerStatusResource) Node(org.graylog2.cluster.Node) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 28 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class AlarmCallbacksResource method test.

@POST
@Timed
@Path("/{alarmCallbackId}/test")
@ApiOperation(value = "Send a test alert for a given alarm callback")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Alarm callback not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 500, message = "Error while testing alarm callback") })
@NoAuditEvent("only used to test alert notifications")
public Response test(@ApiParam(name = "alarmCallbackId", value = "The alarm callback id to send a test alert for.", required = true) @PathParam("alarmCallbackId") String alarmCallbackId) throws TransportConfigurationException, EmailException, NotFoundException {
    final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
    final String streamId = alarmCallbackConfiguration.getStreamId();
    checkPermission(RestPermissions.STREAMS_EDIT, streamId);
    final Stream stream = streamService.load(streamId);
    final DummyAlertCondition testAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
    try {
        AbstractAlertCondition.CheckResult checkResult = testAlertCondition.runCheck();
        AlarmCallback alarmCallback = alarmCallbackFactory.create(alarmCallbackConfiguration);
        alarmCallback.call(stream, checkResult);
    } catch (Exception e) {
        throw new InternalServerErrorException(e.getMessage(), e);
    }
    return Response.ok().build();
}
Also used : InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) EmailAlarmCallback(org.graylog2.alarmcallbacks.EmailAlarmCallback) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) TransportConfigurationException(org.graylog2.plugin.alarms.transports.TransportConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) EmailException(org.apache.commons.mail.EmailException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 29 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class StreamAlertConditionResource method testNew.

@POST
@Path("test")
@Timed
@ApiOperation("Test new alert condition")
@NoAuditEvent("resource doesn't modify any data")
public Response testNew(@ApiParam(name = "streamId", value = "The stream ID this alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "Alert condition parameters", required = true) @Valid @NotNull CreateConditionRequest ccr) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamId);
    final Stream stream = streamService.load(streamId);
    try {
        final AlertCondition alertCondition = alertService.fromRequest(convertConfigurationInRequest(ccr), stream, getCurrentUser().getName());
        return Response.ok(testAlertCondition(alertCondition)).build();
    } catch (ConfigurationException e) {
        throw new BadRequestException("Invalid alert condition parameters", e);
    }
}
Also used : ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) BadRequestException(javax.ws.rs.BadRequestException) Stream(org.graylog2.plugin.streams.Stream) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 30 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class StreamAlertConditionResource method testExisting.

@POST
@Path("{conditionId}/test")
@Timed
@ApiOperation("Test existing alert condition")
@NoAuditEvent("resource doesn't modify any data")
public Response testExisting(@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_EDIT, streamId);
    final Stream stream = streamService.load(streamId);
    final AlertCondition alertCondition = streamService.getAlertCondition(stream, conditionId);
    final AlertConditionTestResponse testResultResponse = testAlertCondition(alertCondition);
    if (testResultResponse.error()) {
        return Response.status(400).entity(testResultResponse).build();
    } else {
        return Response.ok(testResultResponse).build();
    }
}
Also used : AlertConditionTestResponse(org.graylog2.rest.resources.streams.responses.AlertConditionTestResponse) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Stream(org.graylog2.plugin.streams.Stream) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)33 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)33 POST (javax.ws.rs.POST)30 Path (javax.ws.rs.Path)27 Timed (com.codahale.metrics.annotation.Timed)14 ApiResponses (io.swagger.annotations.ApiResponses)10 Produces (javax.ws.rs.Produces)10 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)10 BadRequestException (javax.ws.rs.BadRequestException)9 Consumes (javax.ws.rs.Consumes)6 Stream (org.graylog2.plugin.streams.Stream)6 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)5 PUT (javax.ws.rs.PUT)5 Search (org.graylog.plugins.views.search.Search)5 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)4 ValidationResult (org.graylog2.plugin.rest.ValidationResult)4 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3