use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method callThrowsAlarmCallbackExceptionIfURLIsMalformed.
@Test
public void callThrowsAlarmCallbackExceptionIfURLIsMalformed() throws Exception {
final Configuration configuration = new Configuration(ImmutableMap.of("url", "!FOOBAR"));
alarmCallback.initialize(configuration);
final Stream stream = mock(Stream.class);
final AlertCondition alertCondition = mock(AlertCondition.class);
final List<MessageSummary> messageSummaries = ImmutableList.of();
final AlertCondition.CheckResult checkResult = new AbstractAlertCondition.CheckResult(true, alertCondition, "Result Description", new DateTime(2016, 9, 6, 17, 0, DateTimeZone.UTC), messageSummaries);
expectedException.expect(AlarmCallbackException.class);
expectedException.expectMessage("Malformed URL: !FOOBAR");
alarmCallback.call(stream, checkResult);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method callThrowsAlarmCallbackExceptionIfRemoteServerReturnsError.
@Test
public void callThrowsAlarmCallbackExceptionIfRemoteServerReturnsError() throws Exception {
server.enqueue(new MockResponse().setResponseCode(500));
server.start();
final Configuration configuration = new Configuration(ImmutableMap.of("url", server.url("/").toString()));
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
final Stream stream = mock(Stream.class);
final AlertCondition alertCondition = mock(AlertCondition.class);
final List<MessageSummary> messageSummaries = ImmutableList.of();
final AlertCondition.CheckResult checkResult = new AbstractAlertCondition.CheckResult(true, alertCondition, "Result Description", new DateTime(2016, 9, 6, 17, 0, DateTimeZone.UTC), messageSummaries);
expectedException.expect(AlarmCallbackException.class);
expectedException.expectMessage("Expected successful HTTP response [2xx] but got [500].");
alarmCallback.call(stream, checkResult);
final RecordedRequest request = server.takeRequest();
assertThat(request.getPath()).isEqualTo("/");
assertThat(request.getHeader("Content-Type")).isEqualTo("application/json");
assertThat(request.getBodySize()).isPositive();
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class StreamRouterEngineTest method testMultipleStreamWithDifferentMatching.
@Test
public void testMultipleStreamWithDifferentMatching() {
final String dummyField = "dummyField";
final String dummyValue = "dummyValue";
final StreamRule streamRule1 = getStreamRuleMock("StreamRule1Id", StreamRuleType.EXACT, dummyField, dummyValue);
final StreamRule streamRule2 = getStreamRuleMock("StreamRule2Id", StreamRuleType.EXACT, dummyField, "not" + dummyValue);
final Stream stream1 = mock(Stream.class);
when(stream1.getId()).thenReturn("Stream1Id");
when(stream1.getMatchingType()).thenReturn(Stream.MatchingType.OR);
when(stream1.getStreamRules()).thenReturn(Lists.newArrayList(streamRule1, streamRule2));
final Stream stream2 = mock(Stream.class);
when(stream2.getId()).thenReturn("Stream2Id");
when(stream2.getMatchingType()).thenReturn(Stream.MatchingType.AND);
when(stream2.getStreamRules()).thenReturn(Lists.newArrayList(streamRule1, streamRule2));
final Message message = mock(Message.class);
when(message.getField(eq(dummyField))).thenReturn(dummyValue);
final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream1, stream2));
final List<Stream> result = engine.match(message);
assertThat(result).hasSize(1);
assertThat(result).contains(stream1);
assertThat(result).doesNotContain(stream2);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class StreamRouterEngineTest method testEmptyStreamRulesNonMatch.
@Test
public void testEmptyStreamRulesNonMatch() {
final Stream stream = mock(Stream.class);
when(stream.getStreamRules()).thenReturn(Collections.emptyList());
final Message message = mock(Message.class);
final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
final List<Stream> result = engine.match(message);
assertThat(result).isEmpty();
assertThat(result).doesNotContain(stream);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class StreamRouterEngineTest method testOrMatchingShouldNotMatch.
@Test
public void testOrMatchingShouldNotMatch() {
final String dummyField = "dummyField";
final String dummyValue = "dummyValue";
final Stream stream = mock(Stream.class);
when(stream.getMatchingType()).thenReturn(Stream.MatchingType.OR);
final StreamRule streamRule1 = getStreamRuleMock("StreamRule1Id", StreamRuleType.EXACT, dummyField, "not" + dummyValue);
final StreamRule streamRule2 = getStreamRuleMock("StreamRule2Id", StreamRuleType.EXACT, dummyField, "alsoNot" + dummyValue);
when(stream.getStreamRules()).thenReturn(Lists.newArrayList(streamRule1, streamRule2));
final Message message = mock(Message.class);
when(message.getField(eq(dummyField))).thenReturn(dummyValue);
final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
final List<Stream> result = engine.match(message);
assertThat(result).isEmpty();
}
Aggregations