Search in sources :

Example 6 with Sidecar

use of org.graylog.plugins.sidecar.rest.models.Sidecar in project graylog2-server by Graylog2.

the class AdministrationResource method administration.

@POST
@Timed
@ApiOperation(value = "Lists existing Sidecar registrations including compatible sidecars using pagination")
@RequiresPermissions({ SidecarRestPermissions.SIDECARS_READ, SidecarRestPermissions.COLLECTORS_READ, SidecarRestPermissions.CONFIGURATIONS_READ })
@NoAuditEvent("this is not changing any data")
public SidecarListResponse administration(@ApiParam(name = "JSON body", required = true) @Valid @NotNull AdministrationRequest request) {
    final String sort = Sidecar.FIELD_NODE_NAME;
    final String order = "asc";
    final String mappedQuery = sidecarStatusMapper.replaceStringStatusSearchQuery(request.query());
    SearchQuery searchQuery;
    try {
        searchQuery = searchQueryParser.parse(mappedQuery);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
    }
    final long total = sidecarService.count();
    final Optional<Predicate<Sidecar>> filters = administrationFiltersFactory.getFilters(request.filters());
    final List<Collector> collectors = getCollectors(request.filters());
    final PaginatedList<Sidecar> sidecars = sidecarService.findPaginated(searchQuery, filters.orElse(null), request.page(), request.perPage(), sort, order);
    final List<SidecarSummary> sidecarSummaries = sidecarService.toSummaryList(sidecars, activeSidecarFilter);
    final List<SidecarSummary> summariesWithCollectors = sidecarSummaries.stream().map(collector -> {
        final List<String> compatibleCollectors = collectors.stream().filter(c -> c.nodeOperatingSystem().equalsIgnoreCase(collector.nodeDetails().operatingSystem())).map(Collector::id).collect(Collectors.toList());
        return collector.toBuilder().collectors(compatibleCollectors).build();
    }).filter(collectorSummary -> !filters.isPresent() || collectorSummary.collectors().size() > 0).collect(Collectors.toList());
    return SidecarListResponse.create(request.query(), sidecars.pagination(), total, false, sort, order, summariesWithCollectors, request.filters());
}
Also used : SearchQuery(org.graylog2.search.SearchQuery) CollectorActions(org.graylog.plugins.sidecar.rest.models.CollectorActions) Produces(javax.ws.rs.Produces) SidecarService(org.graylog.plugins.sidecar.services.SidecarService) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) PaginatedList(org.graylog2.database.PaginatedList) AdministrationFilter(org.graylog.plugins.sidecar.filter.AdministrationFilter) MediaType(javax.ws.rs.core.MediaType) CollectorService(org.graylog.plugins.sidecar.services.CollectorService) SidecarConfiguration(org.graylog.plugins.sidecar.system.SidecarConfiguration) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) Map(java.util.Map) PluginRestResource(org.graylog2.plugin.rest.PluginRestResource) BadRequestException(javax.ws.rs.BadRequestException) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Predicate(java.util.function.Predicate) CollectorAction(org.graylog.plugins.sidecar.rest.models.CollectorAction) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) BulkActionRequest(org.graylog.plugins.sidecar.rest.requests.BulkActionRequest) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) SidecarSummary(org.graylog.plugins.sidecar.rest.models.SidecarSummary) Response(javax.ws.rs.core.Response) BulkActionsRequest(org.graylog.plugins.sidecar.rest.requests.BulkActionsRequest) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) ConfigurationService(org.graylog.plugins.sidecar.services.ConfigurationService) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar) SearchQueryParser(org.graylog2.search.SearchQueryParser) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ImmutableList(com.google.common.collect.ImmutableList) AdministrationFiltersFactory(org.graylog.plugins.sidecar.filter.AdministrationFiltersFactory) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) SidecarRestPermissions(org.graylog.plugins.sidecar.permissions.SidecarRestPermissions) SearchQuery(org.graylog2.search.SearchQuery) AdministrationRequest(org.graylog.plugins.sidecar.rest.requests.AdministrationRequest) POST(javax.ws.rs.POST) ActiveSidecarFilter(org.graylog.plugins.sidecar.filter.ActiveSidecarFilter) SidecarAuditEventTypes(org.graylog.plugins.sidecar.audit.SidecarAuditEventTypes) RestResource(org.graylog2.shared.rest.resources.RestResource) SidecarListResponse(org.graylog.plugins.sidecar.rest.responses.SidecarListResponse) ActionService(org.graylog.plugins.sidecar.services.ActionService) ApiResponse(io.swagger.annotations.ApiResponse) Collector(org.graylog.plugins.sidecar.rest.models.Collector) PUT(javax.ws.rs.PUT) SidecarStatusMapper(org.graylog.plugins.sidecar.mapper.SidecarStatusMapper) Predicate(java.util.function.Predicate) SidecarSummary(org.graylog.plugins.sidecar.rest.models.SidecarSummary) Collector(org.graylog.plugins.sidecar.rest.models.Collector) BadRequestException(javax.ws.rs.BadRequestException) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 7 with Sidecar

