use of de.codecentric.boot.admin.model.StatusInfo in project spring-boot-admin by codecentric.
the class StatusUpdater method updateStatus.
public void updateStatus(Application application) {
StatusInfo oldStatus = application.getStatusInfo();
StatusInfo newStatus = queryStatus(application);
boolean statusChanged = !newStatus.equals(oldStatus);
Application.Builder builder = Application.copyOf(application).withStatusInfo(newStatus);
if (statusChanged && !newStatus.isOffline() && !newStatus.isUnknown()) {
builder.withInfo(queryInfo(application));
}
Application newState = builder.build();
store.save(newState);
if (statusChanged) {
publisher.publishEvent(new ClientApplicationStatusChangedEvent(newState, oldStatus, newStatus));
}
}
use of de.codecentric.boot.admin.model.StatusInfo in project spring-boot-admin by codecentric.
the class HipchatNotifierTest method test_onApplicationEvent_trigger.
@Test
public void test_onApplicationEvent_trigger() {
StatusInfo infoDown = StatusInfo.ofDown();
StatusInfo infoUp = StatusInfo.ofUp();
@SuppressWarnings("unchecked") ArgumentCaptor<HttpEntity<Map<String, Object>>> httpRequest = ArgumentCaptor.forClass((Class<HttpEntity<Map<String, Object>>>) (Class<?>) HttpEntity.class);
when(restTemplate.postForEntity(isA(String.class), httpRequest.capture(), eq(Void.class))).thenReturn(ResponseEntity.ok((Void) null));
notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), infoUp, infoDown));
assertThat(httpRequest.getValue().getHeaders()).containsEntry("Content-Type", asList("application/json"));
Map<String, Object> body = httpRequest.getValue().getBody();
assertThat(body).containsEntry("color", "red");
assertThat(body).containsEntry("message", "<strong>App</strong>/-id- is <strong>DOWN</strong>");
assertThat(body).containsEntry("notify", Boolean.TRUE);
assertThat(body).containsEntry("message_format", "html");
}
use of de.codecentric.boot.admin.model.StatusInfo in project spring-boot-admin by codecentric.
the class PagerdutyNotifierTest method test_onApplicationEvent_resolve.
@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));
}
use of de.codecentric.boot.admin.model.StatusInfo in project spring-boot-admin by codecentric.
the class SlackNotifierTest method test_onApplicationEvent_trigger.
@Test
public void test_onApplicationEvent_trigger() {
StatusInfo infoDown = StatusInfo.ofDown();
StatusInfo infoUp = StatusInfo.ofUp();
notifier.setChannel(channel);
notifier.setIcon(icon);
notifier.notify(getEvent(infoUp, infoDown));
Object expected = expectedMessage("danger", user, icon, channel, standardMessage(infoDown.getStatus(), appName, id));
verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class));
}
use of de.codecentric.boot.admin.model.StatusInfo in project spring-boot-admin by codecentric.
the class SlackNotifierTest method test_onApplicationEvent_resolve_without_channel_and_icon.
@Test
public void test_onApplicationEvent_resolve_without_channel_and_icon() {
StatusInfo infoDown = StatusInfo.ofDown();
StatusInfo infoUp = StatusInfo.ofUp();
notifier.notify(getEvent(infoDown, infoUp));
Object expected = expectedMessage("good", user, null, null, standardMessage(infoUp.getStatus(), appName, id));
verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class));
}
Aggregations