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");
}
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());
}
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.");
}
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/");
}
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.");
}
Aggregations