Search in sources :

Example 6 with Configuration

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

the class ConfigurationServiceTest method testAddMissingNewline.

@Test
public void testAddMissingNewline() throws Exception {
    configuration = buildTestConfig("template\n without\n newline");
    this.configurationService.save(configuration);
    Configuration result = this.configurationService.renderConfigurationForCollector(sidecar, configuration);
    Configuration configWithNewline = buildTestConfig(configuration.template() + "\n");
    assertEquals(configWithNewline, result);
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) Test(org.junit.Test)

Example 7 with Configuration

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

the class SidecarCollectorConfigurationFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Configuration configuration = configurationService.find(modelId.id());
    if (isNull(configuration)) {
        LOG.debug("Couldn't find collector configuration {}", entityDescriptor);
        return Optional.empty();
    }
    return Optional.of(exportNativeEntity(configuration, entityDescriptorIds));
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 8 with Configuration

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

the class SidecarCollectorConfigurationFacade method resolveNativeEntity.

@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
    final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entityDescriptor);
    final ModelId modelId = entityDescriptor.id();
    final Configuration configuration = configurationService.find(modelId.id());
    if (isNull(configuration)) {
        LOG.debug("Could not find configuration {}", entityDescriptor);
    } else {
        final EntityDescriptor collectorEntityDescriptor = EntityDescriptor.create(configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1);
        mutableGraph.putEdge(entityDescriptor, collectorEntityDescriptor);
    }
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 9 with Configuration

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

the class ConfigurationVariableResource method getConfigurationVariablesConfigurations.

@GET
@Path("/{id}/configurations")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_READ)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Show configurations using this variable")
public List<Configuration> getConfigurationVariablesConfigurations(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
    final ConfigurationVariable configurationVariable = findVariableOrFail(id);
    final List<Configuration> configurations = this.configurationService.findByConfigurationVariable(configurationVariable);
    return configurations;
}
Also used : ConfigurationVariable(org.graylog.plugins.sidecar.rest.models.ConfigurationVariable) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with Configuration

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

the class ConfigurationVariableResource method deleteConfigurationVariable.

@DELETE
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete a configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_DELETE)
public Response deleteConfigurationVariable(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
    final ConfigurationVariable configurationVariable = findVariableOrFail(id);
    final List<Configuration> configurations = this.configurationService.findByConfigurationVariable(configurationVariable);
    if (!configurations.isEmpty()) {
        final ValidationResult validationResult = new ValidationResult();
        validationResult.addError("name", "Variable is still used in the following configurations: " + configurations.stream().map(c -> c.name()).collect(Collectors.joining(", ")));
        return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
    }
    int deleted = configurationVariableService.delete(id);
    if (deleted == 0) {
        return Response.notModified().build();
    }
    etagService.invalidateAll();
    return Response.accepted().build();
}
Also used : ConfigurationVariable(org.graylog.plugins.sidecar.rest.models.ConfigurationVariable) PathParam(javax.ws.rs.PathParam) EtagService(org.graylog.plugins.sidecar.services.EtagService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ConfigurationVariableService(org.graylog.plugins.sidecar.services.ConfigurationVariableService) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ConfigurationVariable(org.graylog.plugins.sidecar.rest.models.ConfigurationVariable) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PluginRestResource(org.graylog2.plugin.rest.PluginRestResource) Api(io.swagger.annotations.Api) SidecarRestPermissions(org.graylog.plugins.sidecar.permissions.SidecarRestPermissions) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) POST(javax.ws.rs.POST) SidecarAuditEventTypes(org.graylog.plugins.sidecar.audit.SidecarAuditEventTypes) RestResource(org.graylog2.shared.rest.resources.RestResource) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) Response(javax.ws.rs.core.Response) ValidationResult(org.graylog2.plugin.rest.ValidationResult) PUT(javax.ws.rs.PUT) Pattern(java.util.regex.Pattern) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) ConfigurationService(org.graylog.plugins.sidecar.services.ConfigurationService) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

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