Search in sources :

Example 1 with EmailConfiguration

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

the class FormattedEmailAlertSenderTest method defaultBodyTemplateDoesNotShowBacklogIfBacklogIsEmpty.

@Test
public void defaultBodyTemplateDoesNotShowBacklogIfBacklogIsEmpty() throws Exception {
    FormattedEmailAlertSender emailAlertSender = new FormattedEmailAlertSender(new EmailConfiguration(), 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("<No backlog>\n").doesNotContain("Last messages accounting for this alert:\n");
}
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 2 with EmailConfiguration

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

the class FormattedEmailAlertSenderTest method defaultBodyTemplateShowsBacklogIfBacklogIsNotEmpty.

@Test
public void defaultBodyTemplateShowsBacklogIfBacklogIsNotEmpty() throws Exception {
    FormattedEmailAlertSender emailAlertSender = new FormattedEmailAlertSender(new EmailConfiguration(), 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);
    Message message = new Message("Test", "source", new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
    String body = emailAlertSender.buildBody(stream, checkResult, Collections.singletonList(message));
    assertThat(body).doesNotContain("<No backlog>\n").containsSequence("Last messages accounting for this alert:\n", message.toString());
}
Also used : Message(org.graylog2.plugin.Message) 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 3 with EmailConfiguration

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

the class FormattedEmailAlertSenderTest method buildBodyContainsInfoMessageIfWebInterfaceURLIsNotSet.

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

        @Override
        public URI getWebInterfaceUri() {
            return null;
        }
    };
    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 4 with EmailConfiguration

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

the class FormattedEmailAlertSenderTest method buildBodyContainsURLIfWebInterfaceURLIsSet.

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

        @Override
        public URI getWebInterfaceUri() {
            return URI.create("https://localhost");
        }
    };
    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: https://localhost/streams/123456/");
}
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 5 with EmailConfiguration

use of org.graylog2.configuration.EmailConfiguration 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)

Aggregations

EmailConfiguration (org.graylog2.configuration.EmailConfiguration)5 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)5 Stream (org.graylog2.plugin.streams.Stream)5 DateTime (org.joda.time.DateTime)5 Test (org.junit.Test)5 Message (org.graylog2.plugin.Message)1