Search in sources :

Example 1 with ConfigurationVariable

use of org.graylog.plugins.sidecar.rest.models.ConfigurationVariable 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());
}
Also used : ConfigurationVariable(org.graylog.plugins.sidecar.rest.models.ConfigurationVariable) Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) Test(org.junit.Test)

Example 2 with ConfigurationVariable

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

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

the class ConfigurationVariableResource method updateConfigurationVariable.

@PUT
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_UPDATE)
public Response updateConfigurationVariable(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "JSON body", required = true) @Valid @NotNull ConfigurationVariable request) {
    final ConfigurationVariable previousConfigurationVariable = findVariableOrFail(id);
    ValidationResult validationResult = validateConfigurationVariableHelper(request);
    if (validationResult.failed()) {
        return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
    }
    if (!previousConfigurationVariable.name().equals(request.name())) {
        configurationService.replaceVariableNames(previousConfigurationVariable.fullName(), request.fullName());
    }
    final ConfigurationVariable updatedConfigurationVariable = persistConfigurationVariable(id, request);
    etagService.invalidateAll();
    return Response.ok().entity(updatedConfigurationVariable).build();
}
Also used : ConfigurationVariable(org.graylog.plugins.sidecar.rest.models.ConfigurationVariable) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Path(javax.ws.rs.Path) 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) PUT(javax.ws.rs.PUT)

Example 4 with ConfigurationVariable

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

Example 5 with ConfigurationVariable

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

the class ConfigurationVariableResource method createConfigurationVariable.

@POST
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create new configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_CREATE)
public Response createConfigurationVariable(@ApiParam(name = "JSON body", required = true) @Valid @NotNull ConfigurationVariable request) {
    ValidationResult validationResult = validateConfigurationVariableHelper(request);
    if (validationResult.failed()) {
        return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
    }
    final ConfigurationVariable configurationVariable = persistConfigurationVariable(null, request);
    return Response.ok().entity(configurationVariable).build();
}
Also used : ConfigurationVariable(org.graylog.plugins.sidecar.rest.models.ConfigurationVariable) ValidationResult(org.graylog2.plugin.rest.ValidationResult) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Aggregations

ConfigurationVariable (org.graylog.plugins.sidecar.rest.models.ConfigurationVariable)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Produces (javax.ws.rs.Produces)4 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)4 Path (javax.ws.rs.Path)3 Configuration (org.graylog.plugins.sidecar.rest.models.Configuration)3 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 ValidationResult (org.graylog2.plugin.rest.ValidationResult)3 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Valid (javax.validation.Valid)1 NotNull (javax.validation.constraints.NotNull)1