use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class FormattedEmailAlertSenderTest method buildBodyUsesCustomBody.
@Test
public void buildBodyUsesCustomBody() throws Exception {
Configuration pluginConfig = new Configuration(Collections.<String, Object>singletonMap("body", "Test: ${stream.id}"));
emailAlertSender.initialize(pluginConfig);
Stream stream = mock(Stream.class);
when(stream.getId()).thenReturn("123456");
AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
String body = emailAlertSender.buildBody(stream, checkResult, Collections.<Message>emptyList());
assertThat(body).isEqualTo("Test: 123456");
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class FieldContentValueAlertConditionTest method testCorrectUsageOfRelativeRange.
@Test
public void testCorrectUsageOfRelativeRange() throws Exception {
final Stream stream = mock(Stream.class);
final Searches searches = mock(Searches.class);
final Configuration configuration = mock(Configuration.class);
final SearchResult searchResult = mock(SearchResult.class);
final int alertCheckInterval = 42;
final RelativeRange relativeRange = RelativeRange.create(alertCheckInterval);
when(configuration.getAlertCheckInterval()).thenReturn(alertCheckInterval);
when(searches.search(anyString(), anyString(), eq(relativeRange), anyInt(), anyInt(), any(Sorting.class))).thenReturn(searchResult);
final FieldContentValueAlertCondition alertCondition = new FieldContentValueAlertCondition(searches, configuration, stream, null, DateTime.now(DateTimeZone.UTC), "mockuser", ImmutableMap.<String, Object>of("field", "test", "value", "test"), "Field Content Value Test COndition");
final AbstractAlertCondition.CheckResult result = alertCondition.runCheck();
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method checkConfigurationFailsWithInvalidURL.
@Test
public void checkConfigurationFailsWithInvalidURL() throws Exception {
final Map<String, Object> configMap = ImmutableMap.of("url", "!Foobar!");
final Configuration configuration = new Configuration(configMap);
alarmCallback.initialize(configuration);
expectedException.expect(ConfigurationException.class);
expectedException.expectMessage("Malformed URL");
alarmCallback.checkConfiguration();
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method callThrowsAlarmCallbackExceptionIfRequestBodyCanNotBeBuilt.
@Test
public void callThrowsAlarmCallbackExceptionIfRequestBodyCanNotBeBuilt() throws Exception {
final Configuration configuration = new Configuration(ImmutableMap.of("url", "http://example.org"));
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) {
@Override
public String getResultDescription() {
throw new RuntimeException("Boom");
}
};
expectedException.expect(AlarmCallbackException.class);
expectedException.expectMessage("Unable to serialize alarm");
alarmCallback.call(stream, checkResult);
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method callSucceedsIfRemoteRequestSucceeds.
@Test
public void callSucceedsIfRemoteRequestSucceeds() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200));
server.start();
final Configuration configuration = new Configuration(ImmutableMap.of("url", server.url("/").toString()));
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
final Stream stream = new StreamMock(ImmutableMap.of("_id", "stream-id", "title", "Stream Title", "description", "Stream Description"), ImmutableList.of());
final AlertCondition alertCondition = new DummyAlertCondition(stream, "condition-id", new DateTime(2016, 9, 6, 17, 0, DateTimeZone.UTC), "user", ImmutableMap.of(), "Alert Condition Title");
final List<MessageSummary> messageSummaries = ImmutableList.of(new MessageSummary("graylog_1", new Message("Test message 1", "source1", new DateTime(2016, 9, 6, 17, 0, DateTimeZone.UTC))), new MessageSummary("graylog_2", new Message("Test message 2", "source2", new DateTime(2016, 9, 6, 17, 0, DateTimeZone.UTC))));
final AlertCondition.CheckResult checkResult = new AbstractAlertCondition.CheckResult(true, alertCondition, "Result Description", new DateTime(2016, 9, 6, 17, 0, DateTimeZone.UTC), messageSummaries);
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();
final String requestBody = request.getBody().readUtf8();
final JsonNode jsonNode = objectMapper.readTree(requestBody);
assertThat(jsonNode.get("check_result").get("matching_messages").size()).isEqualTo(2);
assertThat(jsonNode.get("check_result").get("triggered").asBoolean()).isTrue();
assertThat(jsonNode.get("check_result").get("triggered_at").asText()).isEqualTo("2016-09-06T17:00:00.000Z");
assertThat(jsonNode.get("stream").get("id").asText()).isEqualTo("stream-id");
}
Aggregations