use of io.hops.hopsworks.alerting.config.dto.AlertManagerConfig in project hopsworks by logicalclocks.
the class ManagementResource method updateConfig.
@POST
@Path("config")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateConfig(PostableAlertManagerConfig config, @Context SecurityContext sc) throws AlertException {
try {
AlertManagerConfig alertManagerConfig = toAlertManagerConfig(config);
alertManagerConfiguration.writeAndReload(alertManagerConfig);
alertManagerConfig = alertManagerConfiguration.read();
return Response.ok().entity(alertManagerConfig).build();
} catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
} catch (AlertManagerConfigUpdateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
} catch (AlertManagerClientCreateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
} catch (IllegalArgumentException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
}
}
use of io.hops.hopsworks.alerting.config.dto.AlertManagerConfig 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.AlertManagerConfig in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testAddPagerdutyToReceiver.
@Test
public void testAddPagerdutyToReceiver() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerNoSuchElementException, AlertManagerConfigReadException, AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
PagerdutyConfig pagerdutyConfig = new PagerdutyConfig().withServiceKey("serviceKey");
Receiver receiver = new Receiver("team-DB-pager");
AlertManagerConfig config = alertManagerConfigController.addPagerdutyToReceiver("team-DB-pager", pagerdutyConfig);
alertManagerConfigController.writeAndReload(config);
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
int index = alertManagerConfig.getReceivers().indexOf(receiver);
Receiver updatedReceiver = alertManagerConfig.getReceivers().get(index);
assert updatedReceiver.getPagerdutyConfigs().contains(pagerdutyConfig);
}
use of io.hops.hopsworks.alerting.config.dto.AlertManagerConfig 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.AlertManagerConfig 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);
}
Aggregations