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

View File

@ -42,10 +42,13 @@ function EditNotificationModalContent(props) {
onDownload,
onUpgrade,
onRename,
onHealthIssue,
supportsOnGrab,
supportsOnDownload,
supportsOnUpgrade,
supportsOnRename,
supportsOnHealthIssue,
includeHealthWarnings,
tags,
fields,
message
@ -147,6 +150,35 @@ function EditNotificationModalContent(props) {
/>
</FormGroup>
<FormGroup>
<FormLabel>On Health Issue</FormLabel>
<FormInputGroup
type={inputTypes.CHECK}
name="onHealthIssue"
helpText="Be notified on health check failures"
isDisabled={!supportsOnHealthIssue.value}
{...onHealthIssue}
onChange={onInputChange}
/>
</FormGroup>
{
onHealthIssue.value &&
<FormGroup>
<FormLabel>Include Health Warnings</FormLabel>
<FormInputGroup
type={inputTypes.CHECK}
name="includeHealthWarnings"
helpText="Be notified on health warnings in addition to errors"
isDisabled={!supportsOnHealthIssue.value}
{...includeHealthWarnings}
onChange={onInputChange}
/>
</FormGroup>
}
<FormGroup>
<FormLabel>Tags</FormLabel>

View File

@ -58,10 +58,12 @@ class Notification extends Component {
onDownload,
onUpgrade,
onRename,
onHealthIssue,
supportsOnGrab,
supportsOnDownload,
supportsOnUpgrade,
supportsOnRename
supportsOnRename,
supportsOnHealthIssue
} = this.props;
return (
@ -103,7 +105,14 @@ class Notification extends Component {
}
{
!onGrab && !onDownload && !onRename &&
supportsOnHealthIssue && onHealthIssue &&
<Label kind={kinds.SUCCESS}>
On Health Issue
</Label>
}
{
!onGrab && !onDownload && !onRename && !onHealthIssue &&
<Label
kind={kinds.DISABLED}
outline={true}
@ -140,10 +149,12 @@ Notification.propTypes = {
onDownload: PropTypes.bool.isRequired,
onUpgrade: PropTypes.bool.isRequired,
onRename: PropTypes.bool.isRequired,
onHealthIssue: PropTypes.bool.isRequired,
supportsOnGrab: PropTypes.bool.isRequired,
supportsOnDownload: PropTypes.bool.isRequired,
supportsOnUpgrade: PropTypes.bool.isRequired,
supportsOnRename: PropTypes.bool.isRequired,
supportsOnHealthIssue: PropTypes.bool.isRequired,
onConfirmDeleteNotification: PropTypes.func.isRequired
};

View File

@ -65,6 +65,11 @@ namespace NzbDrone.Core.Test.NotificationTests
TestLogger.Info("OnRename was called");
}
public override void OnHealthIssue(NzbDrone.Core.HealthCheck.HealthCheck artist)
{
TestLogger.Info("OnHealthIssue was called");
}
}
class TestNotificationWithNoEvents : NotificationBase<TestSetting>
@ -102,6 +107,7 @@ namespace NzbDrone.Core.Test.NotificationTests
notification.SupportsOnDownload.Should().BeTrue();
notification.SupportsOnUpgrade.Should().BeTrue();
notification.SupportsOnRename.Should().BeTrue();
notification.SupportsOnHealthIssue.Should().BeTrue();
}
@ -114,6 +120,7 @@ namespace NzbDrone.Core.Test.NotificationTests
notification.SupportsOnDownload.Should().BeFalse();
notification.SupportsOnUpgrade.Should().BeFalse();
notification.SupportsOnRename.Should().BeFalse();
notification.SupportsOnHealthIssue.Should().BeFalse();
}
}

View File

@ -0,0 +1,15 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(135)]
public class health_issue_notification : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Notifications").AddColumn("OnHealthIssue").AsBoolean().WithDefaultValue(0);
Alter.Table("Notifications").AddColumn("IncludeHealthWarnings").AsBoolean().WithDefaultValue(0);
}
}
}

