use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class AlertManagerConfigController method removePagerdutyFromReceiver.
/**
* @param name
* @param pagerdutyConfig
* @return updated AlertManagerConfig or null if it is not updated
* @throws AlertManagerNoSuchElementException
* @throws AlertManagerServerException
* @throws AlertManagerConfigReadException
*/
public AlertManagerConfig removePagerdutyFromReceiver(String name, PagerdutyConfig pagerdutyConfig) throws AlertManagerNoSuchElementException, AlertManagerConfigReadException {
AlertManagerConfig alertManagerConfig = read();
int index = getIndexOfReceiver(alertManagerConfig, name);
Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
index = receiverToUpdate.getPagerdutyConfigs() == null ? -1 : receiverToUpdate.getPagerdutyConfigs().indexOf(pagerdutyConfig);
if (index > -1) {
receiverToUpdate.getPagerdutyConfigs().remove(index);
return alertManagerConfig;
}
return null;
}
use of io.hops.hopsworks.alerting.config.dto.Receiver 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.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testAddDuplicateReceiver.
@Test
public void testAddDuplicateReceiver() throws AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
List<EmailConfig> emailConfigList = new ArrayList<>();
emailConfigList.add(new EmailConfig("ermias@kth.se"));
Receiver receiver = new Receiver("team-X-mails").withEmailConfigs(emailConfigList);
Assert.assertThrows(AlertManagerDuplicateEntryException.class, () -> {
alertManagerConfigController.addReceiver(receiver);
});
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testUpdateReceiverRollbackServerException.
@Test
public void testUpdateReceiverRollbackServerException() throws AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException {
Mockito.when(client.reload()).thenThrow(AlertManagerServerException.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(AlertManagerServerException.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.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testUpdateReceiver.
@Test
public void testUpdateReceiver() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerNoSuchElementException, AlertManagerConfigReadException, AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
EmailConfig emailConfig = new EmailConfig("team-Y+alerts@example.org");
List<EmailConfig> emailConfigList = new ArrayList<>();
emailConfigList.add(emailConfig);
Receiver receiver = new Receiver("team-Y-mail").withEmailConfigs(emailConfigList);
AlertManagerConfig config = alertManagerConfigController.updateReceiver("team-Y-mails", receiver);
alertManagerConfigController.writeAndReload(config);
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
int index = alertManagerConfig.getReceivers().indexOf(receiver);
assert index > -1;
Receiver updatedReceiver = alertManagerConfig.getReceivers().get(index);
assert updatedReceiver.getEmailConfigs().contains(emailConfig);
}
Aggregations