Search in sources :

Example 11 with Output

use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.

the class StreamOutputResource method add.

@POST
@Timed
@ApiOperation(value = "Associate outputs with a stream")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid output specification in input.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_CREATE)
public Response add(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) @Valid @NotNull AddOutputRequest aor) throws ValidationException, NotFoundException {
    final Stream stream = streamService.load(streamid);
    for (String outputId : aor.outputs()) {
        final Output output = outputService.load(outputId);
        streamService.addOutput(stream, output);
        clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
    }
    return Response.accepted().build();
}
Also used : Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) 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 12 with Output

use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.

the class StreamOutputResource method remove.

@DELETE
@Path("/{outputId}")
@Timed
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_DELETE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete output of a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_DELETE)
public void remove(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws NotFoundException {
    final Stream stream = streamService.load(streamid);
    final Output output = outputService.load(outputId);
    streamService.removeOutput(stream, output);
    outputRegistry.removeOutput(output);
    clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
Also used : Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with Output

use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.

the class OutputRegistry method removeOutput.

public void removeOutput(Output output) {
    final MessageOutput messageOutput = runningMessageOutputs.getIfPresent(output.getId());
    if (messageOutput != null) {
        messageOutput.stop();
    }
    runningMessageOutputs.invalidate(output.getId());
    faultCounters.invalidate(output.getId());
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput)

Example 14 with Output

use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.

the class BatchedElasticSearchOutputFlushThread method doRun.

@Override
public void doRun() {
    LOG.debug("Checking for outputs to flush ...");
    for (MessageOutput output : outputRegistry.getMessageOutputs()) {
        if (output instanceof BlockingBatchedESOutput) {
            try {
                LOG.debug("Flushing output <{}>", output);
                ((BlockingBatchedESOutput) output).forceFlushIfTimedout();
            } catch (Exception e) {
                LOG.error("Caught exception while trying to flush output: {}", e);
            }
        }
    }
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) BlockingBatchedESOutput(org.graylog2.outputs.BlockingBatchedESOutput)

Example 15 with Output

use of org.graylog2.plugin.streams.Output in project graylog2-server by Graylog2.

the class StreamServiceImpl method loadAll.

private List<Stream> loadAll(DBObject query) {
    final List<DBObject> results = query(StreamImpl.class, query);
    final List<String> streamIds = results.stream().map(o -> o.get("_id").toString()).collect(Collectors.toList());
    final Map<String, List<StreamRule>> allStreamRules = streamRuleService.loadForStreamIds(streamIds);
    final ImmutableList.Builder<Stream> streams = ImmutableList.builder();
    for (DBObject o : results) {
        final ObjectId objectId = (ObjectId) o.get("_id");
        final String id = objectId.toHexString();
        final List<StreamRule> streamRules = allStreamRules.getOrDefault(id, Collections.emptyList());
        LOG.debug("Found {} rules for stream <{}>", streamRules.size(), id);
        final Set<Output> outputs = loadOutputsForRawStream(o);
        @SuppressWarnings("unchecked") final Map<String, Object> fields = o.toMap();
        streams.add(new StreamImpl(objectId, fields, streamRules, outputs, getIndexSet(o)));
    }
    return streams.build();
}
Also used : QueryBuilder(com.mongodb.QueryBuilder) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) EmailAlarmCallback(org.graylog2.alarmcallbacks.EmailAlarmCallback) HashMap(java.util.HashMap) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlertService(org.graylog2.alerts.AlertService) StreamRule(org.graylog2.plugin.streams.StreamRule) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) DBObject(com.mongodb.DBObject) Map(java.util.Map) MongoIndexSet(org.graylog2.indexer.MongoIndexSet) EmbeddedPersistable(org.graylog2.plugin.database.EmbeddedPersistable) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) Alert(org.graylog2.alerts.Alert) PersistedServiceImpl(org.graylog2.database.PersistedServiceImpl) NotFoundException(org.graylog2.database.NotFoundException) Nullable(javax.annotation.Nullable) Notification(org.graylog2.notifications.Notification) Logger(org.slf4j.Logger) NotificationService(org.graylog2.notifications.NotificationService) BasicDBObject(com.mongodb.BasicDBObject) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) AlarmCallbackConfigurationImpl(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationImpl) AlarmCallbackConfigurationService(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationService) CreateStreamRequest(org.graylog2.rest.resources.streams.requests.CreateStreamRequest) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) ValidationException(org.graylog2.plugin.database.ValidationException) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) ObjectId(org.bson.types.ObjectId) Optional(java.util.Optional) MongoConnection(org.graylog2.database.MongoConnection) Collections(java.util.Collections) ObjectId(org.bson.types.ObjectId) ImmutableList(com.google.common.collect.ImmutableList) StreamRule(org.graylog2.plugin.streams.StreamRule) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Output(org.graylog2.plugin.streams.Output) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Stream(org.graylog2.plugin.streams.Stream) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Aggregations

Output (org.graylog2.plugin.streams.Output)15 Stream (org.graylog2.plugin.streams.Stream)11 ApiOperation (io.swagger.annotations.ApiOperation)10 Timed (com.codahale.metrics.annotation.Timed)9 Produces (javax.ws.rs.Produces)9 MessageOutput (org.graylog2.plugin.outputs.MessageOutput)9 ApiResponses (io.swagger.annotations.ApiResponses)8 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)8 AuditEvent (org.graylog2.audit.jersey.AuditEvent)7 Path (javax.ws.rs.Path)6 Test (org.junit.Test)6 Consumes (javax.ws.rs.Consumes)4 DateTime (org.joda.time.DateTime)4 HashSet (java.util.HashSet)3 GET (javax.ws.rs.GET)3 POST (javax.ws.rs.POST)3 ObjectId (org.bson.types.ObjectId)3 ValidationException (org.graylog2.plugin.database.ValidationException)3 StreamRule (org.graylog2.plugin.streams.StreamRule)3 AvailableOutputSummary (org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary)3