use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class OpsGenieNotifier method createRequest.
protected HttpEntity<?> createRequest(InstanceEvent event, Instance instance) {
Map<String, Object> body = new HashMap<>();
if (user != null) {
body.put("user", user);
}
if (source != null) {
body.put("source", source);
}
if (event instanceof InstanceStatusChangedEvent && !StatusInfo.STATUS_UP.equals(((InstanceStatusChangedEvent) event).getStatusInfo().getStatus())) {
body.put("message", getMessage(event, instance));
body.put("alias", generateAlias(instance));
body.put("description", getDescription(event, instance));
if (actions != null) {
body.put("actions", actions);
}
if (tags != null) {
body.put("tags", tags);
}
if (entity != null) {
body.put("entity", entity);
}
Map<String, Object> details = new HashMap<>();
details.put("type", "link");
details.put("href", instance.getRegistration().getHealthUrl());
details.put("text", "Instance health-endpoint");
body.put("details", details);
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HttpHeaders.AUTHORIZATION, "GenieKey " + apiKey);
return new HttpEntity<>(body, headers);
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class StatusUpdaterTest method should_change_status_to_down.
@Test
public void should_change_status_to_down() {
String body = "{ \"status\" : \"UP\", \"details\" : { \"foo\" : \"bar\" } }";
this.wireMock.stubFor(get("/health").willReturn(okForContentType(ActuatorMediaType.V2_JSON, body).withHeader("Content-Length", Integer.toString(body.length()))));
StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()).assertNext((event) -> {
assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class);
assertThat(event.getInstance()).isEqualTo(this.instance.getId());
InstanceStatusChangedEvent statusChangedEvent = (InstanceStatusChangedEvent) event;
assertThat(statusChangedEvent.getStatusInfo().getStatus()).isEqualTo("UP");
assertThat(statusChangedEvent.getStatusInfo().getDetails()).isEqualTo(singletonMap("foo", "bar"));
}).thenCancel().verify();
StepVerifier.create(this.repository.find(this.instance.getId())).assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP")).verifyComplete();
StepVerifier.create(this.repository.computeIfPresent(this.instance.getId(), (key, instance) -> Mono.just(instance.deregister()))).then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete()).thenCancel().verify();
StepVerifier.create(this.repository.find(this.instance.getId())).assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UNKNOWN")).verifyComplete();
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class InfoUpdateTriggerTest method should_start_and_stop_monitor.
@Test
public void should_start_and_stop_monitor() throws Exception {
// given
this.trigger.stop();
this.trigger.setInterval(Duration.ofMillis(10));
this.trigger.setLifetime(Duration.ofMillis(10));
this.trigger.start();
await().until(this.events::wasSubscribed);
this.events.next(new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown()));
Thread.sleep(50L);
// then it should start updating one time for registration and at least once for
// monitor
verify(this.updater, atLeast(2)).updateInfo(this.instance.getId());
// given long lifetime
this.trigger.setLifetime(Duration.ofSeconds(10));
Thread.sleep(50L);
clearInvocations(this.updater);
// when the lifetime is not expired
Thread.sleep(50L);
// should never update
verify(this.updater, never()).updateInfo(any(InstanceId.class));
// when trigger ist destroyed
this.trigger.setLifetime(Duration.ofMillis(10));
this.trigger.stop();
clearInvocations(this.updater);
Thread.sleep(15L);
// it should stop updating
verify(this.updater, never()).updateInfo(any(InstanceId.class));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class MicrosoftTeamsNotifierTest method test_getStatusChangedMessageForAppReturns_correctContent.
@Test
void test_getStatusChangedMessageForAppReturns_correctContent() {
Message message = notifier.getStatusChangedMessage(instance, notifier.createEvaluationContext(new InstanceStatusChangedEvent(instance.getId(), 1L, StatusInfo.ofDown()), instance));
assertMessage(message, notifier.getStatusChangedTitle(), notifier.getMessageSummary(), "Test App with id TestAppId changed status from UNKNOWN to DOWN", RED);
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class MicrosoftTeamsNotifierTest method test_onApplicationStatusChangedEvent_resolve.
@Test
@SuppressWarnings("unchecked")
void test_onApplicationStatusChangedEvent_resolve() {
InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(instance.getId(), 1L, StatusInfo.ofUp());
StepVerifier.create(notifier.doNotify(event, instance)).verifyComplete();
ArgumentCaptor<HttpEntity<Message>> entity = ArgumentCaptor.forClass(HttpEntity.class);
verify(mockRestTemplate).postForEntity(eq(URI.create("http://example.com")), entity.capture(), eq(Void.class));
assertThat(entity.getValue().getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
assertMessage(entity.getValue().getBody(), notifier.getStatusChangedTitle(), notifier.getMessageSummary(), "Test App with id TestAppId changed status from UNKNOWN to UP", GREEN);
}
Aggregations