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);
}
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);
});
}
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);
}
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;
}
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);
});
}
Aggregations