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);
}
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));
}
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));
}
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;
}
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);
}
Aggregations