mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-28 23:27:08 -04:00
New: Option to send notification when a Health Check warning occurs
This commit is contained in:
@@ -26,6 +26,11 @@ namespace NzbDrone.Core.Notifications.Boxcar
|
||||
_proxy.SendNotification(MOVIE_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>();
|
||||
|
||||
@@ -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.Movies;
|
||||
using NzbDrone.Core.Validation;
|
||||
@@ -112,6 +113,18 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
||||
ExecuteScript(environmentVariables);
|
||||
}
|
||||
|
||||
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
|
||||
{
|
||||
var environmentVariables = new StringDictionary();
|
||||
|
||||
environmentVariables.Add("Radarr_EventType", "HealthIssue");
|
||||
environmentVariables.Add("Radarr_Health_Issue_Level", nameof(healthCheck.Type));
|
||||
environmentVariables.Add("Radarr_Health_Issue_Message", healthCheck.Message);
|
||||
environmentVariables.Add("Radarr_Health_Issue_Type", healthCheck.Source.Name);
|
||||
environmentVariables.Add("Radarr_Health_Issue_Wiki", healthCheck.WikiUrl.ToString() ?? string.Empty);
|
||||
|
||||
ExecuteScript(environmentVariables);
|
||||
}
|
||||
public override ValidationResult Test()
|
||||
{
|
||||
var failures = new List<ValidationFailure>();
|
||||
|
||||
@@ -53,6 +53,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>();
|
||||
|
||||
@@ -32,6 +32,10 @@ namespace NzbDrone.Core.Notifications.Email
|
||||
_emailService.SendEmail(Settings, MOVIE_DOWNLOADED_TITLE_BRANDED, body);
|
||||
}
|
||||
|
||||
public override void OnHealthIssue(HealthCheck.HealthCheck message)
|
||||
{
|
||||
_emailService.SendEmail(Settings, HEALTH_ISSUE_TITLE_BRANDED, message.Message);
|
||||
}
|
||||
|
||||
public override ValidationResult Test()
|
||||
{
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace NzbDrone.Core.Notifications.Gotify
|
||||
_proxy.SendNotification(MOVIE_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>();
|
||||
|
||||
@@ -10,9 +10,11 @@ namespace NzbDrone.Core.Notifications
|
||||
void OnGrab(GrabMessage grabMessage);
|
||||
void OnDownload(DownloadMessage message);
|
||||
void OnMovieRename(Movie movie);
|
||||
void OnHealthIssue(HealthCheck.HealthCheck healthCheck);
|
||||
bool SupportsOnGrab { get; }
|
||||
bool SupportsOnDownload { get; }
|
||||
bool SupportsOnUpgrade { get; }
|
||||
bool SupportsOnRename { get; }
|
||||
bool SupportsOnHealthIssue { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace NzbDrone.Core.Notifications.Join
|
||||
_proxy.SendNotification(MOVIE_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>();
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -10,9 +10,11 @@ namespace NzbDrone.Core.Notifications
|
||||
{
|
||||
protected const string MOVIE_GRABBED_TITLE = "Movie Grabbed";
|
||||
protected const string MOVIE_DOWNLOADED_TITLE = "Movie Downloaded";
|
||||
protected const string HEALTH_ISSUE_TITLE = "Health Check Failure";
|
||||
|
||||
protected const string MOVIE_GRABBED_TITLE_BRANDED = "Radarr - " + MOVIE_GRABBED_TITLE;
|
||||
protected const string MOVIE_DOWNLOADED_TITLE_BRANDED = "Radarr - " + MOVIE_DOWNLOADED_TITLE;
|
||||
protected const string HEALTH_ISSUE_TITLE_BRANDED = "Radarr - " + 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("OnMovieRename");
|
||||
public bool SupportsOnDownload => HasConcreteImplementation("OnDownload");
|
||||
public bool SupportsOnUpgrade => SupportsOnDownload;
|
||||
public bool SupportsOnHealthIssue => HasConcreteImplementation("OnHealthIssue");
|
||||
|
||||
protected TSettings Settings => (TSettings)Definition.Settings;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace NzbDrone.Core.Notifications.PushBullet
|
||||
_proxy.SendNotification(MOVIE_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>();
|
||||
|
||||
@@ -26,6 +26,11 @@ namespace NzbDrone.Core.Notifications.Pushover
|
||||
_proxy.SendNotification(MOVIE_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>();
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -26,6 +26,11 @@ namespace NzbDrone.Core.Notifications.Telegram
|
||||
_proxy.SendNotification(MOVIE_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>();
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace NzbDrone.Core.Notifications.Twitter
|
||||
_twitterService.SendNotification($"[Radarr] 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")
|
||||
|
||||
@@ -41,7 +41,12 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
||||
UpdateAndCleanMovie(movie);
|
||||
}
|
||||
|
||||
public override string Name => "Kodi (XBMC)";
|
||||
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
|
||||
{
|
||||
Notify(Settings, HEALTH_ISSUE_TITLE_BRANDED, healthCheck.Message);
|
||||
}
|
||||
|
||||
public override string Name => "Kodi";
|
||||
|
||||
public override ValidationResult Test()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user