Notify user about results of manually executed health check (#2044)

When manually starting health checks, the user should always receive a notification about the status, whether successful or not.
This commit is contained in:
Florian Scholdei
2022-05-25 09:30:45 +02:00
committed by GitHub
parent bd68c301ea
commit 6216945f0d
5 changed files with 22 additions and 11 deletions

View File

@@ -227,22 +227,28 @@ final class HealthChecker {
}
private void notifyCurrentUser(Repository repository, HealthCheckResult result) {
if (!(repository.isHealthy() && result.isHealthy())) {
String currentUser = SecurityUtils.getSubject().getPrincipal().toString();
if (!scmConfiguration.getEmergencyContacts().contains(currentUser)) {
notificationSender.send(getHealthCheckFailedNotification(repository));
}
if (repository.isHealthy() && result.isHealthy()) {
notificationSender.send(getHealthCheckSuccessNotification(repository));
} else {
notificationSender.send(getHealthCheckFailedNotification(repository));
}
}
private void notifyEmergencyContacts(Repository repository) {
String currentUser = SecurityUtils.getSubject().getPrincipal().toString();
Set<String> emergencyContacts = scmConfiguration.getEmergencyContacts();
for (String user : emergencyContacts) {
notificationSender.send(getHealthCheckFailedNotification(repository), user);
if (!user.equals(currentUser)) {
notificationSender.send(getHealthCheckFailedNotification(repository), user);
}
}
}
private Notification getHealthCheckFailedNotification(Repository repository) {
return new Notification(Type.ERROR, "/repo/" + repository.getNamespaceAndName() + "/settings/general", "healthCheckFailed");
}
private Notification getHealthCheckSuccessNotification(Repository repository) {
return new Notification(Type.SUCCESS, "/repo/" + repository.getNamespaceAndName() + "/settings/general", "healthCheckSuccess");
}
}