Search in sources :

Example 71 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class IndicesResource method indexSetClosed.

@GET
@Timed
@Path("/{indexSetId}/closed")
@ApiOperation(value = "Get a list of closed indices that can be reopened.")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetClosed(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> closedIndices = indices.getClosedIndices(indexSet).stream().filter((indexName) -> isPermitted(RestPermissions.INDICES_READ, indexName) && indexSetRegistry.isManagedIndex(indexName)).collect(Collectors.toSet());
    return ClosedIndices.create(closedIndices, closedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) IndexStats(org.graylog2.rest.models.system.indexer.responses.IndexStats) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Set(java.util.Set) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) AuditEventTypes(org.graylog2.audit.AuditEventTypes) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) Inject(javax.inject.Inject) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ImmutableList(com.google.common.collect.ImmutableList) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Cluster(org.graylog2.indexer.cluster.Cluster) ForbiddenException(javax.ws.rs.ForbiddenException) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) RestResource(org.graylog2.shared.rest.resources.RestResource) ApiResponse(io.swagger.annotations.ApiResponse) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) 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)

Example 72 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class IndicesResource method indexSetReopened.

@GET
@Timed
@Path("/{indexSetId}/reopened")
@ApiOperation(value = "Get a list of reopened indices, which will not be cleaned by retention cleaning")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetReopened(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> reopenedIndices = indices.getReopenedIndices(indexSet).stream().filter((indexName) -> isPermitted(RestPermissions.INDICES_READ, indexName) && indexSetRegistry.isManagedIndex(indexName)).collect(Collectors.toSet());
    return ClosedIndices.create(reopenedIndices, reopenedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) IndexStats(org.graylog2.rest.models.system.indexer.responses.IndexStats) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Set(java.util.Set) IndexStatistics(org.graylog2.indexer.indices.IndexStatistics) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) AuditEventTypes(org.graylog2.audit.AuditEventTypes) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) Inject(javax.inject.Inject) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ImmutableList(com.google.common.collect.ImmutableList) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Cluster(org.graylog2.indexer.cluster.Cluster) ForbiddenException(javax.ws.rs.ForbiddenException) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) RestResource(org.graylog2.shared.rest.resources.RestResource) ApiResponse(io.swagger.annotations.ApiResponse) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) 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)

Example 73 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class LoggersResource method loggers.

@GET
@Timed
@ApiOperation(value = "List all loggers and their current levels")
@Produces(MediaType.APPLICATION_JSON)
public LoggersSummary loggers() {
    final Collection<LoggerConfig> loggerConfigs = getLoggerConfigs();
    final Map<String, SingleLoggerSummary> loggers = Maps.newHashMapWithExpectedSize(loggerConfigs.size());
    for (LoggerConfig config : loggerConfigs) {
        if (!isPermitted(RestPermissions.LOGGERS_READ, config.getName())) {
            continue;
        }
        final Level level = config.getLevel();
        loggers.put(config.getName(), SingleLoggerSummary.create(level.toString().toLowerCase(Locale.ENGLISH), level.intLevel()));
    }
    return LoggersSummary.create(loggers);
}
Also used : SingleLoggerSummary(org.graylog2.rest.models.system.loggers.responses.SingleLoggerSummary) Level(org.apache.logging.log4j.Level) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 74 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class LoggersResource method setSingleLoggerLevel.

@PUT
@Timed
@ApiOperation(value = "Set the loglevel of a single logger", notes = "Provided level is falling back to DEBUG if it does not exist")
@Path("/{loggerName}/level/{level}")
@AuditEvent(type = AuditEventTypes.LOG_LEVEL_UPDATE)
public void setSingleLoggerLevel(@ApiParam(name = "loggerName", required = true) @PathParam("loggerName") @NotEmpty String loggerName, @ApiParam(name = "level", required = true) @NotEmpty @PathParam("level") String level) {
    checkPermission(RestPermissions.LOGGERS_EDIT, loggerName);
    final Level newLevel = Level.toLevel(level.toUpperCase(Locale.ENGLISH));
    setLoggerLevel(loggerName, newLevel);
    LOG.debug("Successfully set log level for logger \"{}\" to \"{}\"", loggerName, newLevel);
}
Also used : Level(org.apache.logging.log4j.Level) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 75 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class LoggersResource method subsystems.

@GET
@Timed
@Path("/subsystems")
@ApiOperation(value = "List all logger subsystems and their current levels")
@Produces(MediaType.APPLICATION_JSON)
public SubsystemSummary subsystems() {
    final Map<String, SingleSubsystemSummary> subsystems = Maps.newHashMap();
    for (Map.Entry<String, Subsystem> subsystem : SUBSYSTEMS.entrySet()) {
        if (!isPermitted(RestPermissions.LOGGERS_READSUBSYSTEM, subsystem.getKey())) {
            continue;
        }
        try {
            final String category = subsystem.getValue().getCategory();
            final Level level = getLoggerLevel(category);
            subsystems.put(subsystem.getKey(), SingleSubsystemSummary.create(subsystem.getValue().getTitle(), subsystem.getValue().getCategory(), subsystem.getValue().getDescription(), level.toString().toLowerCase(Locale.ENGLISH), level.intLevel()));
        } catch (Exception e) {
            LOG.error("Error while listing logger subsystem.", e);
        }
    }
    return SubsystemSummary.create(subsystems);
}
Also used : SingleSubsystemSummary(org.graylog2.rest.models.system.loggers.responses.SingleSubsystemSummary) Level(org.apache.logging.log4j.Level) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) 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)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)414 ApiOperation (io.swagger.annotations.ApiOperation)255 ApiResponses (io.swagger.annotations.ApiResponses)196 Path (javax.ws.rs.Path)169 Counted (com.codahale.metrics.annotation.Counted)128 Produces (javax.ws.rs.Produces)112 GET (javax.ws.rs.GET)107 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)105 AuditEvent (org.graylog2.audit.jersey.AuditEvent)82 POST (javax.ws.rs.POST)78 Consumes (javax.ws.rs.Consumes)58 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)53 NotFoundException (javax.ws.rs.NotFoundException)52 PUT (javax.ws.rs.PUT)52 URI (java.net.URI)45 DELETE (javax.ws.rs.DELETE)45 BadRequestException (javax.ws.rs.BadRequestException)41 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)41 HashMap (java.util.HashMap)34 Event (keywhiz.log.Event)29