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());
}
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);
}
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());
}
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);
}
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;
}
Aggregations