Search in sources :

Example 1 with AvailableOutputSummary

use of org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary in project graylog2-server by Graylog2.

the class MessageOutputFactory method getAvailableOutputs.

public Map<String, AvailableOutputSummary> getAvailableOutputs() {
    final Map<String, AvailableOutputSummary> result = new HashMap<>(availableOutputs.size());
    for (Map.Entry<String, MessageOutput.Factory<? extends MessageOutput>> messageOutputEntry : this.availableOutputs.entrySet()) {
        final MessageOutput.Factory messageOutputFactoryClass = messageOutputEntry.getValue();
        final MessageOutput.Descriptor descriptor = messageOutputFactoryClass.getDescriptor();
        final AvailableOutputSummary availableOutputSummary = AvailableOutputSummary.create(descriptor.getName(), messageOutputEntry.getKey(), descriptor.getHumanName(), descriptor.getLinkToDocs(), messageOutputFactoryClass.getConfig().getRequestedConfiguration());
        result.put(messageOutputEntry.getKey(), availableOutputSummary);
    }
    return result;
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) HashMap(java.util.HashMap) AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with AvailableOutputSummary

use of org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary in project graylog2-server by Graylog2.

the class OutputResource method create.

@POST
@Timed
@ApiOperation(value = "Create an output")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid output specification in input.", response = OutputSummary.class) })
@AuditEvent(type = AuditEventTypes.MESSAGE_OUTPUT_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) CreateOutputRequest csor) throws ValidationException {
    checkPermission(RestPermissions.OUTPUTS_CREATE);
    final AvailableOutputSummary outputSummary = messageOutputFactory.getAvailableOutputs().get(csor.type());
    if (outputSummary == null) {
        throw new ValidationException("type", "Invalid output type");
    }
    // Make sure the config values will be stored with the correct type.
    final CreateOutputRequest createOutputRequest = CreateOutputRequest.create(csor.title(), csor.type(), ConfigurationMapConverter.convertValues(csor.configuration(), outputSummary.requestedConfiguration()), csor.streams());
    final Output output = outputService.create(createOutputRequest, getCurrentUser().getName());
    final URI outputUri = getUriBuilderToSelf().path(OutputResource.class).path("{outputId}").build(output.getId());
    return Response.created(outputUri).entity(OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), new HashMap<>(output.getConfiguration()), output.getContentPack())).build();
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) Output(org.graylog2.plugin.streams.Output) URI(java.net.URI) DateTime(org.joda.time.DateTime) CreateOutputRequest(org.graylog2.rest.models.streams.outputs.requests.CreateOutputRequest) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with AvailableOutputSummary

use of org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary in project graylog2-server by Graylog2.

the class OutputResource method update.

@PUT
@Path("/{outputId}")
@Timed
@ApiOperation(value = "Update output")
@RequiresPermissions(RestPermissions.OUTPUTS_EDIT)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such output on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_OUTPUT_UPDATE)
public Output update(@ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId, @ApiParam(name = "JSON body", required = true) Map<String, Object> deltas) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.OUTPUTS_EDIT, outputId);
    final Output oldOutput = outputService.load(outputId);
    final AvailableOutputSummary outputSummary = messageOutputFactory.getAvailableOutputs().get(oldOutput.getType());
    if (outputSummary == null) {
        throw new ValidationException("type", "Invalid output type");
    }
    deltas.remove("streams");
    if (deltas.containsKey("configuration")) {
        @SuppressWarnings("unchecked") final Map<String, Object> configuration = (Map<String, Object>) deltas.get("configuration");
        deltas.put("configuration", ConfigurationMapConverter.convertValues(configuration, outputSummary.requestedConfiguration()));
    }
    final Output output = this.outputService.update(outputId, deltas);
    this.outputRegistry.removeOutput(oldOutput);
    return output;
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) Output(org.graylog2.plugin.streams.Output) AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

AvailableOutputSummary (org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary)3 Timed (com.codahale.metrics.annotation.Timed)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Produces (javax.ws.rs.Produces)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2 ValidationException (org.graylog2.plugin.database.ValidationException)2 Output (org.graylog2.plugin.streams.Output)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 URI (java.net.URI)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 MessageOutput (org.graylog2.plugin.outputs.MessageOutput)1 CreateOutputRequest (org.graylog2.rest.models.streams.outputs.requests.CreateOutputRequest)1 DateTime (org.joda.time.DateTime)1