use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.
the class PagerdutyNotifierTest method test_onApplicationEvent_trigger.
@Test
public void test_onApplicationEvent_trigger() {
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 1, StatusInfo.ofUp()))).verifyComplete();
reset(restTemplate);
StatusInfo down = StatusInfo.ofDown();
when(repository.find(INSTANCE.getId())).thenReturn(Mono.just(INSTANCE.withStatusInfo(down)));
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 2, down))).verifyComplete();
Map<String, Object> expected = new HashMap<>();
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<>();
details.put("from", "UP");
details.put("to", down);
expected.put("details", details);
Map<String, Object> context = new HashMap<>();
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));
}
use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.
the class Instance method apply.
private Instance apply(InstanceEvent event, boolean isNewEvent) {
Assert.notNull(event, "'event' must not be null");
Assert.isTrue(this.id.equals(event.getInstance()), "'event' must refer the same instance");
Assert.isTrue(event.getVersion() >= this.nextVersion(), () -> "Event " + event.getVersion() + " must be greater or equal to " + this.nextVersion());
List<InstanceEvent> unsavedEvents = appendToEvents(event, isNewEvent);
if (event instanceof InstanceRegisteredEvent) {
Registration registration = ((InstanceRegisteredEvent) event).getRegistration();
return new Instance(this.id, event.getVersion(), registration, true, StatusInfo.ofUnknown(), event.getTimestamp(), Info.empty(), Endpoints.empty(), updateBuildVersion(registration.getMetadata()), updateTags(registration.getMetadata()), unsavedEvents);
} else if (event instanceof InstanceRegistrationUpdatedEvent) {
Registration registration = ((InstanceRegistrationUpdatedEvent) event).getRegistration();
return new Instance(this.id, event.getVersion(), registration, this.registered, this.statusInfo, this.statusTimestamp, this.info, this.endpoints, updateBuildVersion(registration.getMetadata(), this.info.getValues()), updateTags(registration.getMetadata(), this.info.getValues()), unsavedEvents);
} else if (event instanceof InstanceStatusChangedEvent) {
StatusInfo statusInfo = ((InstanceStatusChangedEvent) event).getStatusInfo();
return new Instance(this.id, event.getVersion(), this.registration, this.registered, statusInfo, event.getTimestamp(), this.info, this.endpoints, this.buildVersion, this.tags, unsavedEvents);
} else if (event instanceof InstanceEndpointsDetectedEvent) {
Endpoints endpoints = ((InstanceEndpointsDetectedEvent) event).getEndpoints();
return new Instance(this.id, event.getVersion(), this.registration, this.registered, this.statusInfo, this.statusTimestamp, this.info, endpoints, this.buildVersion, this.tags, unsavedEvents);
} else if (event instanceof InstanceInfoChangedEvent) {
Info info = ((InstanceInfoChangedEvent) event).getInfo();
Map<String, ?> metaData = (this.registration != null) ? this.registration.getMetadata() : emptyMap();
return new Instance(this.id, event.getVersion(), this.registration, this.registered, this.statusInfo, this.statusTimestamp, info, this.endpoints, updateBuildVersion(metaData, info.getValues()), updateTags(metaData, info.getValues()), unsavedEvents);
} else if (event instanceof InstanceDeregisteredEvent) {
return new Instance(this.id, event.getVersion(), this.registration, false, StatusInfo.ofUnknown(), event.getTimestamp(), Info.empty(), Endpoints.empty(), null, Tags.empty(), unsavedEvents);
}
return this;
}
use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.
the class StatusUpdater method convertStatusInfo.
protected Mono<StatusInfo> convertStatusInfo(ClientResponse response) {
Boolean hasCompatibleContentType = response.headers().contentType().map((mt) -> mt.isCompatibleWith(MediaType.APPLICATION_JSON) || mt.isCompatibleWith(ACTUATOR_V2_MEDIATYPE)).orElse(false);
StatusInfo statusInfoFromStatus = this.getStatusInfoFromStatus(response.statusCode(), emptyMap());
if (hasCompatibleContentType) {
return response.bodyToMono(RESPONSE_TYPE).map((body) -> {
if (body.get("status") instanceof String) {
return StatusInfo.from(body);
}
return getStatusInfoFromStatus(response.statusCode(), body);
}).defaultIfEmpty(statusInfoFromStatus);
}
return response.releaseBody().then(Mono.just(statusInfoFromStatus));
}
use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.
the class TelegramNotifierTest method test_onApplicationEvent_trigger.
@Test
public void test_onApplicationEvent_trigger() {
StatusInfo infoDown = StatusInfo.ofDown();
@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().build());
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))).verifyComplete();
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), infoDown))).verifyComplete();
verify(restTemplate).getForObject(eq("https://telegram.com/bot--token-/sendmessage?chat_id={chat_id}&text={text}" + "&parse_mode={parse_mode}&disable_notification={disable_notification}"), eq(Void.class), eq(getParameters("DOWN")));
}
use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.
the class InstanceStatusChangedEventMixinTest method verifyDeserialize.
@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
String json = new JSONObject().put("instance", "test123").put("version", 12345678L).put("timestamp", 1587751031.000000000).put("type", "STATUS_CHANGED").put("statusInfo", new JSONObject().put("status", "OFFLINE").put("details", new JSONObject().put("foo", "bar"))).toString();
InstanceStatusChangedEvent event = objectMapper.readValue(json, InstanceStatusChangedEvent.class);
assertThat(event).isNotNull();
assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
assertThat(event.getVersion()).isEqualTo(12345678L);
assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
StatusInfo statusInfo = event.getStatusInfo();
assertThat(statusInfo).isNotNull();
assertThat(statusInfo.getStatus()).isEqualTo("OFFLINE");
assertThat(statusInfo.getDetails()).containsOnly(entry("foo", "bar"));
}
Aggregations