View File

@ -68,7 +68,8 @@ namespace NzbDrone.Core.Datastore
.Ignore(i => i.SupportsOnGrab)
.Ignore(i => i.SupportsOnDownload)
.Ignore(i => i.SupportsOnUpgrade)
.Ignore(i => i.SupportsOnRename);
.Ignore(i => i.SupportsOnRename)
.Ignore(i => i.SupportsOnHealthIssue);
Mapper.Entity<MetadataDefinition>().RegisterDefinition("Metadata")
.Ignore(d => d.Tags);

View File

@ -0,0 +1,14 @@
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.HealthCheck
{
public class HealthCheckFailedEvent : IEvent
{
public HealthCheck HealthCheck { get; private set; }
public HealthCheckFailedEvent(HealthCheck healthCheck)
{
HealthCheck = healthCheck;
}
}
}

View File

@ -86,6 +86,11 @@ namespace NzbDrone.Core.HealthCheck
else
{
if (_healthCheckResults.Find(result.Source.Name) == null)
{
_eventAggregator.PublishEvent(new HealthCheckFailedEvent(result));
}
_healthCheckResults.Set(result.Source.Name, result);
}
}

View File

@ -26,6 +26,11 @@ namespace NzbDrone.Core.Notifications.Boxcar
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE , message.Message, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE, message.Message, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -8,6 +8,7 @@ using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Processes;
using NzbDrone.Core.HealthCheck;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Validation;
@ -125,6 +126,19 @@ namespace NzbDrone.Core.Notifications.CustomScript
ExecuteScript(environmentVariables);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
var environmentVariables = new StringDictionary();
environmentVariables.Add("Sonarr_EventType", "HealthIssue");
environmentVariables.Add("Sonarr_Health_Issue_Level", nameof(healthCheck.Type));
environmentVariables.Add("Sonarr_Health_Issue_Message", healthCheck.Message);
environmentVariables.Add("Sonarr_Health_Issue_Type", healthCheck.Source.Name);
environmentVariables.Add("Sonarr_Health_Issue_Wiki", healthCheck.WikiUrl.ToString() ?? string.Empty);
ExecuteScript(environmentVariables);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -69,6 +69,23 @@ namespace NzbDrone.Core.Notifications.Discord
_proxy.SendPayload(payload, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
var attachments = new List<Embed>
{
new Embed
{
Title = healthCheck.Source.Name,
Text = healthCheck.Message,
Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? (int)DiscordColors.Warning : (int)DiscordColors.Success
}
};
var payload = CreatePayload("Health Issue", attachments);
_proxy.SendPayload(payload, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -33,6 +33,10 @@ namespace NzbDrone.Core.Notifications.Email
_emailService.SendEmail(Settings, EPISODE_DOWNLOADED_TITLE_BRANDED, body);
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_emailService.SendEmail(Settings, HEALTH_ISSUE_TITLE_BRANDED, message.Message);
}
public override ValidationResult Test()
{

View File

@ -29,6 +29,11 @@ namespace NzbDrone.Core.Notifications.Gotify
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -28,7 +28,10 @@ namespace NzbDrone.Core.Notifications.Growl
{
_growlService.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, "DOWNLOAD", Settings.Host, Settings.Port, Settings.Password);
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_growlService.SendNotification(HEALTH_ISSUE_TITLE, message.Message, "HEALTHISSUE", Settings.Host, Settings.Port, Settings.Password);
}
public override ValidationResult Test()
{

View File

@ -10,9 +10,11 @@ namespace NzbDrone.Core.Notifications
void OnGrab(GrabMessage grabMessage);
void OnDownload(DownloadMessage message);
void OnRename(Series series);
void OnHealthIssue(HealthCheck.HealthCheck healthCheck);
bool SupportsOnGrab { get; }
bool SupportsOnDownload { get; }
bool SupportsOnUpgrade { get; }
bool SupportsOnRename { get; }
bool SupportsOnHealthIssue { get; }
}
}

View File

