Search in sources :

Example 16 with Result

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;
}
Also used : DropdownField(org.graylog2.rest.models.configuration.responses.DropdownField) BooleanField(org.graylog2.rest.models.configuration.responses.BooleanField) RequestedConfigurationField(org.graylog2.rest.models.configuration.responses.RequestedConfigurationField) TextField(org.graylog2.rest.models.configuration.responses.TextField) Map(java.util.Map) NumberField(org.graylog2.rest.models.configuration.responses.NumberField)

Example 17 with 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));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Message(org.graylog2.plugin.Message) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 18 with Result

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);
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Configuration(org.graylog2.plugin.configuration.Configuration) MessageOutputConfigurationException(org.graylog2.plugin.outputs.MessageOutputConfigurationException) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 19 with Result

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;
}
Also used : RateMetricsResponse(org.graylog2.rest.models.metrics.responses.RateMetricsResponse) TimerRateMetricsResponse(org.graylog2.rest.models.metrics.responses.TimerRateMetricsResponse) TimerRateMetricsResponse(org.graylog2.rest.models.metrics.responses.TimerRateMetricsResponse) TimerMetricsResponse(org.graylog2.rest.models.metrics.responses.TimerMetricsResponse)

Example 20 with 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;
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

Test (org.junit.Test)73 Message (org.graylog2.plugin.Message)51 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 Stream (org.graylog2.plugin.streams.Stream)20 StreamRule (org.graylog2.plugin.streams.StreamRule)19 DateTime (org.joda.time.DateTime)18 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)12 ApiResponses (io.swagger.annotations.ApiResponses)11 Produces (javax.ws.rs.Produces)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 Function (com.google.common.base.Function)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)8 ZonedDateTime (java.time.ZonedDateTime)8 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)8 Sorting (org.graylog2.indexer.searches.Sorting)8 URI (java.net.URI)7 MessageSummary (org.graylog2.plugin.MessageSummary)7