Commit 215f2a1d by Johannes Edmeier

Add pagerduty notification

parent 06e1423f
...@@ -32,7 +32,8 @@ public class AdminServerImportSelector implements DeferredImportSelector { ...@@ -32,7 +32,8 @@ public class AdminServerImportSelector implements DeferredImportSelector {
HazelcastStoreConfiguration.class.getCanonicalName(), HazelcastStoreConfiguration.class.getCanonicalName(),
AdminServerWebConfiguration.class.getCanonicalName(), AdminServerWebConfiguration.class.getCanonicalName(),
DiscoveryClientConfiguration.class.getCanonicalName(), DiscoveryClientConfiguration.class.getCanonicalName(),
RevereseZuulProxyConfiguration.class.getCanonicalName() }; RevereseZuulProxyConfiguration.class.getCanonicalName(),
PagerdutyNotifierConfiguration.class.getCanonicalName() };
} }
} }
...@@ -43,5 +43,4 @@ public class MailNotifierConfiguration { ...@@ -43,5 +43,4 @@ public class MailNotifierConfiguration {
public MailNotifier mailNotifier() { public MailNotifier mailNotifier() {
return new MailNotifier(mailSender); return new MailNotifier(mailSender);
} }
} }
\ No newline at end of file
/*
* 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.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import de.codecentric.boot.admin.notify.PagerdutyNotifier;
@Configuration
@ConditionalOnProperty("spring.boot.admin.notify.pagerduty.service-key")
public class PagerdutyNotifierConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.boot.admin.notify.pagerduty", name = "enabled", matchIfMissing = true)
@ConfigurationProperties("spring.boot.admin.notify.pagerduty")
public PagerdutyNotifier pagerdutyNotifier() {
return new PagerdutyNotifier();
}
}
\ No newline at end of file
package de.codecentric.boot.admin.notify;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
public abstract class AbstractNotifier {
/**
* List of changes to ignore. Must be in Format OLD:NEW, for any status use * as wildcard, e.g.
* *:UP or OFFLINE:*
*/
protected String[] ignoreChanges = { "UNKNOWN:UP" };
/**
* Enables the mail notification.
*/
private boolean enabled = true;
@EventListener
public void onClientApplicationStatusChanged(ClientApplicationStatusChangedEvent event) {
if (enabled && shouldNotify(event.getFrom().getStatus(), event.getTo().getStatus())) {
try {
notify(event);
} catch (Exception ex) {
getLogger().error("Couldn't notify for status change {} ", event, ex);
}
}
}
protected boolean shouldNotify(String from, String to) {
return Arrays.binarySearch(ignoreChanges, (from + ":" + to)) < 0
&& Arrays.binarySearch(ignoreChanges, ("*:" + to)) < 0
&& Arrays.binarySearch(ignoreChanges, (from + ":*")) < 0;
}
protected abstract void notify(ClientApplicationStatusChangedEvent event) throws Exception;
private Logger getLogger() {
return LoggerFactory.getLogger(this.getClass());
}
public void setIgnoreChanges(String[] ignoreChanges) {
String[] copy = Arrays.copyOf(ignoreChanges, ignoreChanges.length);
Arrays.sort(copy);
this.ignoreChanges = copy;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
\ No newline at end of file
...@@ -17,11 +17,6 @@ package de.codecentric.boot.admin.notify; ...@@ -17,11 +17,6 @@ package de.codecentric.boot.admin.notify;
import java.util.Arrays; import java.util.Arrays;
import javax.mail.MessagingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext; import org.springframework.expression.ParserContext;
...@@ -33,14 +28,11 @@ import org.springframework.mail.javamail.JavaMailSender; ...@@ -33,14 +28,11 @@ import org.springframework.mail.javamail.JavaMailSender;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent; import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
public class MailNotifier { public class MailNotifier extends AbstractNotifier {
private final static String DEFAULT_SUBJECT = "#{application.name} (#{application.id}) is #{to.status}";
private static final Logger LOGGER = LoggerFactory.getLogger(MailNotifier.class); private final static String DEFAULT_TEXT = "#{application.name} (#{application.id})\nstatus changed from #{from.status} to #{to.status}\n\n#{application.healthUrl}";
private final String DEFAULT_SUBJECT = "#{application.name} (#{application.id}) is #{to.status}";
private final String DEFAULT_TEXT = "#{application.name} (#{application.id})\nstatus changed from #{from.status} to #{to.status}\n\n#{application.healthUrl}";
private final SpelExpressionParser parser = new SpelExpressionParser(); private final SpelExpressionParser parser = new SpelExpressionParser();
private MailSender sender; private MailSender sender;
/** /**
...@@ -68,35 +60,14 @@ public class MailNotifier { ...@@ -68,35 +60,14 @@ public class MailNotifier {
*/ */
private Expression subject; private Expression subject;
/**
* List of changes to ignore. Must be in Format OLD:NEW, for any status use * as wildcard, e.g.
* *:UP or OFFLINE:*
*/
private String[] ignoreChanges = { "UNKNOWN:UP" };
/**
* Enables the mail notification.
*/
private boolean enabled = true;
public MailNotifier(MailSender sender) { public MailNotifier(MailSender sender) {
this.sender = sender; this.sender = sender;
this.subject = parser.parseExpression(DEFAULT_SUBJECT, ParserContext.TEMPLATE_EXPRESSION); this.subject = parser.parseExpression(DEFAULT_SUBJECT, ParserContext.TEMPLATE_EXPRESSION);
this.text = parser.parseExpression(DEFAULT_TEXT, ParserContext.TEMPLATE_EXPRESSION); this.text = parser.parseExpression(DEFAULT_TEXT, ParserContext.TEMPLATE_EXPRESSION);
} }
@EventListener @Override
public void onClientApplicationStatusChanged(ClientApplicationStatusChangedEvent event) { protected void notify(ClientApplicationStatusChangedEvent event) {
if (enabled && shouldSendMail(event.getFrom().getStatus(), event.getTo().getStatus())) {
try {
sendMail(event);
} catch (Exception ex) {
LOGGER.error("Couldn't send mail for Statuschange {} ", event, ex);
}
}
}
private void sendMail(ClientApplicationStatusChangedEvent event) throws MessagingException {
EvaluationContext context = new StandardEvaluationContext(event); EvaluationContext context = new StandardEvaluationContext(event);
SimpleMailMessage message = new SimpleMailMessage(); SimpleMailMessage message = new SimpleMailMessage();
...@@ -109,12 +80,6 @@ public class MailNotifier { ...@@ -109,12 +80,6 @@ public class MailNotifier {
sender.send(message); sender.send(message);
} }
private boolean shouldSendMail(String from, String to) {
return Arrays.binarySearch(ignoreChanges, (from + ":" + to)) < 0
&& Arrays.binarySearch(ignoreChanges, ("*:" + to)) < 0
&& Arrays.binarySearch(ignoreChanges, (from + ":*")) < 0;
}
public void setSender(JavaMailSender sender) { public void setSender(JavaMailSender sender) {
this.sender = sender; this.sender = sender;
} }
...@@ -139,14 +104,4 @@ public class MailNotifier { ...@@ -139,14 +104,4 @@ public class MailNotifier {
this.text = parser.parseExpression(text, ParserContext.TEMPLATE_EXPRESSION); this.text = parser.parseExpression(text, ParserContext.TEMPLATE_EXPRESSION);
} }
public void setIgnoreChanges(String[] ignoreChanges) {
String[] copy = Arrays.copyOf(ignoreChanges, ignoreChanges.length);
Arrays.sort(copy);
this.ignoreChanges = copy;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
} }
/*
* 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 java.net.URI;
import java.util.Arrays;
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.ClientApplicationStatusChangedEvent;
public class PagerdutyNotifier extends AbstractNotifier {
public static final URI DEFAULT_URI = URI
.create("https://events.pagerduty.com/generic/2010-04-15/create_event.json");
private final static 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 notify(ClientApplicationStatusChangedEvent event) throws Exception {
restTemplate.postForEntity(url, createPagerdutyEvent(event), Void.class);
}
private Map<String, Object> createPagerdutyEvent(ClientApplicationStatusChangedEvent event) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("service_key", serviceKey);
result.put("incident_key",
event.getApplication().getName() + "/" + event.getApplication().getId());
result.put("description", description.getValue(event, String.class));
Map<String, Object> details = new HashMap<String, Object>();
details.put("from", event.getFrom());
details.put("to", event.getTo());
result.put("details", details);
if ("UP".equals(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<String, Object>();
context.put("type", "link");
context.put("href", event.getApplication().getHealthUrl());
context.put("text", "Application health-endpoint");
result.put("contexts", Arrays.asList(context));
}
return result;
}
public void setUrl(URI url) {
this.url = url;
}
public void setClient(String client) {
this.client = client;
}
public void setClientUrl(URI clientUrl) {
this.clientUrl = clientUrl;
}
public void setServiceKey(String serviceKey) {
this.serviceKey = serviceKey;
}
public void setDescription(String description) {
this.description = parser.parseExpression(description, ParserContext.TEMPLATE_EXPRESSION);
}
public void setRestTemplate(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
}
{"groups": [ {"groups": [
{
"name": "spring.boot.admin.hazelcast",
"sourceType": "de.codecentric.boot.admin.config.HazelcastStoreConfiguration"
},
{
"name": "spring.boot.admin.discovery",
"sourceType": "de.codecentric.boot.admin.config.DiscoveryClientConfiguration"
}
],"properties": [ ],"properties": [
{ {
"name": "spring.boot.admin.hazelcast.enabled", "name": "spring.boot.admin.hazelcast.enabled",
......
...@@ -31,6 +31,7 @@ import de.codecentric.boot.admin.journal.store.HazelcastJournaledEventStore; ...@@ -31,6 +31,7 @@ import de.codecentric.boot.admin.journal.store.HazelcastJournaledEventStore;
import de.codecentric.boot.admin.journal.store.JournaledEventStore; import de.codecentric.boot.admin.journal.store.JournaledEventStore;
import de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore; import de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore;
import de.codecentric.boot.admin.notify.MailNotifier; import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.notify.PagerdutyNotifier;
import de.codecentric.boot.admin.registry.store.ApplicationStore; import de.codecentric.boot.admin.registry.store.ApplicationStore;
import de.codecentric.boot.admin.registry.store.HazelcastApplicationStore; import de.codecentric.boot.admin.registry.store.HazelcastApplicationStore;
import de.codecentric.boot.admin.registry.store.SimpleApplicationStore; import de.codecentric.boot.admin.registry.store.SimpleApplicationStore;
...@@ -72,7 +73,7 @@ public class AdminServerWebConfigurationTest { ...@@ -72,7 +73,7 @@ public class AdminServerWebConfigurationTest {
@Test @Test
public void simpleConfig() { public void simpleConfig() {
load("spring.boot.admin.discovery.enabled:false"); load();
assertThat(context.getBean(ApplicationStore.class), assertThat(context.getBean(ApplicationStore.class),
is(instanceOf(SimpleApplicationStore.class))); is(instanceOf(SimpleApplicationStore.class)));
assertTrue(context.getBeansOfType(ApplicationDiscoveryListener.class).isEmpty()); assertTrue(context.getBeansOfType(ApplicationDiscoveryListener.class).isEmpty());
...@@ -84,13 +85,20 @@ public class AdminServerWebConfigurationTest { ...@@ -84,13 +85,20 @@ public class AdminServerWebConfigurationTest {
@Test @Test
public void simpleConfig_mail() { public void simpleConfig_mail() {
load("spring.mail.host:localhost", "spring.boot.admin.discovery.enabled:false"); load("spring.mail.host:localhost");
assertThat(context.getBean(MailNotifier.class), is(instanceOf(MailNotifier.class))); assertThat(context.getBean(MailNotifier.class), is(instanceOf(MailNotifier.class)));
} }
@Test @Test
public void simpleConfig_pagerduty() {
load("spring.boot.admin.notify.pagerduty.service-key:foo");
assertThat(context.getBean(PagerdutyNotifier.class),
is(instanceOf(PagerdutyNotifier.class)));
}
@Test
public void hazelcastConfig() { public void hazelcastConfig() {
load(TestHazelcastConfig.class, "spring.boot.admin.discovery.enabled:false"); load(TestHazelcastConfig.class);
assertThat(context.getBean(ApplicationStore.class), assertThat(context.getBean(ApplicationStore.class),
is(instanceOf(HazelcastApplicationStore.class))); is(instanceOf(HazelcastApplicationStore.class)));
assertThat(context.getBean(JournaledEventStore.class), assertThat(context.getBean(JournaledEventStore.class),
...@@ -100,7 +108,7 @@ public class AdminServerWebConfigurationTest { ...@@ -100,7 +108,7 @@ public class AdminServerWebConfigurationTest {
@Test @Test
public void discoveryConfig() { public void discoveryConfig() {
load("spring.boot.admin.discovery.enabled:true"); load(NoopDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ApplicationStore.class), assertThat(context.getBean(ApplicationStore.class),
is(instanceOf(SimpleApplicationStore.class))); is(instanceOf(SimpleApplicationStore.class)));
context.getBean(ApplicationDiscoveryListener.class); context.getBean(ApplicationDiscoveryListener.class);
...@@ -125,10 +133,10 @@ public class AdminServerWebConfigurationTest { ...@@ -125,10 +133,10 @@ public class AdminServerWebConfigurationTest {
} }
applicationContext.register(PropertyPlaceholderAutoConfiguration.class); applicationContext.register(PropertyPlaceholderAutoConfiguration.class);
applicationContext.register(ServerPropertiesAutoConfiguration.class); applicationContext.register(ServerPropertiesAutoConfiguration.class);
applicationContext.register(NoopDiscoveryClientAutoConfiguration.class);
applicationContext.register(MailSenderAutoConfiguration.class); applicationContext.register(MailSenderAutoConfiguration.class);
applicationContext.register(HazelcastAutoConfiguration.class); applicationContext.register(HazelcastAutoConfiguration.class);
applicationContext.register(MailNotifierConfiguration.class); applicationContext.register(MailNotifierConfiguration.class);
applicationContext.register(PagerdutyNotifierConfiguration.class);
applicationContext.register(HazelcastStoreConfiguration.class); applicationContext.register(HazelcastStoreConfiguration.class);
applicationContext.register(DiscoveryClientConfiguration.class); applicationContext.register(DiscoveryClientConfiguration.class);
applicationContext.register(AdminServerWebConfiguration.class); applicationContext.register(AdminServerWebConfiguration.class);
......
package de.codecentric.boot.admin.notify;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.model.StatusInfo;
public class AbstractNotifierTest {
private TestableNotifier notifier = new TestableNotifier();
@Test
public void test_onApplicationEvent() {
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofDown(), StatusInfo.ofUp()));
assertTrue(notifier.hasNotified);
}
@Test
public void test_onApplicationEvent_disbaled() {
notifier.setEnabled(false);
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofDown(), StatusInfo.ofUp()));
assertFalse(notifier.hasNotified);
}
@Test
public void test_onApplicationEvent_noSend() {
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofUnknown(), StatusInfo.ofUp()));
assertFalse(notifier.hasNotified);
}
@Test
public void test_onApplicationEvent_noSend_wildcard() {
notifier.setIgnoreChanges(new String[] { "*:UP" });
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofOffline(), StatusInfo.ofUp()));
assertFalse(notifier.hasNotified);
}
private static class TestableNotifier extends AbstractNotifier {
private boolean hasNotified;
@Override
protected void notify(ClientApplicationStatusChangedEvent event) throws Exception {
hasNotified = true;
}
}
}
package de.codecentric.boot.admin.notify; package de.codecentric.boot.admin.notify;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import org.junit.Before; import org.junit.Before;
...@@ -33,9 +31,8 @@ public class MailNotifierTest { ...@@ -33,9 +31,8 @@ public class MailNotifierTest {
@Test @Test
public void test_onApplicationEvent() { public void test_onApplicationEvent() {
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent( notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-") Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
.withHealthUrl("http://health").build(), StatusInfo.ofDown(), StatusInfo StatusInfo.ofDown(), StatusInfo.ofUp()));
.ofUp()));
SimpleMailMessage expected = new SimpleMailMessage(); SimpleMailMessage expected = new SimpleMailMessage();
expected.setTo(new String[] { "foo@bar.com" }); expected.setTo(new String[] { "foo@bar.com" });
...@@ -47,36 +44,4 @@ public class MailNotifierTest { ...@@ -47,36 +44,4 @@ public class MailNotifierTest {
verify(sender).send(eq(expected)); verify(sender).send(eq(expected));
} }
@Test
public void test_onApplicationEvent_disbaled() {
notifier.setEnabled(false);
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-")
.withHealthUrl("http://health").build(), StatusInfo.ofDown(), StatusInfo
.ofUp()));
verify(sender, never()).send(isA(SimpleMailMessage.class));
}
@Test
public void test_onApplicationEvent_noSend() {
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-")
.withHealthUrl("http://health").build(), StatusInfo.ofUnknown(), StatusInfo
.ofUp()));
verify(sender, never()).send(isA(SimpleMailMessage.class));
}
@Test
public void test_onApplicationEvent_noSend_wildcard() {
notifier.setIgnoreChanges(new String[] { "*:UP" });
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-")
.withHealthUrl("http://health").build(), StatusInfo.ofOffline(), StatusInfo
.ofUp()));
verify(sender, never()).send(isA(SimpleMailMessage.class));
}
} }
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.onClientApplicationStatusChanged(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.onClientApplicationStatusChanged(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));
}
}
server.port=8080 server.port=8080
info.version=1.0.0 info.version=1.0.0
spring.application.name=spring-boot-admin-server-test spring.application.name=spring-boot-admin-server-test
spring.boot.admin.url=http://localhost:8080 spring.boot.admin.url=http://localhost:8080
spring.boot.admin.discovery.enabled=false \ No newline at end of file
\ No newline at end of file
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