@ -27,6 +27,11 @@ namespace NzbDrone.Core.Notifications.Join
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE_BRANDED, message.Message, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE_BRANDED, message.Message, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -47,6 +47,13 @@ namespace NzbDrone.Core.Notifications.Emby
}
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
if (Settings.Notify)
{
_mediaBrowserService.Notify(Settings, HEALTH_ISSUE_TITLE_BRANDED, message.Message);
}
}
public override ValidationResult Test()
{

View File

@ -10,9 +10,11 @@ namespace NzbDrone.Core.Notifications
{
protected const string EPISODE_GRABBED_TITLE = "Episode Grabbed";
protected const string EPISODE_DOWNLOADED_TITLE = "Episode Downloaded";
protected const string HEALTH_ISSUE_TITLE = "Health Check Failure";
protected const string EPISODE_GRABBED_TITLE_BRANDED = "Sonarr - " + EPISODE_GRABBED_TITLE;
protected const string EPISODE_DOWNLOADED_TITLE_BRANDED = "Sonarr - " + EPISODE_DOWNLOADED_TITLE;
protected const string HEALTH_ISSUE_TITLE_BRANDED = "Sonarr - " + HEALTH_ISSUE_TITLE;
public abstract string Name { get; }
@ -42,10 +44,16 @@ namespace NzbDrone.Core.Notifications
}
public virtual void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
}
public bool SupportsOnGrab => HasConcreteImplementation("OnGrab");
public bool SupportsOnRename => HasConcreteImplementation("OnRename");
public bool SupportsOnDownload => HasConcreteImplementation("OnDownload");
public bool SupportsOnUpgrade => SupportsOnDownload;
public bool SupportsOnHealthIssue => HasConcreteImplementation("OnHealthIssue");
protected TSettings Settings => (TSettings)Definition.Settings;

View File

@ -8,11 +8,14 @@ namespace NzbDrone.Core.Notifications
public bool OnDownload { get; set; }
public bool OnUpgrade { get; set; }
public bool OnRename { get; set; }
public bool OnHealthIssue { get; set; }
public bool SupportsOnGrab { get; set; }
public bool SupportsOnDownload { get; set; }
public bool SupportsOnUpgrade { get; set; }
public bool SupportsOnRename { get; set; }
public bool SupportsOnHealthIssue { get; set; }
public bool IncludeHealthWarnings { get; set; }
public override bool Enable => OnGrab || OnDownload || (OnDownload && OnUpgrade);
public override bool Enable => OnGrab || OnDownload || (OnDownload && OnUpgrade) || OnHealthIssue;
}
}

View File

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Notifications
List<INotification> OnDownloadEnabled();
List<INotification> OnUpgradeEnabled();
List<INotification> OnRenameEnabled();
List<INotification> OnHealthIssueEnabled();
}
public class NotificationFactory : ProviderFactory<INotification, NotificationDefinition>, INotificationFactory
@ -42,6 +43,11 @@ namespace NzbDrone.Core.Notifications
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnRename).ToList();
}
public List<INotification> OnHealthIssueEnabled()
{
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnHealthIssue).ToList();
}
public override void SetProviderCharacteristics(INotification provider, NotificationDefinition definition)
{
base.SetProviderCharacteristics(provider, definition);
@ -50,6 +56,7 @@ namespace NzbDrone.Core.Notifications
definition.SupportsOnDownload = provider.SupportsOnDownload;
definition.SupportsOnUpgrade = provider.SupportsOnUpgrade;
definition.SupportsOnRename = provider.SupportsOnRename;
definition.SupportsOnHealthIssue = provider.SupportsOnHealthIssue;
}
}
}

View File

@ -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);
}
}
}
}
}

View File

