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