use of org.graylog2.plugin.alarms.AlertCondition 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, emailFactory);
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.plugin.alarms.AlertCondition 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, emailFactory);
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.plugin.alarms.AlertCondition 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, emailFactory);
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.plugin.alarms.AlertCondition in project graylog2-server by Graylog2.
the class V20161125142400_EmailAlarmCallbackMigrationTest method doMigrateMultipleQualifyingStreams.
@Test
public void doMigrateMultipleQualifyingStreams() throws Exception {
final String matchingStreamId1 = "matchingStreamId1";
final String matchingStreamId2 = "matchingStreamId2";
final Stream stream1 = mock(Stream.class);
when(stream1.getAlertReceivers()).thenReturn(Collections.emptyMap());
final Stream stream2 = mock(Stream.class);
when(stream2.getAlertReceivers()).thenReturn(ImmutableMap.of("users", ImmutableList.of("foouser"), "emails", ImmutableList.of("foo@bar.com")));
when(stream2.getId()).thenReturn(matchingStreamId1);
final Stream stream3 = mock(Stream.class);
when(stream3.getAlertReceivers()).thenReturn(ImmutableMap.of("users", ImmutableList.of("foouser2")));
when(stream3.getId()).thenReturn(matchingStreamId2);
when(this.streamService.loadAll()).thenReturn(ImmutableList.of(stream1, stream2, stream3));
final AlertCondition alertCondition1 = mock(AlertCondition.class);
final AlertCondition alertCondition2 = mock(AlertCondition.class);
when(this.streamService.getAlertConditions(eq(stream2))).thenReturn(ImmutableList.of(alertCondition1));
when(this.streamService.getAlertConditions(eq(stream3))).thenReturn(ImmutableList.of(alertCondition2));
final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
when(configurationRequest.getFields()).thenReturn(Collections.emptyMap());
final AlarmCallbackConfiguration newAlarmCallback1 = mock(AlarmCallbackConfiguration.class);
final String newAlarmCallbackId1 = "newAlarmCallbackId1";
final AlarmCallbackConfiguration newAlarmCallback2 = mock(AlarmCallbackConfiguration.class);
final String newAlarmCallbackId2 = "newAlarmCallbackId2";
when(alarmCallbackConfigurationService.create(eq(matchingStreamId1), any(CreateAlarmCallbackRequest.class), eq(localAdminId))).thenReturn(newAlarmCallback1);
when(alarmCallbackConfigurationService.create(eq(matchingStreamId2), any(CreateAlarmCallbackRequest.class), eq(localAdminId))).thenReturn(newAlarmCallback2);
when(alarmCallbackConfigurationService.save(eq(newAlarmCallback1))).thenReturn(newAlarmCallbackId1);
when(alarmCallbackConfigurationService.save(eq(newAlarmCallback2))).thenReturn(newAlarmCallbackId2);
this.emailAlarmCallbackMigrationPeriodical.upgrade();
final ArgumentCaptor<String> streamIdCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<CreateAlarmCallbackRequest> createAlarmCallbackRequestCaptor = ArgumentCaptor.forClass(CreateAlarmCallbackRequest.class);
final ArgumentCaptor<String> userIdCaptor = ArgumentCaptor.forClass(String.class);
verify(this.alarmCallbackConfigurationService, times(2)).create(streamIdCaptor.capture(), createAlarmCallbackRequestCaptor.capture(), userIdCaptor.capture());
assertThat(streamIdCaptor.getAllValues()).isNotNull().isNotEmpty().contains(matchingStreamId1).contains(matchingStreamId2);
createAlarmCallbackRequestCaptor.getAllValues().forEach(createAlarmCallbackRequest -> assertThat(createAlarmCallbackRequest.type()).isEqualTo(EmailAlarmCallback.class.getCanonicalName()));
final ArgumentCaptor<AlarmCallbackConfiguration> alarmCallbackConfigurationCaptor = ArgumentCaptor.forClass(AlarmCallbackConfiguration.class);
verify(this.alarmCallbackConfigurationService, times(2)).save(alarmCallbackConfigurationCaptor.capture());
assertThat(alarmCallbackConfigurationCaptor.getAllValues()).isNotNull().isNotEmpty().hasSize(2).contains(newAlarmCallback1).contains(newAlarmCallback2);
verifyMigrationCompletedWasPosted(ImmutableMap.of(matchingStreamId1, Optional.of(newAlarmCallbackId1), matchingStreamId2, Optional.of(newAlarmCallbackId2)));
}
use of org.graylog2.plugin.alarms.AlertCondition in project graylog2-server by Graylog2.
the class V20161125142400_EmailAlarmCallbackMigrationTest method doMigrateSingleQualifyingStream.
@Test
public void doMigrateSingleQualifyingStream() throws Exception {
final String matchingStreamId = "matchingStreamId";
final Stream stream1 = mock(Stream.class);
when(stream1.getAlertReceivers()).thenReturn(Collections.emptyMap());
final Stream stream2 = mock(Stream.class);
when(stream2.getAlertReceivers()).thenReturn(ImmutableMap.of("users", ImmutableList.of("foouser"), "emails", ImmutableList.of("foo@bar.com")));
when(stream2.getId()).thenReturn(matchingStreamId);
when(this.streamService.loadAll()).thenReturn(ImmutableList.of(stream1, stream2));
final AlertCondition alertCondition = mock(AlertCondition.class);
when(this.streamService.getAlertConditions(eq(stream2))).thenReturn(ImmutableList.of(alertCondition));
final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
when(configurationRequest.getFields()).thenReturn(Collections.emptyMap());
final AlarmCallbackConfiguration newAlarmCallback = mock(AlarmCallbackConfiguration.class);
final String newAlarmCallbackId = "newAlarmCallbackId";
when(alarmCallbackConfigurationService.create(eq(matchingStreamId), any(CreateAlarmCallbackRequest.class), eq(localAdminId))).thenReturn(newAlarmCallback);
when(alarmCallbackConfigurationService.save(eq(newAlarmCallback))).thenReturn(newAlarmCallbackId);
this.emailAlarmCallbackMigrationPeriodical.upgrade();
final ArgumentCaptor<String> streamIdCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<CreateAlarmCallbackRequest> createAlarmCallbackRequestCaptor = ArgumentCaptor.forClass(CreateAlarmCallbackRequest.class);
final ArgumentCaptor<String> userIdCaptor = ArgumentCaptor.forClass(String.class);
verify(this.alarmCallbackConfigurationService, times(1)).create(streamIdCaptor.capture(), createAlarmCallbackRequestCaptor.capture(), userIdCaptor.capture());
assertThat(streamIdCaptor.getValue()).isNotNull().isNotEmpty().isEqualTo(matchingStreamId);
final CreateAlarmCallbackRequest createAlarmCallbackRequest = createAlarmCallbackRequestCaptor.getValue();
assertThat(createAlarmCallbackRequest.type()).isEqualTo(EmailAlarmCallback.class.getCanonicalName());
final ArgumentCaptor<AlarmCallbackConfiguration> alarmCallbackConfigurationCaptor = ArgumentCaptor.forClass(AlarmCallbackConfiguration.class);
verify(this.alarmCallbackConfigurationService, times(1)).save(alarmCallbackConfigurationCaptor.capture());
assertThat(alarmCallbackConfigurationCaptor.getValue()).isEqualTo(newAlarmCallback);
verifyMigrationCompletedWasPosted(ImmutableMap.of(matchingStreamId, Optional.of(newAlarmCallbackId)));
}
Aggregations