Search in sources :

Example 1 with SlackConfig

use of io.hops.hopsworks.alerting.config.dto.SlackConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testRemoveSlackFromReceiver.

@Test
public void testRemoveSlackFromReceiver() throws AlertManagerConfigUpdateException, AlertManagerNoSuchElementException, AlertManagerConfigReadException, AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    SlackConfig slackConfig = new SlackConfig("https://hooks.slack.com/services/12345678901/0987654321", "#offtopic");
    Receiver receiver = new Receiver("slack_general");
    AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
    int index = alertManagerConfig.getReceivers().indexOf(receiver);
    Receiver updatedReceiver = alertManagerConfig.getReceivers().get(index);
    assert updatedReceiver.getSlackConfigs().contains(slackConfig);
    AlertManagerConfig config = alertManagerConfigController.removeSlackFromReceiver("slack_general", slackConfig);
    alertManagerConfigController.writeAndReload(config);
    alertManagerConfig = this.alertManagerConfigController.read();
    index = alertManagerConfig.getReceivers().indexOf(receiver);
    updatedReceiver = alertManagerConfig.getReceivers().get(index);
    assert !updatedReceiver.getSlackConfigs().contains(slackConfig);
}
Also used : SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 2 with SlackConfig

use of io.hops.hopsworks.alerting.config.dto.SlackConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddSlackToReceiverValidation.

@Test
public void testAddSlackToReceiverValidation() throws AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    SlackConfig slackConfig = new SlackConfig("https://hooks.slack.com/services/1234567890/0987654321", null);
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        alertManagerConfigController.addSlackToReceiver("slack_general", slackConfig);
    });
    SlackConfig slackConfig1 = new SlackConfig(null, "#general");
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        alertManagerConfigController.addSlackToReceiver("slack_general", slackConfig1);
    });
    SlackConfig slackConfig2 = new SlackConfig();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        alertManagerConfigController.addSlackToReceiver("slack_general", slackConfig2);
    });
}
Also used : SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) Test(org.junit.Test)

Example 3 with SlackConfig

use of io.hops.hopsworks.alerting.config.dto.SlackConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddReceiverSlack.

@Test
public void testAddReceiverSlack() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    List<SlackConfig> slackConfigs = new ArrayList<>();
    slackConfigs.add(new SlackConfig("https://hooks.slack.com/services/1234567890/0987654321", "#general").withIconEmoji("https://gravatar.com/avatar/e3fb1c1d58b043af5e3a6a645b7f569f").withTitle("{{ template \"hopsworks.title\" . }}").withText("{{ template \"hopsworks.text\" . }}"));
    Receiver receiver = new Receiver("team-Z-slack").withSlackConfigs(slackConfigs);
    AlertManagerConfig config = alertManagerConfigController.addReceiver(receiver);
    alertManagerConfigController.writeAndReload(config);
    AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
    assert alertManagerConfig.getReceivers().contains(receiver);
}
Also used : SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) ArrayList(java.util.ArrayList) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Test(org.junit.Test)

Example 4 with SlackConfig

use of io.hops.hopsworks.alerting.config.dto.SlackConfig 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 5 with SlackConfig

use of io.hops.hopsworks.alerting.config.dto.SlackConfig in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddDuplicateSlackToReceiver.

@Test
public void testAddDuplicateSlackToReceiver() throws AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    SlackConfig slackConfig = new SlackConfig("https://hooks.slack.com/services/12345678901/e3fb1c1d58b043af5e3a6a645b7f569f", "#general").withIconEmoji("https://gravatar.com/avatar/e3fb1c1d58b043af5e3a6a645b7f569f").withTitle("{{ template \"hopsworks.title\" . }}").withText("{{ template \"hopsworks.text\" . }}");
    Assert.assertThrows(AlertManagerDuplicateEntryException.class, () -> {
        alertManagerConfigController.addSlackToReceiver("slack_general", slackConfig);
    });
}
Also used : SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) Test(org.junit.Test)

Aggregations

SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)6 Test (org.junit.Test)5 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)4 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)3 ArrayList (java.util.ArrayList)2 EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)1 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)1 AlertReceiver (io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver)1