Commit 74c1089d by Johannes Edmeier

Remove PagerdutyNotifier

parent 14cbcec5
...@@ -15,8 +15,18 @@ ...@@ -15,8 +15,18 @@
*/ */
package de.codecentric.boot.admin.config; package de.codecentric.boot.admin.config;
import java.util.List; import de.codecentric.boot.admin.notify.CompositeNotifier;
import de.codecentric.boot.admin.notify.HipchatNotifier;
import de.codecentric.boot.admin.notify.LetsChatNotifier;
import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.notify.Notifier;
import de.codecentric.boot.admin.notify.NotifierListener;
import de.codecentric.boot.admin.notify.SlackNotifier;
import de.codecentric.boot.admin.notify.filter.FilteringNotifier;
import de.codecentric.boot.admin.notify.filter.web.NotificationFilterController;
import de.codecentric.boot.admin.web.PrefixHandlerMapping;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
...@@ -33,145 +43,116 @@ import org.springframework.context.annotation.Configuration; ...@@ -33,145 +43,116 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.mail.MailSender; import org.springframework.mail.MailSender;
import de.codecentric.boot.admin.notify.CompositeNotifier;
import de.codecentric.boot.admin.notify.HipchatNotifier;
import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.notify.Notifier;
import de.codecentric.boot.admin.notify.NotifierListener;
import de.codecentric.boot.admin.notify.PagerdutyNotifier;
import de.codecentric.boot.admin.notify.SlackNotifier;
import de.codecentric.boot.admin.notify.LetsChatNotifier;
import de.codecentric.boot.admin.notify.filter.FilteringNotifier;
import de.codecentric.boot.admin.notify.filter.web.NotificationFilterController;
import de.codecentric.boot.admin.web.PrefixHandlerMapping;
@Configuration @Configuration
public class NotifierConfiguration { public class NotifierConfiguration {
@Configuration @Configuration
@ConditionalOnBean(Notifier.class) @ConditionalOnBean(Notifier.class)
public static class NotifierListenerConfiguration { public static class NotifierListenerConfiguration {
@Autowired @Autowired
private Notifier notifier; private Notifier notifier;
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public NotifierListener notifierListener() { public NotifierListener notifierListener() {
return new NotifierListener(notifier); return new NotifierListener(notifier);
} }
} }
@Configuration @Configuration
@ConditionalOnBean(Notifier.class) @ConditionalOnBean(Notifier.class)
@AutoConfigureBefore({ NotifierListenerConfiguration.class }) @AutoConfigureBefore({NotifierListenerConfiguration.class})
public static class CompositeNotifierConfiguration { public static class CompositeNotifierConfiguration {
@Bean @Bean
@Primary @Primary
@Conditional(NoSingleNotifierCandidateCondition.class) @Conditional(NoSingleNotifierCandidateCondition.class)
public CompositeNotifier compositeNotifier(List<Notifier> notifiers) { public CompositeNotifier compositeNotifier(List<Notifier> notifiers) {
return new CompositeNotifier(notifiers); return new CompositeNotifier(notifiers);
} }
static class NoSingleNotifierCandidateCondition extends NoneNestedConditions { static class NoSingleNotifierCandidateCondition extends NoneNestedConditions {
NoSingleNotifierCandidateCondition() { NoSingleNotifierCandidateCondition() {
super(ConfigurationPhase.REGISTER_BEAN); super(ConfigurationPhase.REGISTER_BEAN);
} }
@ConditionalOnSingleCandidate(Notifier.class) @ConditionalOnSingleCandidate(Notifier.class)
static class HasSingleNotifierInstance { static class HasSingleNotifierInstance {
} }
} }
} }
@Configuration @Configuration
@ConditionalOnSingleCandidate(FilteringNotifier.class) @ConditionalOnSingleCandidate(FilteringNotifier.class)
public static class FilteringNotifierWebConfiguration { public static class FilteringNotifierWebConfiguration {
@Autowired @Autowired
private FilteringNotifier filteringNotifier; private FilteringNotifier filteringNotifier;
@Autowired @Autowired
private AdminServerProperties adminServerProperties; private AdminServerProperties adminServer;
@Bean @Bean
public NotificationFilterController notificationFilterController() { public NotificationFilterController notificationFilterController() {
return new NotificationFilterController(filteringNotifier); return new NotificationFilterController(filteringNotifier);
} }
@Bean @Bean
public PrefixHandlerMapping prefixHandlerMappingNotificationFilterController() { public PrefixHandlerMapping prefixHandlerMappingNotificationFilterController() {
PrefixHandlerMapping prefixHandlerMapping = new PrefixHandlerMapping(notificationFilterController()); PrefixHandlerMapping prefixHandlerMapping = new PrefixHandlerMapping(notificationFilterController());
prefixHandlerMapping.setPrefix(adminServerProperties.getContextPath()); prefixHandlerMapping.setPrefix(adminServer.getContextPath());
return prefixHandlerMapping; return prefixHandlerMapping;
} }
} }
@Configuration @Configuration
@ConditionalOnBean(MailSender.class) @ConditionalOnBean(MailSender.class)
@AutoConfigureAfter({ MailSenderAutoConfiguration.class }) @AutoConfigureAfter({MailSenderAutoConfiguration.class})
@AutoConfigureBefore({ NotifierListenerConfiguration.class, @AutoConfigureBefore({NotifierListenerConfiguration.class, CompositeNotifierConfiguration.class})
CompositeNotifierConfiguration.class }) public static class MailNotifierConfiguration {
public static class MailNotifierConfiguration { @Autowired
@Autowired private MailSender mailSender;
private MailSender mailSender;
@Bean
@Bean @ConditionalOnMissingBean
@ConditionalOnMissingBean @ConfigurationProperties("spring.boot.admin.notify.mail")
@ConfigurationProperties("spring.boot.admin.notify.mail") public MailNotifier mailNotifier() {
public MailNotifier mailNotifier() { return new MailNotifier(mailSender);
return new MailNotifier(mailSender); }
} }
}
@Configuration
@Configuration @ConditionalOnProperty(prefix = "spring.boot.admin.notify.hipchat", name = "url")
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.pagerduty", name = "service-key") @AutoConfigureBefore({NotifierListenerConfiguration.class, CompositeNotifierConfiguration.class})
@AutoConfigureBefore({ NotifierListenerConfiguration.class, public static class HipchatNotifierConfiguration {
CompositeNotifierConfiguration.class }) @Bean
public static class PagerdutyNotifierConfiguration { @ConditionalOnMissingBean
@Bean @ConfigurationProperties("spring.boot.admin.notify.hipchat")
@ConditionalOnMissingBean public HipchatNotifier hipchatNotifier() {
@ConfigurationProperties("spring.boot.admin.notify.pagerduty") return new HipchatNotifier();
public PagerdutyNotifier pagerdutyNotifier() { }
return new PagerdutyNotifier(); }
}
} @Configuration
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.slack", name = "webhook-url")
@Configuration @AutoConfigureBefore({NotifierListenerConfiguration.class, CompositeNotifierConfiguration.class})
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.hipchat", name = "url") public static class SlackNotifierConfiguration {
@AutoConfigureBefore({ NotifierListenerConfiguration.class, @Bean
CompositeNotifierConfiguration.class }) @ConditionalOnMissingBean
public static class HipchatNotifierConfiguration { @ConfigurationProperties("spring.boot.admin.notify.slack")
@Bean public SlackNotifier slackNotifier() {
@ConditionalOnMissingBean return new SlackNotifier();
@ConfigurationProperties("spring.boot.admin.notify.hipchat") }
public HipchatNotifier hipchatNotifier() { }
return new HipchatNotifier();
} @Configuration
} @ConditionalOnProperty(prefix = "spring.boot.admin.notify.letschat", name = "url")
@AutoConfigureBefore({NotifierListenerConfiguration.class, CompositeNotifierConfiguration.class})
@Configuration public static class LetsChatNotifierConfiguration {
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.slack", name = "webhook-url") @Bean
@AutoConfigureBefore({ NotifierListenerConfiguration.class, @ConditionalOnMissingBean
CompositeNotifierConfiguration.class }) @ConfigurationProperties("spring.boot.admin.notify.letschat")
public static class SlackNotifierConfiguration { public LetsChatNotifier letsChatNotifier() {
@Bean return new LetsChatNotifier();
@ConditionalOnMissingBean }
@ConfigurationProperties("spring.boot.admin.notify.slack") }
public SlackNotifier slackNotifier() {
return new SlackNotifier();
}
}
@Configuration
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.letschat", name = "url")
@AutoConfigureBefore({ NotifierListenerConfiguration.class,
CompositeNotifierConfiguration.class })
public static class LetsChatNotifierConfiguration {
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties("spring.boot.admin.notify.letschat")
public LetsChatNotifier letsChatNotifier() {
return new LetsChatNotifier();
}
}
} }
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.notify;
import static java.util.Collections.singletonList;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.web.client.RestTemplate;
import de.codecentric.boot.admin.event.ClientApplicationEvent;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
/**
* Notifier submitting events to Pagerduty.
*
* @author Johannes Edmeier
*/
public class PagerdutyNotifier extends AbstractStatusChangeNotifier {
public static final URI DEFAULT_URI = URI
.create("https://events.pagerduty.com/generic/2010-04-15/create_event.json");
private static final String DEFAULT_DESCRIPTION = "#{application.name}/#{application.id} is #{to.status}";
private final SpelExpressionParser parser = new SpelExpressionParser();
private RestTemplate restTemplate = new RestTemplate();
/**
* URI for pagerduty-REST-API
*/
private URI url = DEFAULT_URI;
/**
* Service-Key for pagerduty-REST-API
*/
private String serviceKey;
/**
* Client for pagerduty-REST-API
*/
private String client;
/**
* Client-url for pagerduty-REST-API
*/
private URI clientUrl;
/**
* Trigger description. SpEL template using event as root;
*/
private Expression description;
public PagerdutyNotifier() {
this.description = parser.parseExpression(DEFAULT_DESCRIPTION,
ParserContext.TEMPLATE_EXPRESSION);
}
@Override
protected void doNotify(ClientApplicationEvent event) throws Exception {
restTemplate.postForEntity(url, createPagerdutyEvent(event), Void.class);
}
protected Map<String, Object> createPagerdutyEvent(ClientApplicationEvent event) {
Map<String, Object> result = new HashMap<>();
result.put("service_key", serviceKey);
result.put("incident_key",
event.getApplication().getName() + "/" + event.getApplication().getId());
result.put("description", getDescription(event));
Map<String, Object> details = getDetails(event);
result.put("details", details);
if (event instanceof ClientApplicationStatusChangedEvent) {
if ("UP".equals(((ClientApplicationStatusChangedEvent) event).getTo().getStatus())) {
result.put("event_type", "resolve");
} else {
result.put("event_type", "trigger");
if (client != null) {
result.put("client", client);
}
if (clientUrl != null) {
result.put("client_url", clientUrl);
}
Map<String, Object> context = new HashMap<>();
context.put("type", "link");
context.put("href", event.getApplication().getHealthUrl());
context.put("text", "Application health-endpoint");
result.put("contexts", singletonList(context));
}
}
return result;
}
protected String getDescription(ClientApplicationEvent event) {
return description.getValue(event, String.class);
}
protected Map<String, Object> getDetails(ClientApplicationEvent event) {
Map<String, Object> details = new HashMap<>();
if (event instanceof ClientApplicationStatusChangedEvent) {
details.put("from", ((ClientApplicationStatusChangedEvent) event).getFrom());
details.put("to", ((ClientApplicationStatusChangedEvent) event).getTo());
}
return details;
}
public void setUrl(URI url) {
this.url = url;
}
public URI getUrl() {
return url;
}
public void setClient(String client) {
this.client = client;
}
public String getClient() {
return client;
}
public void setClientUrl(URI clientUrl) {
this.clientUrl = clientUrl;
}
public URI getClientUrl() {
return clientUrl;
}
public void setServiceKey(String serviceKey) {
this.serviceKey = serviceKey;
}
public String getServiceKey() {
return serviceKey;
}
public void setDescription(String description) {
this.description = parser.parseExpression(description, ParserContext.TEMPLATE_EXPRESSION);
}
public String getDescription() {
return description.getExpressionString();
}
public void setRestTemplate(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
}
...@@ -15,11 +15,19 @@ ...@@ -15,11 +15,19 @@
*/ */
package de.codecentric.boot.admin.config; package de.codecentric.boot.admin.config;
import static org.assertj.core.api.Assertions.assertThat; import de.codecentric.boot.admin.event.ClientApplicationEvent;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.model.StatusInfo;
import de.codecentric.boot.admin.notify.CompositeNotifier;
import de.codecentric.boot.admin.notify.HipchatNotifier;
import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.notify.Notifier;
import de.codecentric.boot.admin.notify.NotifierListener;
import de.codecentric.boot.admin.notify.SlackNotifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration; import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
...@@ -28,139 +36,125 @@ import org.springframework.context.annotation.Bean; ...@@ -28,139 +36,125 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import de.codecentric.boot.admin.event.ClientApplicationEvent; import static org.assertj.core.api.Assertions.assertThat;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.model.StatusInfo;
import de.codecentric.boot.admin.notify.CompositeNotifier;
import de.codecentric.boot.admin.notify.HipchatNotifier;
import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.notify.Notifier;
import de.codecentric.boot.admin.notify.NotifierListener;
import de.codecentric.boot.admin.notify.PagerdutyNotifier;
import de.codecentric.boot.admin.notify.SlackNotifier;
public class NotifierConfigurationTest { public class NotifierConfigurationTest {
private static final ClientApplicationEvent APP_DOWN = new ClientApplicationStatusChangedEvent( private static final ClientApplicationEvent APP_DOWN = new ClientApplicationStatusChangedEvent(
Application.create("App").withId("id-1").withHealthUrl("http://health") Application.create("App")
.withStatusInfo(StatusInfo.ofDown()).build(), .withId("id-1")
StatusInfo.ofUp(), StatusInfo.ofDown()); .withHealthUrl("http://health")
.withStatusInfo(StatusInfo.ofDown())
private AnnotationConfigWebApplicationContext context; .build(), StatusInfo.ofUp(), StatusInfo.ofDown());
@After private AnnotationConfigWebApplicationContext context;
public void close() {
if (this.context != null) { @After
this.context.close(); public void close() {
} if (this.context != null) {
} this.context.close();
}
@Test }
public void test_notifierListener() {
load(TestSingleNotifierConfig.class); @Test
context.publishEvent(APP_DOWN); public void test_notifierListener() {
assertThat(context.getBean(TestNotifier.class).getEvents()).containsOnly(APP_DOWN); load(TestSingleNotifierConfig.class);
} context.publishEvent(APP_DOWN);
assertThat(context.getBean(TestNotifier.class).getEvents()).containsOnly(APP_DOWN);
@Test }
public void test_no_notifierListener() {
load(null); @Test
assertThat(context.getBeansOfType(NotifierListener.class)).isEmpty(); public void test_no_notifierListener() {
} load(null);
assertThat(context.getBeansOfType(NotifierListener.class)).isEmpty();
@Test }
public void test_mail() {
load(null, "spring.mail.host:localhost"); @Test
assertThat(context.getBean(MailNotifier.class)).isInstanceOf(MailNotifier.class); public void test_mail() {
} load(null, "spring.mail.host:localhost");
assertThat(context.getBean(MailNotifier.class)).isInstanceOf(MailNotifier.class);
@Test }
public void test_pagerduty() {
load(null, "spring.boot.admin.notify.pagerduty.service-key:foo"); @Test
assertThat(context.getBean(PagerdutyNotifier.class)).isInstanceOf(PagerdutyNotifier.class); public void test_hipchat() {
} load(null, "spring.boot.admin.notify.hipchat.url:http://example.com");
assertThat(context.getBean(HipchatNotifier.class)).isInstanceOf(HipchatNotifier.class);
@Test }
public void test_hipchat() {
load(null, "spring.boot.admin.notify.hipchat.url:http://example.com"); @Test
assertThat(context.getBean(HipchatNotifier.class)).isInstanceOf(HipchatNotifier.class); public void test_slack() {
} load(null, "spring.boot.admin.notify.slack.webhook-url:http://example.com");
assertThat(context.getBean(SlackNotifier.class)).isInstanceOf(SlackNotifier.class);
@Test }
public void test_slack() {
load(null, "spring.boot.admin.notify.slack.webhook-url:http://example.com"); @Test
assertThat(context.getBean(SlackNotifier.class)).isInstanceOf(SlackNotifier.class); public void test_multipleNotifiers() {
} load(TestMultipleNotifierConfig.class);
assertThat(context.getBean(Notifier.class)).isInstanceOf(CompositeNotifier.class);
@Test assertThat(context.getBeansOfType(Notifier.class)).hasSize(3);
public void test_multipleNotifiers() { }
load(TestMultipleNotifierConfig.class);
assertThat(context.getBean(Notifier.class)).isInstanceOf(CompositeNotifier.class); @Test
assertThat(context.getBeansOfType(Notifier.class)).hasSize(3); public void test_multipleNotifiersWithPrimary() {
} load(TestMultipleWithPrimaryNotifierConfig.class);
assertThat(context.getBean(Notifier.class)).isInstanceOf(TestNotifier.class);
@Test assertThat(context.getBeansOfType(Notifier.class)).hasSize(2);
public void test_multipleNotifiersWithPrimary() { }
load(TestMultipleWithPrimaryNotifierConfig.class);
assertThat(context.getBean(Notifier.class)).isInstanceOf(TestNotifier.class); private void load(Class<?> config, String... environment) {
assertThat(context.getBeansOfType(Notifier.class)).hasSize(2); context = new AnnotationConfigWebApplicationContext();
} if (config != null) {
context.register(config);
private void load(Class<?> config, String... environment) { }
context = new AnnotationConfigWebApplicationContext(); context.register(MailSenderAutoConfiguration.class);
if (config != null) { context.register(NotifierConfiguration.class);
context.register(config);
} EnvironmentTestUtils.addEnvironment(context, environment);
context.register(MailSenderAutoConfiguration.class); context.refresh();
context.register(NotifierConfiguration.class); }
EnvironmentTestUtils.addEnvironment(context, environment); public static class TestSingleNotifierConfig {
context.refresh(); @Bean
} public Notifier testNotifier() {
return new TestNotifier();
public static class TestSingleNotifierConfig { }
@Bean
public Notifier testNotifier() { }
return new TestNotifier();
} private static class TestMultipleNotifierConfig {
@Bean
} public Notifier testNotifier1() {
return new TestNotifier();
private static class TestMultipleNotifierConfig { }
@Bean
public Notifier testNotifier1() { @Bean
return new TestNotifier(); public Notifier testNotifier2() {
} return new TestNotifier();
}
@Bean }
public Notifier testNotifier2() {
return new TestNotifier(); private static class TestMultipleWithPrimaryNotifierConfig {
} @Bean
} @Primary
public Notifier testNotifierPrimary() {
private static class TestMultipleWithPrimaryNotifierConfig { return new TestNotifier();
@Bean }
@Primary
public Notifier testNotifierPrimary() { @Bean
return new TestNotifier(); public Notifier testNotifier2() {
} return new TestNotifier();
}
@Bean }
public Notifier testNotifier2() {
return new TestNotifier(); private static class TestNotifier implements Notifier {
} private List<ClientApplicationEvent> events = new ArrayList<>();
}
@Override
private static class TestNotifier implements Notifier { public void notify(ClientApplicationEvent event) {
private List<ClientApplicationEvent> events = new ArrayList<>(); this.events.add(event);
}
@Override
public void notify(ClientApplicationEvent event) { public List<ClientApplicationEvent> getEvents() {
this.events.add(event); return events;
} }
}
public List<ClientApplicationEvent> getEvents() {
return events;
}
}
} }
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.notify;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.web.client.RestTemplate;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.model.StatusInfo;
public class PagerdutyNotifierTest {
private PagerdutyNotifier notifier;
private RestTemplate restTemplate;
@Before
public void setUp() {
restTemplate = mock(RestTemplate.class);
notifier = new PagerdutyNotifier();
notifier.setServiceKey("--service--");
notifier.setClient("TestClient");
notifier.setClientUrl(URI.create("http://localhost"));
notifier.setRestTemplate(restTemplate);
}
@Test
public void test_onApplicationEvent_resolve() {
StatusInfo infoDown = StatusInfo.ofDown();
StatusInfo infoUp = StatusInfo.ofUp();
notifier.notify(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
infoDown, infoUp));
Map<String, Object> expected = new HashMap<String, Object>();
expected.put("service_key", "--service--");
expected.put("incident_key", "App/-id-");
expected.put("event_type", "resolve");
expected.put("description", "App/-id- is UP");
Map<String, Object> details = new HashMap<String, Object>();
details.put("from", infoDown);
details.put("to", infoUp);
expected.put("details", details);
verify(restTemplate).postForEntity(eq(PagerdutyNotifier.DEFAULT_URI), eq(expected),
eq(Void.class));
}
@Test
public void test_onApplicationEvent_trigger() {
StatusInfo infoDown = StatusInfo.ofDown();
StatusInfo infoUp = StatusInfo.ofUp();
notifier.notify(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
infoUp, infoDown));
Map<String, Object> expected = new HashMap<String, Object>();
expected.put("service_key", "--service--");
expected.put("incident_key", "App/-id-");
expected.put("event_type", "trigger");
expected.put("description", "App/-id- is DOWN");
expected.put("client", "TestClient");
expected.put("client_url", URI.create("http://localhost"));
Map<String, Object> details = new HashMap<String, Object>();
details.put("from", infoUp);
details.put("to", infoDown);
expected.put("details", details);
Map<String, Object> context = new HashMap<String, Object>();
context.put("type", "link");
context.put("href", "http://health");
context.put("text", "Application health-endpoint");
expected.put("contexts", Arrays.asList(context));
verify(restTemplate).postForEntity(eq(PagerdutyNotifier.DEFAULT_URI), eq(expected),
eq(Void.class));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment