use of org.graylog2.rest.models.system.outputs.responses.OutputSummary in project graylog2-server by Graylog2.
the class StreamOutputResource method get.
@GET
@Timed
@ApiOperation(value = "Get a list of all outputs for a stream")
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream on this node.") })
public OutputListResponse get(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamid);
checkPermission(RestPermissions.STREAM_OUTPUTS_READ);
final Stream stream = streamService.load(streamid);
final Set<OutputSummary> outputs = new HashSet<>();
for (Output output : stream.getOutputs()) outputs.add(OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), new HashMap<>(output.getConfiguration()), output.getContentPack()));
return OutputListResponse.create(outputs);
}
use of org.graylog2.rest.models.system.outputs.responses.OutputSummary in project graylog2-server by Graylog2.
the class OutputResource method get.
@GET
@Timed
@ApiOperation(value = "Get a list of all outputs")
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
public OutputListResponse get() {
checkPermission(RestPermissions.OUTPUTS_READ);
final Set<OutputSummary> outputs = new HashSet<>();
for (Output output : outputService.loadAll()) outputs.add(OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), new HashMap<>(output.getConfiguration()), output.getContentPack()));
return OutputListResponse.create(outputs);
}
use of org.graylog2.rest.models.system.outputs.responses.OutputSummary 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();
}
use of org.graylog2.rest.models.system.outputs.responses.OutputSummary 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;
}
use of org.graylog2.rest.models.system.outputs.responses.OutputSummary in project graylog2-server by Graylog2.
the class OutputResource method get.
@GET
@Path("/{outputId}")
@Timed
@ApiOperation(value = "Get specific output")
@RequiresPermissions(RestPermissions.OUTPUTS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such output on this node.") })
public OutputSummary get(@ApiParam(name = "outputId", value = "The id of the output we want.", required = true) @PathParam("outputId") String outputId) throws NotFoundException {
checkPermission(RestPermissions.OUTPUTS_READ, outputId);
final Output output = outputService.load(outputId);
return OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), output.getConfiguration(), output.getContentPack());
}
Aggregations