Search in sources :

Example 1 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent 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 ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent 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 ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent in project spring-boot-admin by codecentric.

the class MailNotifierTest method test_onApplicationEvent_noSend_wildcard.

@Test
public void test_onApplicationEvent_noSend_wildcard() {
    notifier.setIgnoreChanges(new String[] { "*:UP" });
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofOffline(), StatusInfo.ofUp()));
    verifyNoMoreInteractions(sender);
}
Also used : ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 4 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent in project spring-boot-admin by codecentric.

the class MailNotifierTest method test_onApplicationEvent_noSend.

@Test
public void test_onApplicationEvent_noSend() {
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofUnknown(), StatusInfo.ofUp()));
    verifyNoMoreInteractions(sender);
}
Also used : ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 5 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent 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)

Aggregations

ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)11 Test (org.junit.Test)9 StatusInfo (de.codecentric.boot.admin.model.StatusInfo)5 HashMap (java.util.HashMap)2 HttpEntity (org.springframework.http.HttpEntity)2 ClientApplicationEvent (de.codecentric.boot.admin.event.ClientApplicationEvent)1 Application (de.codecentric.boot.admin.model.Application)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1