Search in sources :

Example 16 with Output

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

the class OutputRegistryTest method testLaunchNewOutput.

@Test
public void testLaunchNewOutput() throws Exception {
    final String outputId = "foobar";
    final Stream stream = mock(Stream.class);
    when(messageOutputFactory.fromStreamOutput(eq(output), eq(stream), any(Configuration.class))).thenReturn(messageOutput);
    when(outputService.load(eq(outputId))).thenReturn(output);
    final OutputRegistry outputRegistry = new OutputRegistry(null, outputService, messageOutputFactory, null, null, FAULT_COUNT_THRESHOLD, FAULT_PENALTY_SECONDS);
    assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
    MessageOutput result = outputRegistry.getOutputForIdAndStream(outputId, stream);
    assertSame(result, messageOutput);
    assertNotNull(outputRegistry.getRunningMessageOutputs());
    assertEquals(outputRegistry.getRunningMessageOutputs().size(), 1);
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Configuration(org.graylog2.plugin.configuration.Configuration) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 17 with Output

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

the class OutputRouterTest method testGetMessageOutputsForStreamWithTwoOutputs.

@Test
public void testGetMessageOutputsForStreamWithTwoOutputs() throws Exception {
    final Stream stream = mock(Stream.class);
    final Output output1 = mock(Output.class);
    final Output output2 = mock(Output.class);
    final String output1Id = "foo";
    final String output2Id = "bar";
    final MessageOutput messageOutput1 = mock(MessageOutput.class);
    final MessageOutput messageOutput2 = mock(MessageOutput.class);
    final Set<Output> outputSet = ImmutableSet.of(output1, output2);
    when(stream.getOutputs()).thenReturn(outputSet);
    when(output1.getId()).thenReturn(output1Id);
    when(output2.getId()).thenReturn(output2Id);
    when(outputRegistry.getOutputForIdAndStream(eq(output1Id), eq(stream))).thenReturn(messageOutput1);
    when(outputRegistry.getOutputForIdAndStream(eq(output2Id), eq(stream))).thenReturn(messageOutput2);
    final OutputRouter outputRouter = new OutputRouter(defaultMessageOutput, outputRegistry);
    final Collection<MessageOutput> messageOutputs = outputRouter.getMessageOutputsForStream(stream);
    assertEquals(messageOutputs.size(), 2);
    assertTrue(messageOutputs.contains(messageOutput1));
    assertTrue(messageOutputs.contains(messageOutput2));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 18 with Output

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

the class OutputRouterTest method testGetMessageOutputsForSingleStream.

@Test
public void testGetMessageOutputsForSingleStream() throws Exception {
    final Stream stream = mock(Stream.class);
    final Output output = mock(Output.class);
    final String outputId = "foobar";
    final MessageOutput messageOutput = mock(MessageOutput.class);
    final Set<Output> outputSet = ImmutableSet.of(output);
    when(stream.getOutputs()).thenReturn(outputSet);
    when(output.getId()).thenReturn(outputId);
    when(outputRegistry.getOutputForIdAndStream(eq(outputId), eq(stream))).thenReturn(messageOutput);
    final OutputRouter outputRouter = new OutputRouter(defaultMessageOutput, outputRegistry);
    final Collection<MessageOutput> messageOutputs = outputRouter.getMessageOutputsForStream(stream);
    assertEquals(messageOutputs.size(), 1);
    assertTrue(messageOutputs.contains(messageOutput));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 19 with Output

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

the class BundleImporter method createStream.

private org.graylog2.plugin.streams.Stream createStream(final String bundleId, final Stream streamDescription, final String userName) throws ValidationException {
    // We cannot create streams without having a default index set.
    final IndexSet indexSet = indexSetRegistry.getDefault();
    final Map<String, Object> streamData = ImmutableMap.<String, Object>builder().put(StreamImpl.FIELD_TITLE, streamDescription.getTitle()).put(StreamImpl.FIELD_DESCRIPTION, streamDescription.getDescription()).put(StreamImpl.FIELD_DISABLED, streamDescription.isDisabled()).put(StreamImpl.FIELD_MATCHING_TYPE, streamDescription.getMatchingType().name()).put(StreamImpl.FIELD_CREATOR_USER_ID, userName).put(StreamImpl.FIELD_CREATED_AT, Tools.nowUTC()).put(StreamImpl.FIELD_CONTENT_PACK, bundleId).put(StreamImpl.FIELD_DEFAULT_STREAM, streamDescription.isDefaultStream()).put(StreamImpl.FIELD_INDEX_SET_ID, indexSet.getConfig().id()).build();
    final String defaultStreamId = org.graylog2.plugin.streams.Stream.DEFAULT_STREAM_ID;
    final ObjectId id = streamDescription.isDefaultStream() ? new ObjectId(defaultStreamId) : new ObjectId(streamDescription.getId());
    final org.graylog2.plugin.streams.Stream stream = new StreamImpl(id, streamData, Collections.emptyList(), Collections.emptySet(), indexSet);
    final String streamId = streamService.save(stream);
    if (streamDescription.getStreamRules() != null) {
        for (StreamRule streamRule : streamDescription.getStreamRules()) {
            final Map<String, Object> streamRuleData = ImmutableMap.<String, Object>builder().put(StreamRuleImpl.FIELD_TYPE, streamRule.getType().toInteger()).put(StreamRuleImpl.FIELD_VALUE, streamRule.getValue()).put(StreamRuleImpl.FIELD_FIELD, streamRule.getField()).put(StreamRuleImpl.FIELD_INVERTED, streamRule.isInverted()).put(StreamRuleImpl.FIELD_STREAM_ID, new ObjectId(streamId)).put(StreamRuleImpl.FIELD_CONTENT_PACK, bundleId).put(StreamRuleImpl.FIELD_DESCRIPTION, streamRule.getDescription()).build();
            streamRuleService.save(new StreamRuleImpl(streamRuleData));
        }
    }
    for (final String outputId : streamDescription.getOutputs()) {
        if (isNullOrEmpty(outputId)) {
            LOG.warn("Couldn't find referenced output <{}> for stream <{}>", outputId, streamDescription.getTitle());
        } else {
            streamService.addOutput(stream, outputsByReferenceId.get(outputId));
        }
    }
    return stream;
}
Also used : ObjectId(org.bson.types.ObjectId) StreamImpl(org.graylog2.streams.StreamImpl) StreamRuleImpl(org.graylog2.streams.StreamRuleImpl) IndexSet(org.graylog2.indexer.IndexSet)

Example 20 with Output

use of org.graylog2.plugin.streams.Output 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);
}
Also used : AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) OutputSummary(org.graylog2.rest.models.system.outputs.responses.OutputSummary) Output(org.graylog2.plugin.streams.Output) 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)

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