Search in sources :

Example 91 with Timed

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

the class ClusterResource method nodes.

@GET
@Timed
@Path("/nodes")
@ApiOperation(value = "List all active nodes in this cluster.")
public NodeSummaryList nodes() {
    final Map<String, Node> nodes = nodeService.allActive(Node.Type.SERVER);
    final List<NodeSummary> nodeList = new ArrayList<>(nodes.size());
    for (Node node : nodes.values()) {
        nodeList.add(nodeSummary(node));
    }
    return NodeSummaryList.create(nodeList);
}
Also used : NodeSummary(org.graylog2.rest.models.system.cluster.responses.NodeSummary) Node(org.graylog2.cluster.Node) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 92 with Timed

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

the class DeflectorResource method cycle.

@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index in index set")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/{indexSetId}/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
public void cycle(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    checkCycle(indexSet);
    final String msg = "Cycling deflector for index set <" + indexSetId + ">. 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 93 with Timed

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

the class GrokResource method bulkUpdatePatterns.

@PUT
@Timed
@ApiOperation("Add a list of new patterns")
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_IMPORT_CREATE)
public Response bulkUpdatePatterns(@ApiParam(name = "patterns", required = true) @NotNull GrokPatternList patternList, @ApiParam(name = "replace", value = "Replace all patterns with the new ones.") @QueryParam("replace") @DefaultValue("false") boolean replace) throws ValidationException {
    checkPermission(RestPermissions.INPUTS_CREATE);
    final Set<String> updatedPatternNames = Sets.newHashSet();
    for (final GrokPattern pattern : patternList.patterns()) {
        updatedPatternNames.add(pattern.name());
        if (!grokPatternService.validate(pattern)) {
            throw new ValidationException("Invalid pattern " + pattern + ". Did not save any patterns.");
        }
    }
    grokPatternService.saveAll(patternList.patterns(), 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) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 94 with Timed

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

the class GrokResource method removePattern.

@DELETE
@Timed
@Path("/{patternId}")
@ApiOperation("Remove an existing pattern by id")
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_DELETE)
public void removePattern(@ApiParam(name = "patternId", required = true) @PathParam("patternId") String patternId) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT);
    final GrokPattern pattern = grokPatternService.load(patternId);
    clusterBus.post(GrokPatternsChangedEvent.create(Sets.newHashSet(pattern.name()), Collections.emptySet()));
    if (grokPatternService.delete(patternId) == 0) {
        throw new javax.ws.rs.NotFoundException("Couldn't remove Grok pattern with ID " + patternId);
    }
}
Also used : GrokPattern(org.graylog2.grok.GrokPattern) 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)

Example 95 with Timed

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

the class GrokResource method createPattern.

@POST
@Timed
@ApiOperation(value = "Add a new named pattern", response = GrokPattern.class)
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_CREATE)
public Response createPattern(@ApiParam(name = "pattern", required = true) @Valid @NotNull GrokPattern pattern) throws ValidationException {
    checkPermission(RestPermissions.INPUTS_CREATE);
    // remove the ID from the pattern, this is only used to create new patterns
    final GrokPattern newPattern = grokPatternService.save(pattern.toBuilder().id(null).build());
    clusterBus.post(GrokPatternsChangedEvent.create(Collections.emptySet(), Sets.newHashSet(newPattern.name())));
    final URI patternUri = getUriBuilderToSelf().path(GrokResource.class, "listPattern").build(newPattern.id());
    return Response.created(patternUri).entity(newPattern).build();
}
Also used : GrokPattern(org.graylog2.grok.GrokPattern) URI(java.net.URI) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

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