@ -26,6 +26,10 @@ namespace NzbDrone.Core.Notifications.Plex.HomeTheater
_plexClientService.Notify(Settings, EPISODE_DOWNLOADED_TITLE_BRANDED, message.Message);
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_plexClientService.Notify(Settings, HEALTH_ISSUE_TITLE_BRANDED, message.Message);
}
public override ValidationResult Test()
{

View File

@ -28,6 +28,11 @@ namespace NzbDrone.Core.Notifications.Prowl
_prowlService.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, Settings.ApiKey, (NotificationPriority)Settings.Priority);
}
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_prowlService.SendNotification(HEALTH_ISSUE_TITLE, message.Message, Settings.ApiKey, (NotificationPriority)Settings.Priority);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -29,6 +29,11 @@ namespace NzbDrone.Core.Notifications.PushBullet
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE_BRANDED, message.Message, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE_BRANDED, healthCheck.Message, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -26,6 +26,11 @@ namespace NzbDrone.Core.Notifications.Pushover
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -70,6 +70,23 @@ namespace NzbDrone.Core.Notifications.Slack
_proxy.SendPayload(payload, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
var attachments = new List<Attachment>
{
new Attachment
{
Title = healthCheck.Source.Name,
Text = healthCheck.Message,
Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? "warning" : "danger"
}
};
var payload = CreatePayload("Health Issue", attachments);
_proxy.SendPayload(payload, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -26,6 +26,11 @@ namespace NzbDrone.Core.Notifications.Telegram
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE, message.Message, Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheck.Message, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

View File

@ -29,6 +29,11 @@ namespace NzbDrone.Core.Notifications.Twitter
_twitterService.SendNotification($"Imported: {message.Message}", Settings);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
_twitterService.SendNotification($"Health Issue: {healthCheck.Message}", Settings);
}
public override object RequestAction(string action, IDictionary<string, string> query)
{
if (action == "startOAuth")

View File

@ -41,6 +41,11 @@ namespace NzbDrone.Core.Notifications.Xbmc
UpdateAndClean(series);
}
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
Notify(Settings, HEALTH_ISSUE_TITLE_BRANDED, healthCheck.Message);
}
public override string Name => "Kodi";
public override ValidationResult Test()

View File

@ -9,10 +9,13 @@ namespace Sonarr.Api.V3.Notifications
public bool OnDownload { get; set; }
public bool OnUpgrade { get; set; }
public bool OnRename { get; set; }
public bool OnHealthIssue { get; set; }
public bool SupportsOnGrab { get; set; }
public bool SupportsOnDownload { get; set; }
public bool SupportsOnUpgrade { get; set; }
public bool SupportsOnRename { get; set; }
public bool SupportsOnHealthIssue { get; set; }
public bool IncludeHealthWarnings { get; set; }
public string TestCommand { get; set; }
}
@ -28,10 +31,13 @@ namespace Sonarr.Api.V3.Notifications
resource.OnDownload = definition.OnDownload;
resource.OnUpgrade = definition.OnUpgrade;
resource.OnRename = definition.OnRename;
resource.OnHealthIssue = definition.OnHealthIssue;
resource.SupportsOnGrab = definition.SupportsOnGrab;
resource.SupportsOnDownload = definition.SupportsOnDownload;
resource.SupportsOnUpgrade = definition.SupportsOnUpgrade;
resource.SupportsOnRename = definition.SupportsOnRename;
resource.SupportsOnHealthIssue = definition.SupportsOnHealthIssue;
resource.IncludeHealthWarnings = definition.IncludeHealthWarnings;
return resource;
}
@ -46,10 +52,13 @@ namespace Sonarr.Api.V3.Notifications
definition.OnDownload = resource.OnDownload;
definition.OnUpgrade = resource.OnUpgrade;
definition.OnRename = resource.OnRename;
definition.OnHealthIssue = resource.OnHealthIssue;
definition.SupportsOnGrab = resource.SupportsOnGrab;
definition.SupportsOnDownload = resource.SupportsOnDownload;
definition.SupportsOnUpgrade = resource.SupportsOnUpgrade;
definition.SupportsOnRename = resource.SupportsOnRename;
definition.SupportsOnHealthIssue = resource.SupportsOnHealthIssue;
definition.IncludeHealthWarnings = resource.IncludeHealthWarnings;
return definition;
}