use of org.graylog.plugins.sidecar.rest.models.Configuration in project graylog2-server by Graylog2.
the class ConfigurationService method replaceVariableNames.
public void replaceVariableNames(String oldName, String newName) {
final DBQuery.Query query = DBQuery.regex(Configuration.FIELD_TEMPLATE, Pattern.compile(Pattern.quote(oldName)));
List<Configuration> configurations = findByQuery(query);
for (Configuration config : configurations) {
final String newTemplate = config.template().replace(oldName, newName);
db.findAndModify(DBQuery.is("_id", config.id()), new BasicDBObject(), new BasicDBObject(), false, config.toBuilder().template(newTemplate).build(), true, true);
}
}
use of org.graylog.plugins.sidecar.rest.models.Configuration in project graylog2-server by Graylog2.
the class ConfigurationResource method renderConfiguration.
@GET
@Timed
@Path("/render/{sidecarId}/{configurationId}")
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_READ)
@ApiOperation(value = "Render configuration template")
public Response renderConfiguration(@Context HttpHeaders httpHeaders, @ApiParam(name = "sidecarId", required = true) @PathParam("sidecarId") String sidecarId, @ApiParam(name = "configurationId", required = true) @PathParam("configurationId") String configurationId) throws RenderTemplateException {
String ifNoneMatch = httpHeaders.getHeaderString("If-None-Match");
Boolean etagCached = false;
Response.ResponseBuilder builder = Response.noContent();
// check if client is up to date with a known valid etag
if (ifNoneMatch != null) {
EntityTag etag = new EntityTag(ifNoneMatch.replaceAll("\"", ""));
if (etagService.isPresent(etag.toString())) {
etagCached = true;
builder = Response.notModified();
builder.tag(etag);
}
}
// fetch configuration from database if client is outdated
if (!etagCached) {
Sidecar sidecar = sidecarService.findByNodeId(sidecarId);
if (sidecar == null) {
throw new NotFoundException("Couldn't find Sidecar by ID: " + sidecarId);
}
Configuration configuration = configurationService.find(configurationId);
if (configuration == null) {
throw new NotFoundException("Couldn't find configuration by ID: " + configurationId);
}
Configuration collectorConfiguration = this.configurationService.renderConfigurationForCollector(sidecar, configuration);
// add new etag to cache
String etagString = configurationToEtag(collectorConfiguration);
EntityTag collectorConfigurationEtag = new EntityTag(etagString);
builder = Response.ok(collectorConfiguration);
builder.tag(collectorConfigurationEtag);
etagService.put(collectorConfigurationEtag.toString());
}
// set cache control
CacheControl cacheControl = new CacheControl();
cacheControl.setNoTransform(true);
cacheControl.setPrivate(true);
builder.cacheControl(cacheControl);
return builder.build();
}
use of org.graylog.plugins.sidecar.rest.models.Configuration in project graylog2-server by Graylog2.
the class ConfigurationResource method copyConfiguration.
@POST
@Path("/{id}/{name}")
@RequiresPermissions({ SidecarRestPermissions.CONFIGURATIONS_READ, SidecarRestPermissions.CONFIGURATIONS_CREATE })
@ApiOperation(value = "Copy a configuration")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_CLONE)
public Response copyConfiguration(@ApiParam(name = "id", required = true) @PathParam("id") String id, @PathParam("name") String name) throws NotFoundException {
final Configuration configuration = configurationService.copyConfiguration(id, name);
final ValidationResult validationResult = validate(configuration);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
configurationService.save(configuration);
return Response.accepted().build();
}
use of org.graylog.plugins.sidecar.rest.models.Configuration in project graylog2-server by Graylog2.
the class AdministrationResource method getCollectors.
private List<Collector> getCollectors(Map<String, String> filters) {
final String collectorKey = AdministrationFilter.Type.COLLECTOR.toString().toLowerCase(Locale.ENGLISH);
final String configurationKey = AdministrationFilter.Type.CONFIGURATION.toString().toLowerCase(Locale.ENGLISH);
final List<String> collectorIds = new ArrayList<>();
// Add ID of collector we want to filter for
if (filters.containsKey(collectorKey)) {
collectorIds.add(filters.get(collectorKey));
}
// Load collectors using the configuration ID that we want to filter for
if (filters.containsKey(configurationKey)) {
final Configuration configuration = configurationService.find(filters.get(configurationKey));
if (!collectorIds.contains(configuration.collectorId())) {
collectorIds.add(configuration.collectorId());
}
}
switch(collectorIds.size()) {
case 0:
return collectorService.all();
case 1:
return ImmutableList.of(collectorService.find(collectorIds.get(0)));
default:
return new ArrayList<>();
}
}
use of org.graylog.plugins.sidecar.rest.models.Configuration in project graylog2-server by Graylog2.
the class ConfigurationServiceTest method testTemplateRenderWithConfigurationVariables.
@Test
public void testTemplateRenderWithConfigurationVariables() throws Exception {
final String TEMPLATE = "foo bar\n myVariable: ${user.myVariable}\n";
final String TEMPLATE_RENDERED = "foo bar\n myVariable: content of myVariable\n";
configuration = buildTestConfig(TEMPLATE);
this.configurationService.save(configuration);
ConfigurationVariable myVariable = ConfigurationVariable.create("myVariable", "desc", "content of myVariable");
this.configurationVariableService.save(myVariable);
Configuration result = this.configurationService.renderConfigurationForCollector(sidecar, configuration);
assertEquals(TEMPLATE_RENDERED, result.template());
}
Aggregations