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 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(stream.getId()).thenReturn("stream-id");
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 EmailAlarmCallbackTest method checkConfigurationSucceedsWithFallbackSender.
@Test
public void checkConfigurationSucceedsWithFallbackSender() throws Exception {
final Map<String, Object> configMap = ImmutableMap.of("subject", "Graylog alert", "body", "foobar", "user_receivers", Collections.emptyList(), "email_receivers", Collections.emptyList());
final Configuration configuration = new Configuration(configMap);
when(emailConfiguration.getFromEmail()).thenReturn("default@sender.org");
alarmCallback.initialize(configuration);
alarmCallback.checkConfiguration();
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class EmailAlarmCallbackTest method checkConfigurationFailsWithoutSubject.
@Test
public void checkConfigurationFailsWithoutSubject() throws Exception {
final Map<String, Object> configMap = ImmutableMap.of("sender", "graylog@example.org", "body", "foobar", "user_receivers", Collections.emptyList(), "email_receivers", Collections.emptyList());
final Configuration configuration = new Configuration(configMap);
alarmCallback.initialize(configuration);
expectedException.expect(ConfigurationException.class);
expectedException.expectMessage("Sender or subject are missing or invalid.");
alarmCallback.checkConfiguration();
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class InputFacadeTest method findExisting.
@Test
@MongoDBFixtures("InputFacadeTest.json")
public void findExisting() {
final Map<String, Object> configuration = new HashMap<>();
configuration.put("override_source", null);
configuration.put("recv_buffer_size", 262144);
configuration.put("bind_address", "127.0.0.1");
configuration.put("port", 5555);
configuration.put("number_worker_threads", 8);
final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
final Optional<NativeEntity<InputWithExtractors>> existingInput = facade.findExisting(entity, Collections.emptyMap());
assertThat(existingInput).isEmpty();
}
Aggregations