Search in sources :

Example 6 with Receiver

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

Example 7 with Receiver

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);
}
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 8 with 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);
    });
}
Also used : 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 9 with 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);
}
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 10 with 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);
}
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)

Aggregations

Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)34 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)21 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 EmailConfig (io.hops.hopsworks.alerting.config.dto.EmailConfig)11 AlertManagerDuplicateEntryException (io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)9 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)7 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)7 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)7 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)7 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)7 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)6 AlertException (io.hops.hopsworks.exceptions.AlertException)6 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)6 ApiOperation (io.swagger.annotations.ApiOperation)6 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 SlackConfig (io.hops.hopsworks.alerting.config.dto.SlackConfig)5 AlertManagerNoSuchElementException (io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException)5 PagerdutyConfig (io.hops.hopsworks.alerting.config.dto.PagerdutyConfig)4