Search in sources :

Example 61 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class FormattedEmailAlertSenderTest method buildBodyContainsInfoMessageIfWebInterfaceURLIsIncomplete.

@Test
public void buildBodyContainsInfoMessageIfWebInterfaceURLIsIncomplete() throws Exception {
    final EmailConfiguration configuration = new EmailConfiguration() {

        @Override
        public URI getWebInterfaceUri() {
            return URI.create("");
        }
    };
    this.emailAlertSender = new FormattedEmailAlertSender(configuration, mockNotificationService, mockNodeId, templateEngine);
    Stream stream = mock(Stream.class);
    when(stream.getId()).thenReturn("123456");
    when(stream.getTitle()).thenReturn("Stream Title");
    AlertCondition alertCondition = mock(AlertCondition.class);
    AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
    when(checkResult.getTriggeredAt()).thenReturn(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
    when(checkResult.getTriggeredCondition()).thenReturn(alertCondition);
    String body = emailAlertSender.buildBody(stream, checkResult, Collections.<Message>emptyList());
    assertThat(body).contains("Stream URL: Please configure 'transport_email_web_interface_url' in your Graylog configuration file.");
}
Also used : EmailConfiguration(org.graylog2.configuration.EmailConfiguration) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Stream(org.graylog2.plugin.streams.Stream) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 62 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class AlarmCallbackFactoryTest method testCreateByAlarmCallbackConfiguration.

@Test
public void testCreateByAlarmCallbackConfiguration() throws Exception {
    AlarmCallbackConfiguration configuration = mock(AlarmCallbackConfiguration.class);
    when(configuration.getType()).thenReturn(DummyAlarmCallback.class.getCanonicalName());
    AlarmCallback alarmCallback = alarmCallbackFactory.create(configuration);
    assertNotNull(alarmCallback);
    assertTrue(alarmCallback instanceof DummyAlarmCallback);
    assertEquals(dummyAlarmCallback, alarmCallback);
}
Also used : AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) Test(org.junit.Test)

Example 63 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class EmailAlarmCallbackTest method checkConfigurationFailsWithoutSender.

@Test
public void checkConfigurationFailsWithoutSender() 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);
    alarmCallback.initialize(configuration);
    when(emailConfiguration.getFromEmail()).thenReturn("");
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("Sender or subject are missing or invalid.");
    alarmCallback.checkConfiguration();
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) EmailConfiguration(org.graylog2.configuration.EmailConfiguration) Test(org.junit.Test)

Example 64 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class EmailAlarmCallbackTest method checkConfigurationSucceedsWithValidConfiguration.

@Test
public void checkConfigurationSucceedsWithValidConfiguration() throws Exception {
    final Map<String, Object> configMap = ImmutableMap.of("sender", "graylog@example.org", "subject", "Graylog alert", "body", "foobar", "user_receivers", Collections.emptyList(), "email_receivers", Collections.emptyList());
    final Configuration configuration = new Configuration(configMap);
    alarmCallback.initialize(configuration);
    alarmCallback.checkConfiguration();
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) EmailConfiguration(org.graylog2.configuration.EmailConfiguration) Test(org.junit.Test)

Example 65 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class HTTPAlarmCallbackTest method checkConfigurationSucceedsWithValidConfiguration.

@Test
public void checkConfigurationSucceedsWithValidConfiguration() throws Exception {
    final Map<String, Object> configMap = ImmutableMap.of("url", "http://example.com/");
    final Configuration configuration = new Configuration(configMap);
    alarmCallback.initialize(configuration);
    alarmCallback.checkConfiguration();
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 Configuration (org.graylog2.plugin.configuration.Configuration)29 ApiOperation (io.swagger.annotations.ApiOperation)24 Timed (com.codahale.metrics.annotation.Timed)23 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)17 Consumes (javax.ws.rs.Consumes)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Stream (org.graylog2.plugin.streams.Stream)13 ApiResponses (io.swagger.annotations.ApiResponses)12 PUT (javax.ws.rs.PUT)11 ValidationException (org.graylog2.plugin.database.ValidationException)11 DateTime (org.joda.time.DateTime)11 Produces (javax.ws.rs.Produces)10 Configuration (org.graylog2.Configuration)10 POST (javax.ws.rs.POST)9 EmailConfiguration (org.graylog2.configuration.EmailConfiguration)9 URI (java.net.URI)8