Search in sources :

Example 31 with NotFoundException

use of org.graylog2.database.NotFoundException 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);
}
Also used : OutputSummary(org.graylog2.rest.models.system.outputs.responses.OutputSummary) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class StreamRuleResource method create.

@POST
@Timed
@ApiOperation(value = "Create a stream rule")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_RULE_CREATE)
public Response create(@ApiParam(name = "streamid", value = "The stream id this new rule belongs to.", required = true) @PathParam("streamid") String streamId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStreamRuleRequest cr) throws NotFoundException, ValidationException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamId);
    checkNotDefaultStream(streamId, "Cannot add stream rules to the default stream.");
    final Stream stream = streamService.load(streamId);
    final StreamRule streamRule = streamRuleService.create(streamId, cr);
    final String id = streamService.save(streamRule);
    clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
    final SingleStreamRuleSummaryResponse response = SingleStreamRuleSummaryResponse.create(id);
    final URI streamRuleUri = getUriBuilderToSelf().path(StreamRuleResource.class).path("{streamRuleId}").build(streamId, id);
    return Response.created(streamRuleUri).entity(response).build();
}
Also used : SingleStreamRuleSummaryResponse(org.graylog2.rest.resources.streams.responses.SingleStreamRuleSummaryResponse) StreamRule(org.graylog2.plugin.streams.StreamRule) Stream(org.graylog2.plugin.streams.Stream) URI(java.net.URI) 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)

Example 33 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class StreamRuleServiceImpl method loadForStreamId.

@Override
public List<StreamRule> loadForStreamId(String streamId) throws NotFoundException {
    ObjectId id = new ObjectId(streamId);
    final List<StreamRule> streamRules = new ArrayList<>();
    final List<DBObject> respStreamRules = query(StreamRuleImpl.class, new BasicDBObject(StreamRuleImpl.FIELD_STREAM_ID, id));
    for (DBObject streamRule : respStreamRules) {
        streamRules.add(toStreamRule(streamRule));
    }
    return streamRules;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) StreamRule(org.graylog2.plugin.streams.StreamRule) ArrayList(java.util.ArrayList) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 34 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class StreamServiceImpl method load.

public Stream load(ObjectId id) throws NotFoundException {
    final DBObject o = get(StreamImpl.class, id);
    if (o == null) {
        throw new NotFoundException("Stream <" + id + "> not found!");
    }
    final List<StreamRule> streamRules = streamRuleService.loadForStreamId(id.toHexString());
    final Set<Output> outputs = loadOutputsForRawStream(o);
    @SuppressWarnings("unchecked") final Map<String, Object> fields = o.toMap();
    return new StreamImpl((ObjectId) o.get("_id"), fields, streamRules, outputs, getIndexSet(o));
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) Output(org.graylog2.plugin.streams.Output) NotFoundException(org.graylog2.database.NotFoundException) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 35 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class ClusterStatsService method ldapStats.

public LdapStats ldapStats() {
    int numberOfRoles = 0;
    LdapSettings ldapSettings = null;
    try {
        numberOfRoles = roleService.loadAll().size();
        ldapSettings = ldapSettingsService.load();
    } catch (NotFoundException ignored) {
    }
    if (ldapSettings == null) {
        return LdapStats.create(false, false, 0, numberOfRoles);
    }
    return LdapStats.create(ldapSettings.isEnabled(), ldapSettings.isActiveDirectory(), ldapSettings.getGroupMapping().size(), numberOfRoles);
}
Also used : NotFoundException(org.graylog2.database.NotFoundException) LdapSettings(org.graylog2.shared.security.ldap.LdapSettings)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)91 Timed (com.codahale.metrics.annotation.Timed)77 Path (javax.ws.rs.Path)75 ApiResponses (io.swagger.annotations.ApiResponses)66 AuditEvent (org.graylog2.audit.jersey.AuditEvent)60 Produces (javax.ws.rs.Produces)44 NotFoundException (org.graylog2.database.NotFoundException)32 GET (javax.ws.rs.GET)30 PUT (javax.ws.rs.PUT)28 BadRequestException (javax.ws.rs.BadRequestException)27 Stream (org.graylog2.plugin.streams.Stream)27 NotFoundException (javax.ws.rs.NotFoundException)26 Consumes (javax.ws.rs.Consumes)21 DELETE (javax.ws.rs.DELETE)21 POST (javax.ws.rs.POST)19 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 MessageInput (org.graylog2.plugin.inputs.MessageInput)15 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)11 Input (org.graylog2.inputs.Input)11 ValidationException (org.graylog2.plugin.database.ValidationException)11