Lidarr/src/NzbDrone.Core/HealthCheck/HealthCheck.cs

54 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Text.RegularExpressions;
2016-02-29 23:33:28 +00:00
using NzbDrone.Common.Http;
2014-02-26 05:40:47 +00:00
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.HealthCheck
{
public class HealthCheck : ModelBase
{
private static readonly Regex CleanFragmentRegex = new Regex("[^a-z ]", RegexOptions.Compiled);
public Type Source { get; set; }
public HealthCheckResult Type { get; set; }
public string Message { get; set; }
2016-02-29 23:33:28 +00:00
public HttpUri WikiUrl { get; set; }
2014-02-26 05:40:47 +00:00
public HealthCheck()
{
}
public HealthCheck(Type source)
2014-02-26 05:40:47 +00:00
{
Source = source;
Type = HealthCheckResult.Ok;
}
public HealthCheck(Type source, HealthCheckResult type, string message, string wikiFragment = null)
{
Source = source;
2014-02-26 05:40:47 +00:00
Type = type;
Message = message;
WikiUrl = MakeWikiUrl(wikiFragment ?? MakeWikiFragment(message));
}
private static string MakeWikiFragment(string message)
{
2021-08-04 22:47:40 +00:00
return "#" + CleanFragmentRegex.Replace(message.ToLower(), string.Empty).Replace(' ', '-');
}
2016-02-29 23:33:28 +00:00
private static HttpUri MakeWikiUrl(string fragment)
{
2021-08-04 22:47:40 +00:00
return new HttpUri("https://wiki.servarr.com/lidarr/system") + new HttpUri(fragment);
2014-02-26 05:40:47 +00:00
}
}
public enum HealthCheckResult
2014-02-26 05:40:47 +00:00
{
Ok = 0,
Notice = 1,
Warning = 2,
Error = 3
2014-02-26 05:40:47 +00:00
}
}