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

58 lines
1.7 KiB
C#
Raw Normal View History

2014-02-26 05:40:47 +00:00
using System;
using System.Text.RegularExpressions;
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; }
2014-02-26 05:40:47 +00:00
public String Message { get; set; }
public Uri 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(' ', '-');
}
private static Uri MakeWikiUrl(String fragment)
{
var rootUri = new Uri("https://github.com/Sonarr/Sonarr/wiki/Health-checks");
if (fragment.StartsWith("#"))
{ // Mono doesn't understand # and generates a different url than windows.
return new Uri(rootUri + fragment);
}
else
{
var fragmentUri = new Uri(fragment, UriKind.Relative);
return new Uri(rootUri, fragmentUri);
}
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
}
}