use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.
the class TestAlertManagerConfigTimer method createReceivers.
private List<AlertReceiver> createReceivers() throws JsonProcessingException {
List<AlertReceiver> alertReceivers = new ArrayList<>();
List<EmailConfig> emailConfigs = new ArrayList<>();
emailConfigs.add(new EmailConfig("test@hopsworks.ai"));
List<SlackConfig> slackConfigs = new ArrayList<>();
slackConfigs.add(new SlackConfig().withChannel("@test"));
List<PagerdutyConfig> pagerdutyConfigs = new ArrayList<>();
pagerdutyConfigs.add(new PagerdutyConfig("serviceKey"));
alertReceivers.add(createAlertReceiver(1, new Receiver("global-receiver__email").withEmailConfigs(emailConfigs), AlertType.GLOBAL_ALERT_EMAIL));
alertReceivers.add(createAlertReceiver(2, new Receiver("project1__slack").withSlackConfigs(slackConfigs), AlertType.PROJECT_ALERT));
alertReceivers.add(createAlertReceiver(3, new Receiver("global-receiver__slack").withSlackConfigs(slackConfigs), AlertType.GLOBAL_ALERT_SLACK));
alertReceivers.add(createAlertReceiver(4, new Receiver("project1__pagerduty").withPagerdutyConfigs(pagerdutyConfigs), AlertType.PROJECT_ALERT));
return alertReceivers;
}
use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.
the class ReceiverBuilder method toEmailConfig.
private EmailConfig toEmailConfig(PostableEmailConfig postableEmailConfigs, Boolean defaultTemplate) {
EmailConfig emailConfig = new EmailConfig(postableEmailConfigs.getTo()).withFrom(postableEmailConfigs.getFrom()).withSmarthost(postableEmailConfigs.getSmarthost()).withHello(postableEmailConfigs.getHello()).withAuthIdentity(postableEmailConfigs.getAuthIdentity()).withAuthPassword(postableEmailConfigs.getAuthPassword()).withAuthSecret(postableEmailConfigs.getAuthSecret()).withAuthUsername(postableEmailConfigs.getAuthUsername()).withHtml(postableEmailConfigs.getHtml()).withText(postableEmailConfigs.getText()).withRequireTls(postableEmailConfigs.getRequireTls()).withTlsConfig(postableEmailConfigs.getTlsConfig()).withSendResolved(postableEmailConfigs.getSendResolved());
if (postableEmailConfigs.getHeaders() != null && !postableEmailConfigs.getHeaders().isEmpty()) {
Map<String, String> headers;
headers = postableEmailConfigs.getHeaders().stream().filter(entry -> entry != null && entry.getKey() != null && entry.getValue() != null).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
emailConfig.setHeaders(headers);
}
if (defaultTemplate && Strings.isNullOrEmpty(emailConfig.getHtml())) {
emailConfig.setHtml(Constants.DEFAULT_EMAIL_HTML);
}
return emailConfig;
}
use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testAddReceiverValidation.
@Test
public void testAddReceiverValidation() throws AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
List<EmailConfig> emailConfigList = new ArrayList<>();
Receiver receiver = new Receiver();
Assert.assertThrows(IllegalArgumentException.class, () -> {
alertManagerConfigController.addReceiver(receiver);
});
Receiver receiver1 = new Receiver("team-Z-email").withEmailConfigs(emailConfigList);
Assert.assertThrows(IllegalArgumentException.class, () -> {
alertManagerConfigController.addReceiver(receiver1);
});
}
use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testUpdateReceiverRollback.
@Test
public void testUpdateReceiverRollback() throws AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException {
Mockito.when(client.reload()).thenThrow(AlertManagerResponseException.class);
List<EmailConfig> emailConfigList = new ArrayList<>();
emailConfigList.add(new EmailConfig("team-Z+alerts@example.org"));
Receiver receiver = new Receiver("team-Z-email").withEmailConfigs(emailConfigList);
Assert.assertThrows(AlertManagerConfigUpdateException.class, () -> {
AlertManagerConfig config = alertManagerConfigController.addReceiver(receiver);
alertManagerConfigController.writeAndReload(config);
});
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
assert !alertManagerConfig.getReceivers().contains(receiver);
}
use of io.hops.hopsworks.alerting.config.dto.EmailConfig in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testAddReceiverEmail.
@Test
public void testAddReceiverEmail() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
List<EmailConfig> emailConfigList = new ArrayList<>();
emailConfigList.add(new EmailConfig("team-Z+alerts@example.org"));
Receiver receiver = new Receiver("team-Z-email").withEmailConfigs(emailConfigList);
AlertManagerConfig config = alertManagerConfigController.addReceiver(receiver);
alertManagerConfigController.writeAndReload(config);
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
assert alertManagerConfig.getReceivers().contains(receiver);
}
Aggregations