-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCustomHealthCheck.cs
82 lines (71 loc) · 2.2 KB
/
CustomHealthCheck.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections.Generic;
using System.Threading.Tasks;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.HealthChecks;
using Umbraco.Extensions;
namespace DoStuff.Core.HealthChecks
{
/// <summary>
/// Register the health check
/// </summary>
public class CustomHealthCheckComposer : IUserComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.HealthChecks().Add<CustomHealthCheck>();
}
}
/// <summary>
/// simple heath check - counts to 100, because it can.
/// </summary>
[HealthCheck("D5ADD41C-E9E9-434B-832D-282B237366C2",
"Custom Health Checks",
Description = "Some Custom Health Checks",
Group = "DoStuff Checks")]
public class CustomHealthCheck : HealthCheck
{
public CustomHealthCheck()
{
}
public override HealthCheckStatus ExecuteAction(HealthCheckAction action)
{
switch (action.Alias)
{
case "count":
return ExecuteCount();
}
return null;
}
public override Task<IEnumerable<HealthCheckStatus>> GetStatus()
{
return Task.FromResult(GetCountStatus().AsEnumerableOfOne());
}
///
private HealthCheckStatus GetCountStatus()
{
// this is where you check the status of your check
return new HealthCheckStatus("We haven't counted yet")
{
ResultType = StatusResultType.Warning,
Description = "We like to count to 100",
Actions = new List<HealthCheckAction>()
{
new HealthCheckAction("count", this.Id)
{
Name = "Count to 100"
}
}
};
}
private HealthCheckStatus ExecuteCount()
{
// this is where you do the things to fix your check
for (int i = 0; i < 100; i++)
{
//counting...
}
return new HealthCheckStatus("Counted to 100");
}
}
}