use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class AvailableAlarmCallbackSummaryResponse method extractRequestedConfiguration.
public List<RequestedConfigurationField> extractRequestedConfiguration(Map<String, Map<String, Object>> config) {
List<RequestedConfigurationField> result = Lists.newArrayList();
List<RequestedConfigurationField> booleanFields = Lists.newArrayList();
for (Map.Entry<String, Map<String, Object>> entry : config.entrySet()) {
try {
String fieldType = (String) entry.getValue().get("type");
switch(fieldType) {
case "text":
result.add(new TextField(entry));
continue;
case "number":
result.add(new NumberField(entry));
continue;
case "boolean":
booleanFields.add(new BooleanField(entry));
continue;
case "dropdown":
result.add(new DropdownField(entry));
continue;
default:
LOG.info("Unknown field type [{}].", fieldType);
}
} catch (Exception e) {
LOG.error("Skipping invalid configuration field [" + entry.getKey() + "]", e);
}
}
result.addAll(booleanFields);
return result;
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class OutputRouterTest method testGetOutputsFromTwoStreams.
@Test
public void testGetOutputsFromTwoStreams() throws Exception {
final Stream stream1 = mock(Stream.class);
final Stream stream2 = mock(Stream.class);
final MessageOutput messageOutput1 = mock(MessageOutput.class);
final Set<MessageOutput> messageOutputSet1 = ImmutableSet.of(messageOutput1);
final MessageOutput messageOutput2 = mock(MessageOutput.class);
final Set<MessageOutput> messageOutputSet2 = ImmutableSet.of(messageOutput2);
final Message message = mock(Message.class);
when(message.getStreams()).thenReturn(ImmutableSet.of(stream1, stream2));
OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
doReturn(messageOutputSet1).when(outputRouter).getMessageOutputsForStream(eq(stream1));
doReturn(messageOutputSet2).when(outputRouter).getMessageOutputsForStream(eq(stream2));
final Collection<MessageOutput> result = outputRouter.getOutputsForMessage(message);
assertEquals(result.size(), 3);
assertTrue(result.contains(defaultMessageOutput));
assertTrue(result.contains(messageOutput1));
assertTrue(result.contains(messageOutput2));
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class OutputRegistryTest method testInvalidOutputConfiguration.
@Test
public void testInvalidOutputConfiguration() throws Exception {
final String outputId = "foobar";
final Stream stream = mock(Stream.class);
when(messageOutputFactory.fromStreamOutput(eq(output), any(Stream.class), any(Configuration.class))).thenThrow(new MessageOutputConfigurationException());
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);
assertNull(result);
assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class MetricUtils method buildTimerMap.
public static TimerRateMetricsResponse buildTimerMap(Timer t) {
final TimerRateMetricsResponse result = new TimerRateMetricsResponse();
final TimerMetricsResponse time = new TimerMetricsResponse();
final RateMetricsResponse rate = new RateMetricsResponse();
if (t == null) {
return result;
}
time.max = TimeUnit.MICROSECONDS.convert(t.getSnapshot().getMax(), TimeUnit.NANOSECONDS);
time.min = TimeUnit.MICROSECONDS.convert(t.getSnapshot().getMin(), TimeUnit.NANOSECONDS);
time.mean = TimeUnit.MICROSECONDS.convert((long) t.getSnapshot().getMean(), TimeUnit.NANOSECONDS);
time.percentile95th = TimeUnit.MICROSECONDS.convert((long) t.getSnapshot().get95thPercentile(), TimeUnit.NANOSECONDS);
time.percentile98th = TimeUnit.MICROSECONDS.convert((long) t.getSnapshot().get98thPercentile(), TimeUnit.NANOSECONDS);
time.percentile99th = TimeUnit.MICROSECONDS.convert((long) t.getSnapshot().get99thPercentile(), TimeUnit.NANOSECONDS);
time.stdDev = TimeUnit.MICROSECONDS.convert((long) t.getSnapshot().getStdDev(), TimeUnit.NANOSECONDS);
rate.oneMinute = t.getOneMinuteRate();
rate.fiveMinute = t.getFiveMinuteRate();
rate.fifteenMinute = t.getFifteenMinuteRate();
rate.total = t.getCount();
rate.mean = t.getMeanRate();
result.time = time;
result.rate = rate;
result.rateUnit = "events/second";
result.durationUnit = TimeUnit.MICROSECONDS.toString().toLowerCase(Locale.ENGLISH);
return result;
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class StreamImpl method asMap.
@Override
public Map<String, Object> asMap(List<StreamRule> streamRules) {
Map<String, Object> result = asMap();
List<Map<String, Object>> streamRulesMap = Lists.newArrayList();
for (StreamRule streamRule : streamRules) {
streamRulesMap.add(streamRule.asMap());
}
result.put(FIELD_RULES, streamRulesMap);
return result;
}
Aggregations