New: Option to send notification when a Health Check warning occurs

This commit is contained in:
Devin Buhl
2019-11-04 15:44:33 -05:00
committed by Qstick
parent e0b6bde525
commit 4e07e3bd68
26 changed files with 253 additions and 5 deletions
@@ -4,6 +4,7 @@ using System.Linq;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download;
using NzbDrone.Core.HealthCheck;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Qualities;
@@ -15,7 +16,8 @@ namespace NzbDrone.Core.Notifications
public class NotificationService
: IHandle<MovieRenamedEvent>,
IHandle<MovieGrabbedEvent>,
IHandle<MovieDownloadedEvent>
IHandle<MovieDownloadedEvent>,
IHandle<HealthCheckFailedEvent>
{
private readonly INotificationFactory _notificationFactory;
@@ -63,6 +65,21 @@ namespace NzbDrone.Core.Notifications
return false;
}
private bool ShouldHandleHealthFailure(HealthCheck.HealthCheck healthCheck, bool includeWarnings)
{
if (healthCheck.Type == HealthCheckResult.Error)
{
return true;
}
if (healthCheck.Type == HealthCheckResult.Warning && includeWarnings)
{
return true;
}
return false;
}
public void Handle(MovieGrabbedEvent message)
{
var grabMessage = new GrabMessage
@@ -138,5 +155,24 @@ namespace NzbDrone.Core.Notifications
}
}
}
public void Handle(HealthCheckFailedEvent message)
{
foreach (var notification in _notificationFactory.OnHealthIssueEnabled())
{
try
{
if (ShouldHandleHealthFailure(message.HealthCheck, ((NotificationDefinition)notification.Definition).IncludeHealthWarnings))
{
notification.OnHealthIssue(message.HealthCheck);
}
}
catch (Exception ex)
{
_logger.Warn(ex, "Unable to send OnHealthIssue notification to: " + notification.Definition.Name);
}
}
}
}
}