Search in sources :

Example 6 with EmailConfig

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;
}
Also used : SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) PagerdutyConfig(io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)

Example 7 with EmailConfig

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;
}
Also used : Entry(io.hops.hopsworks.api.alert.Entry) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig)

Example 8 with 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);
    });
}
Also used : EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 9 with EmailConfig

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);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 10 with EmailConfig

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);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ArrayList(java.util.ArrayList) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Aggregations

EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)13 Test (org.junit.Test)11 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)10 ArrayList (java.util.ArrayList)8 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)6 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)1 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)1 Entry (io.hops.hopsworks.api.alert.Entry)1 AlertReceiver (io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver)1