Search in sources :

Example 16 with Collector

use of org.graylog.plugins.sidecar.rest.models.Collector 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 17 with Collector

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

the class SidecarCollectorFacade method decode.

private NativeEntity<Collector> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final Collector collector = Collector.builder().name(collectorEntity.name().asString(parameters)).serviceType(collectorEntity.serviceType().asString(parameters)).nodeOperatingSystem(collectorEntity.nodeOperatingSystem().asString(parameters)).executablePath(collectorEntity.executablePath().asString(parameters)).executeParameters(collectorEntity.executeParameters().asString(parameters)).validationParameters(collectorEntity.validationParameters().asString(parameters)).defaultTemplate(collectorEntity.defaultTemplate().asString(parameters)).build();
    final Collector savedCollector = collectorService.save(collector);
    return NativeEntity.create(entity.id(), savedCollector.id(), TYPE_V1, collector.name(), savedCollector);
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Example 18 with Collector

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

the class SidecarCollectorFacade method findExisting.

private Optional<NativeEntity<Collector>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final String name = collectorEntity.name().asString(parameters);
    final String os = collectorEntity.nodeOperatingSystem().asString(parameters);
    final Optional<Collector> existingCollector = Optional.ofNullable(collectorService.findByNameAndOs(name, os));
    return existingCollector.map(collector -> NativeEntity.create(entity.id(), collector.id(), TYPE_V1, collector.name(), collector));
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Aggregations

Collector (org.graylog.plugins.sidecar.rest.models.Collector)18 ApiOperation (io.swagger.annotations.ApiOperation)7 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)7 Produces (javax.ws.rs.Produces)6 Path (javax.ws.rs.Path)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)5 SidecarCollectorEntity (org.graylog2.contentpacks.model.entities.SidecarCollectorEntity)5 Test (org.junit.Test)5 POST (javax.ws.rs.POST)4 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)4 Timed (com.codahale.metrics.annotation.Timed)3 PUT (javax.ws.rs.PUT)3 Response (javax.ws.rs.core.Response)3 ValidationResult (org.graylog2.plugin.rest.ValidationResult)3 ImmutableList (com.google.common.collect.ImmutableList)2 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2