Search in sources :

Example 1 with AlertManagerConfig

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());
    }
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired)

Example 2 with AlertManagerConfig

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);
}
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 3 with AlertManagerConfig

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

Example 4 with AlertManagerConfig

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);
}
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 5 with AlertManagerConfig

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

Aggregations

AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)53 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)22 Test (org.junit.Test)19 EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)8 ArrayList (java.util.ArrayList)8 AlertManagerDuplicateEntryException (io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Route (io.hops.hopsworks.alerting.config.dto.Route)5 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)5 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)4 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)4 AlertManagerConfigEntity (io.hops.hopsworks.persistence.entity.alertmanager.AlertManagerConfigEntity)4 AlertReceiver (io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver)4 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)3 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)3 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)3 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)3 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)3 File (java.io.File)3 Date (java.util.Date)3