Search in sources :

Example 1 with StatusInfo

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));
    }
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Application(de.codecentric.boot.admin.model.Application)

Example 2 with StatusInfo

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");
}
Also used : HttpEntity(org.springframework.http.HttpEntity) StatusInfo(de.codecentric.boot.admin.model.StatusInfo) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 3 with StatusInfo

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));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) HashMap(java.util.HashMap) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 4 with StatusInfo

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));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) URI(java.net.URI) Test(org.junit.Test)

Example 5 with StatusInfo

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));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) URI(java.net.URI) Test(org.junit.Test)

Aggregations

StatusInfo (de.codecentric.boot.admin.model.StatusInfo)16 Test (org.junit.Test)15 ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)5 Application (de.codecentric.boot.admin.model.Application)5 URI (java.net.URI)5 Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)2 HttpEntity (org.springframework.http.HttpEntity)2 Info (de.codecentric.boot.admin.model.Info)1 Map (java.util.Map)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1