use of org.graylog.plugins.sidecar.rest.models.Sidecar in project graylog2-server by Graylog2.

the class SidecarResourceTest method getDummyCollectorList.

private List<Sidecar> getDummyCollectorList() {
    final Sidecar sidecar1 = getDummyCollector("collector1id");
    final Sidecar sidecar2 = getDummyCollector("collector2id");
    final Sidecar sidecar3 = getDummyCollector("collector3id");
    return Lists.newArrayList(sidecar1, sidecar2, sidecar3);
}
Also used : Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar)

Example 8 with Sidecar

use of org.graylog.plugins.sidecar.rest.models.Sidecar in project graylog2-server by Graylog2.

the class SidecarServiceImplTest method testFindById.

@Test
@MongoDBFixtures("collectorsMultipleDocuments.json")
public void testFindById() throws Exception {
    final String collector1id = "uniqueid1";
    final Sidecar sidecar = this.sidecarService.findByNodeId(collector1id);
    assertNotNull(sidecar);
    assertEquals(collector1id, sidecar.nodeId());
}
Also used : Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 9 with Sidecar

use of org.graylog.plugins.sidecar.rest.models.Sidecar in project graylog2-server by Graylog2.

the class SidecarService method assignConfiguration.

public Sidecar assignConfiguration(String collectorNodeId, List<ConfigurationAssignment> assignments) throws NotFoundException {
    Sidecar sidecar = findByNodeId(collectorNodeId);
    if (sidecar == null) {
        throw new NotFoundException("Couldn't find collector with ID " + collectorNodeId);
    }
    for (ConfigurationAssignment assignment : assignments) {
        Collector collector = collectorService.find(assignment.collectorId());
        if (collector == null) {
            throw new NotFoundException("Couldn't find collector with ID " + assignment.collectorId());
        }
        Configuration configuration = configurationService.find(assignment.configurationId());
        if (configuration == null) {
            throw new NotFoundException("Couldn't find configuration with ID " + assignment.configurationId());
        }
        if (!configuration.collectorId().equals(collector.id())) {
            throw new NotFoundException("Configuration doesn't match collector ID " + assignment.collectorId());
        }
    }
    Sidecar toSave = sidecar.toBuilder().assignments(assignments).build();
    return save(toSave);
}
Also used : ConfigurationAssignment(org.graylog.plugins.sidecar.rest.requests.ConfigurationAssignment) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) Collector(org.graylog.plugins.sidecar.rest.models.Collector) NotFoundException(org.graylog2.database.NotFoundException) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar)

Example 10 with Sidecar

use of org.graylog.plugins.sidecar.rest.models.Sidecar in project graylog2-server by Graylog2.

the class SidecarService method destroyExpired.

public int destroyExpired(Period period) {
    final DateTime threshold = DateTime.now(DateTimeZone.UTC).minus(period);
    int count;
    try (final Stream<Sidecar> collectorStream = streamAll()) {
        count = collectorStream.mapToInt(collector -> {
            if (collector.lastSeen().isBefore(threshold)) {
                return delete(collector.id());
            }
            return 0;
        }).sum();
    }
    return count;
}
Also used : DateTime(org.joda.time.DateTime) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar)

Aggregations

Sidecar (org.graylog.plugins.sidecar.rest.models.Sidecar)15 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)5 Path (javax.ws.rs.Path)4 SidecarSummary (org.graylog.plugins.sidecar.rest.models.SidecarSummary)4 Test (org.junit.Test)4 ApiResponses (io.swagger.annotations.ApiResponses)3 BadRequestException (javax.ws.rs.BadRequestException)3 GET (javax.ws.rs.GET)3 PUT (javax.ws.rs.PUT)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 ActiveSidecarFilter (org.graylog.plugins.sidecar.filter.ActiveSidecarFilter)3 CollectorAction (org.graylog.plugins.sidecar.rest.models.CollectorAction)3 CollectorActions (org.graylog.plugins.sidecar.rest.models.CollectorActions)3 Configuration (org.graylog.plugins.sidecar.rest.models.Configuration)3 ConfigurationAssignment (org.graylog.plugins.sidecar.rest.requests.ConfigurationAssignment)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 SearchQuery (org.graylog2.search.SearchQuery)3