Search in sources :

Example 86 with AuditEvent

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

the class StreamRuleResource method delete.

@DELETE
@Path("/{streamRuleId}")
@Timed
@ApiOperation(value = "Delete a stream rule")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream rule not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.STREAM_RULE_DELETE)
public void delete(@ApiParam(name = "streamid", value = "The stream id this new rule belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "streamRuleId", required = true) @PathParam("streamRuleId") @NotEmpty String streamRuleId) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    checkNotDefaultStream(streamid, "Cannot delete stream rule from default stream.");
    final StreamRule streamRule = streamRuleService.load(streamRuleId);
    if (streamRule.getStreamId().equals(streamid)) {
        streamRuleService.destroy(streamRule);
        clusterEventBus.post(StreamsChangedEvent.create(streamid));
    } else {
        throw new NotFoundException("Couldn't delete stream rule " + streamRuleId + "in stream " + streamid);
    }
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) NotFoundException(org.graylog2.database.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 87 with AuditEvent

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

the class ClusterConfigResource method update.

@PUT
@Timed
@Path("{configClass}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update configuration in database")
@RequiresPermissions({ RestPermissions.CLUSTER_CONFIG_ENTRY_CREATE, RestPermissions.CLUSTER_CONFIG_ENTRY_EDIT })
@AuditEvent(type = AuditEventTypes.CLUSTER_CONFIGURATION_UPDATE)
public Response update(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass, @ApiParam(name = "body", value = "The payload of the cluster configuration", required = true) @NotNull InputStream body) throws IOException {
    final Class<?> cls = classFromName(configClass);
    if (cls == null) {
        throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\"");
    }
    final Object o;
    try {
        o = objectMapper.readValue(body, cls);
    } catch (Exception e) {
        final String msg = "Couldn't parse cluster configuration \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new BadRequestException(msg);
    }
    try {
        clusterConfigService.write(o);
    } catch (Exception e) {
        final String msg = "Couldn't write cluster config \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new InternalServerErrorException(msg, e);
    }
    return Response.accepted(o).build();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IOException(java.io.IOException) NotFoundException(javax.ws.rs.NotFoundException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 88 with AuditEvent

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

the class DeflectorResource method deprecatedCycle.

@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
@Deprecated
public void deprecatedCycle() {
    final IndexSet indexSet = indexSetRegistry.getDefault();
    checkCycle(indexSet);
    final String msg = "Cycling deflector for default index set <" + indexSet.getConfig().id() + ">. Reason: REST request.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, DeflectorResource.class));
    indexSet.cycle();
}
Also used : Activity(org.graylog2.shared.system.activities.Activity) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) RestrictToMaster(org.graylog2.shared.security.RestrictToMaster)

Example 89 with AuditEvent

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

the class GettingStartedResource method dismissGettingStarted.

@POST
@Path("dismiss")
@ApiOperation("Dismiss auto-showing getting started guide for this version")
@AuditEvent(type = AuditEventTypes.GETTING_STARTED_GUIDE_OPT_OUT_CREATE)
public void dismissGettingStarted() {
    final GettingStartedState gettingStartedState = clusterConfigService.getOrDefault(GettingStartedState.class, GettingStartedState.create(Sets.<String>newHashSet()));
    gettingStartedState.dismissedInVersions().add(currentMinorVersionString());
    clusterConfigService.write(gettingStartedState);
}
Also used : GettingStartedState(org.graylog2.gettingstarted.GettingStartedState) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 90 with AuditEvent

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

the class GrokResource method bulkUpdatePatternsFromTextFile.

@POST
@Consumes(MediaType.TEXT_PLAIN)
@Timed
@ApiOperation("Add a list of new patterns")
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_IMPORT_CREATE)
public Response bulkUpdatePatternsFromTextFile(@ApiParam(name = "patterns", required = true) @NotNull InputStream patternsFile, @ApiParam(name = "replace", value = "Replace all patterns with the new ones.") @QueryParam("replace") @DefaultValue("false") boolean replace) throws ValidationException, IOException {
    checkPermission(RestPermissions.INPUTS_CREATE);
    final List<GrokPattern> grokPatterns = readGrokPatterns(patternsFile);
    if (!grokPatterns.isEmpty()) {
        final Set<String> updatedPatternNames = Sets.newHashSetWithExpectedSize(grokPatterns.size());
        for (final GrokPattern pattern : grokPatterns) {
            updatedPatternNames.add(pattern.name());
            if (!grokPatternService.validate(pattern)) {
                throw new ValidationException("Invalid pattern " + pattern + ". Did not save any patterns.");
            }
        }
        grokPatternService.saveAll(grokPatterns, replace);
        clusterBus.post(GrokPatternsChangedEvent.create(Collections.emptySet(), updatedPatternNames));
    }
    return Response.accepted().build();
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) GrokPattern(org.graylog2.grok.GrokPattern) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Aggregations

AuditEvent (org.graylog2.audit.jersey.AuditEvent)93 ApiOperation (io.swagger.annotations.ApiOperation)92 Timed (com.codahale.metrics.annotation.Timed)76 Path (javax.ws.rs.Path)70 ApiResponses (io.swagger.annotations.ApiResponses)56 PUT (javax.ws.rs.PUT)36 Produces (javax.ws.rs.Produces)34 POST (javax.ws.rs.POST)33 BadRequestException (javax.ws.rs.BadRequestException)31 Consumes (javax.ws.rs.Consumes)29 DELETE (javax.ws.rs.DELETE)26 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)22 URI (java.net.URI)19 Stream (org.graylog2.plugin.streams.Stream)16 NotFoundException (javax.ws.rs.NotFoundException)15 NotFoundException (org.graylog2.database.NotFoundException)14 ValidationException (org.graylog2.plugin.database.ValidationException)13 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)12 Dashboard (org.graylog2.dashboards.Dashboard)9 Input (org.graylog2.inputs.Input)9