diff --git a/src/main/java/io/entraos/monitor/scheduler/ScheduledMonitorManager.java b/src/main/java/io/entraos/monitor/scheduler/ScheduledMonitorManager.java index a8102cd..7b4e817 100644 --- a/src/main/java/io/entraos/monitor/scheduler/ScheduledMonitorManager.java +++ b/src/main/java/io/entraos/monitor/scheduler/ScheduledMonitorManager.java @@ -99,9 +99,15 @@ synchronized void notifyAlerters(Status status) { if (alerter.isAlertingEnabled()) { String serviceName = getProperty("service_name"); String environment = getProperty("environment"); - String message = "Integration Failed on" + serviceName + " in " + environment + ". Status is " + status.toString(); - log.trace("Sending alert: {}", message); - alerter.notifyFailure(message); + if (status == Status.OK) { + String message = "Integration OK on" + serviceName + " in " + environment + ". Status is " + status.toString(); + log.trace("Sending alert: {}", message); + alerter.notifyRevival(message); + } else { + String message = "Integration Failed on" + serviceName + " in " + environment + ". Status is " + status.toString(); + log.trace("Sending alert: {}", message); + alerter.notifyFailure(message); + } } } } diff --git a/src/test/java/io/entraos/monitor/scheduler/ScheduledMonitorManagerTest.java b/src/test/java/io/entraos/monitor/scheduler/ScheduledMonitorManagerTest.java index 77186e3..6702181 100644 --- a/src/test/java/io/entraos/monitor/scheduler/ScheduledMonitorManagerTest.java +++ b/src/test/java/io/entraos/monitor/scheduler/ScheduledMonitorManagerTest.java @@ -27,14 +27,25 @@ public void notifyAlertersFromUnknownToFailure() { manager.notifyAlerters(Status.FAILED); verify(alerter, times(1)).isAlertingEnabled(); + verify(alerter, times(1)).notifyFailure(anyString()); } @Test public void multipleFailedStatuses() { - when(alerter.isAlertingEnabled()).thenReturn(true); manager.notifyAlerters(Status.FAILED); manager.notifyAlerters(Status.FAILED); + verify(alerter, times(2)).isAlertingEnabled(); + } + + @Test + public void notifyAlertersFromOkToFailedToOk() { + when(alerter.isAlertingEnabled()).thenReturn(true); + manager.notifyAlerters(Status.FAILED); verify(alerter, times(1)).isAlertingEnabled(); + verify(alerter, times(1)).notifyFailure(anyString()); + manager.notifyAlerters(Status.OK); + verify(alerter, times(2)).isAlertingEnabled(); + verify(alerter, times(1)).notifyRevival(anyString()); } } \ No newline at end of file