Search in sources :

Example 16 with Configuration

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

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

the class SidecarCollectorConfigurationFacade method decode.

private NativeEntity<Configuration> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
    final Configuration configuration = Configuration.create(configurationEntity.collectorId().asString(parameters), configurationEntity.title().asString(parameters), configurationEntity.color().asString(parameters), configurationEntity.template().asString(parameters));
    final Configuration savedConfiguration = configurationService.save(configuration);
    return NativeEntity.create(entity.id(), savedConfiguration.id(), TYPE_V1, configuration.name(), savedConfiguration);
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)

Example 18 with Configuration

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

the class ConfigurationServiceTest method testTemplateRender.

@Test
public void testTemplateRender() throws Exception {
    final String TEMPLATE = "foo bar\n nodename: ${sidecar.nodeName}\n";
    final String TEMPLATE_RENDERED = "foo bar\n nodename: mockymock\n";
    configuration = buildTestConfig(TEMPLATE);
    this.configurationService.save(configuration);
    Configuration result = this.configurationService.renderConfigurationForCollector(sidecar, configuration);
    Configuration configWithNewline = buildTestConfig(TEMPLATE_RENDERED);
    assertEquals(configWithNewline, result);
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) Test(org.junit.Test)

Aggregations

Configuration (org.graylog.plugins.sidecar.rest.models.Configuration)18 ApiOperation (io.swagger.annotations.ApiOperation)8 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)8 Produces (javax.ws.rs.Produces)7 Path (javax.ws.rs.Path)6 GET (javax.ws.rs.GET)5 ValidationResult (org.graylog2.plugin.rest.ValidationResult)5 NotFoundException (javax.ws.rs.NotFoundException)4 AuditEvent (org.graylog2.audit.jersey.AuditEvent)4 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)4 POST (javax.ws.rs.POST)3 ConfigurationVariable (org.graylog.plugins.sidecar.rest.models.ConfigurationVariable)3 PUT (javax.ws.rs.PUT)2 Response (javax.ws.rs.core.Response)2 Sidecar (org.graylog.plugins.sidecar.rest.models.Sidecar)2 ModelId (org.graylog2.contentpacks.model.ModelId)2 Test (org.junit.Test)2 Timed (com.codahale.metrics.annotation.Timed)1 BasicDBObject (com.mongodb.BasicDBObject)1 Api (io.swagger.annotations.Api)1