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

49 lines
1.4 KiB
C#
Raw Normal View History

2014-02-26 05:40:47 +00:00
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(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)
{
return "#" + CleanFragmentRegex.Replace(message.ToLower(), string.Empty).Replace(' ', '-');
}
2016-02-29 23:33:28 +00:00
private static HttpUri MakeWikiUrl(string fragment)
{
2016-02-29 23:33:28 +00:00
return new HttpUri("https://github.com/Sonarr/Sonarr/wiki/Health-checks") + new HttpUri(fragment);
2014-02-26 05:40:47 +00:00
}
}
public enum HealthCheckResult
2014-02-26 05:40:47 +00:00
{
Ok = 0,
2014-02-26 05:40:47 +00:00
Warning = 1,
Error = 2
}
}