2014-02-26 05:40:47 +00:00
|
|
|
|
using System;
|
2014-06-03 21:04:28 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2014-02-26 05:40:47 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.HealthCheck
|
|
|
|
|
{
|
|
|
|
|
public class HealthCheck : ModelBase
|
|
|
|
|
{
|
2014-06-03 21:04:28 +00:00
|
|
|
|
private static readonly Regex CleanFragmentRegex = new Regex("[^a-z ]", RegexOptions.Compiled);
|
|
|
|
|
|
2014-04-10 00:15:13 +00:00
|
|
|
|
public Type Source { get; set; }
|
|
|
|
|
public HealthCheckResult Type { get; set; }
|
2014-02-26 05:40:47 +00:00
|
|
|
|
public String Message { get; set; }
|
2014-06-03 21:04:28 +00:00
|
|
|
|
public Uri WikiUrl { get; set; }
|
2014-02-26 05:40:47 +00:00
|
|
|
|
|
2014-04-10 00:15:13 +00:00
|
|
|
|
public HealthCheck(Type source)
|
2014-02-26 05:40:47 +00:00
|
|
|
|
{
|
2014-04-10 00:15:13 +00:00
|
|
|
|
Source = source;
|
|
|
|
|
Type = HealthCheckResult.Ok;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 21:04:28 +00:00
|
|
|
|
public HealthCheck(Type source, HealthCheckResult type, String message, String wikiFragment = null)
|
2014-04-10 00:15:13 +00:00
|
|
|
|
{
|
|
|
|
|
Source = source;
|
2014-02-26 05:40:47 +00:00
|
|
|
|
Type = type;
|
|
|
|
|
Message = message;
|
2014-06-03 21:04:28 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2015-02-06 20:18:13 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-10 00:15:13 +00:00
|
|
|
|
public enum HealthCheckResult
|
2014-02-26 05:40:47 +00:00
|
|
|
|
{
|
2014-04-10 00:15:13 +00:00
|
|
|
|
Ok = 0,
|
2014-02-26 05:40:47 +00:00
|
|
|
|
Warning = 1,
|
|
|
|
|
Error = 2
|
|
|
|
|
}
|
|
|
|
|
}
|