1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-25 22:46:31 -04:00

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

closes #3253
This commit is contained in:
Qstick
2019-08-07 21:45:29 -04:00
committed by Taloth Saldono
parent 7b68ce49d5
commit f2efebf7d9
29 changed files with 267 additions and 6 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<EpisodeGrabbedEvent>,
IHandle<EpisodeImportedEvent>,
IHandle<SeriesRenamedEvent>
IHandle<SeriesRenamedEvent>,
IHandle<HealthCheckFailedEvent>
{
private readonly INotificationFactory _notificationFactory;
private readonly Logger _logger;
@@ -85,6 +87,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(EpisodeGrabbedEvent message)
{
var grabMessage = new GrabMessage
@@ -168,5 +185,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);
}
}
}
}
}