19
19
using Seq . Apps ;
20
20
using Seq . Input . HealthCheck . Data ;
21
21
using Seq . Input . HealthCheck . Util ;
22
+ // ReSharper disable UnusedType.Global
22
23
// ReSharper disable MemberCanBePrivate.Global
23
24
// ReSharper disable UnusedAutoPropertyAccessor.Global
24
25
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
25
26
26
- namespace Seq . Input . HealthCheck
27
+ namespace Seq . Input . HealthCheck ;
28
+
29
+ [ SeqApp ( "Health Check Input" ,
30
+ Description = "Periodically GET an HTTP resource and publish response metrics to Seq." ) ]
31
+ public class HealthCheckInput : SeqApp , IPublishJson , IDisposable
27
32
{
28
- [ SeqApp ( "Health Check Input" ,
29
- Description = "Periodically GET an HTTP resource and publish response metrics to Seq." ) ]
30
- public class HealthCheckInput : SeqApp , IPublishJson , IDisposable
33
+ readonly List < HealthCheckTask > _healthCheckTasks = [ ] ;
34
+ HttpClient ? _httpClient ;
35
+
36
+ [ SeqAppSetting (
37
+ DisplayName = "Target URLs" ,
38
+ HelpText = "The HTTP or HTTPS URL that the health check will periodically GET. Multiple URLs " +
39
+ "can be checked; enter one per line." ,
40
+ InputType = SettingInputType . LongText ) ]
41
+ public string TargetUrl { get ; set ; } = null ! ;
42
+
43
+ [ SeqAppSetting (
44
+ DisplayName = "Follow Redirects" ,
45
+ IsOptional = true ,
46
+ HelpText = "If selected, the HTTP request will follow redirects. By default, health checks that trigger redirects will fail." ,
47
+ InputType = SettingInputType . Checkbox ) ]
48
+ public bool FollowRedirects { get ; set ; } = false ;
49
+
50
+ [ SeqAppSetting ( InputType = SettingInputType . Password , IsOptional = true , DisplayName = "Authentication Header" ,
51
+ HelpText = "An optional `Name: Value` header, stored as sensitive data, for authentication purposes." ) ]
52
+ public string ? AuthenticationHeader { get ; set ; }
53
+
54
+ [ SeqAppSetting ( InputType = SettingInputType . LongText , IsOptional = true , DisplayName = "Other Headers" ,
55
+ HelpText = "Additional headers to send with the request, one per line in `Name: Value` format." ) ]
56
+ public string ? OtherHeaders { get ; set ; }
57
+
58
+ [ SeqAppSetting (
59
+ DisplayName = "Bypass HTTP caching" ,
60
+ IsOptional = true ,
61
+ HelpText = "If selected, the unique probe id will be appended to the target URL query string as " +
62
+ "`" + HttpHealthCheck . ProbeIdParameterName + "`, in order to disable any " +
63
+ "intermediary HTTP caching. The `Cache-Control: no-store` header will also be sent." ) ]
64
+ public bool BypassHttpCaching { get ; set ; }
65
+
66
+ [ SeqAppSetting (
67
+ DisplayName = "Interval (seconds)" ,
68
+ IsOptional = true ,
69
+ HelpText = "The time between checks; the default is 60." ) ]
70
+ public int IntervalSeconds { get ; set ; } = 60 ;
71
+
72
+ [ SeqAppSetting (
73
+ DisplayName = "Data extraction expression" ,
74
+ IsOptional = true ,
75
+ HelpText = "A Seq query language expression used to extract information from JSON responses. " +
76
+ "The expression will be evaluated against the response to produce a `Data` property" +
77
+ " on the resulting event. Use the special value `@Properties` to capture the whole " +
78
+ "response. The response must be UTF-8 `application/json` for this to be applied." ) ]
79
+ public string ? DataExtractionExpression { get ; set ; }
80
+
81
+ public void Start ( TextWriter inputWriter )
31
82
{
32
- readonly List < HealthCheckTask > _healthCheckTasks = new List < HealthCheckTask > ( ) ;
33
- HttpClient ? _httpClient ;
34
-
35
- [ SeqAppSetting (
36
- DisplayName = "Target URLs" ,
37
- HelpText = "The HTTP or HTTPS URL that the health check will periodically GET. Multiple URLs " +
38
- "can be checked; enter one per line." ,
39
- InputType = SettingInputType . LongText ) ]
40
- public string TargetUrl { get ; set ; } = null ! ;
41
-
42
- [ SeqAppSetting ( InputType = SettingInputType . Password , IsOptional = true , DisplayName = "Authentication Header" ,
43
- HelpText = "An optional `Name: Value` header, stored as sensitive data, for authentication purposes." ) ]
44
- public string ? AuthenticationHeader { get ; set ; }
45
-
46
- [ SeqAppSetting ( InputType = SettingInputType . LongText , IsOptional = true , DisplayName = "Other Headers" ,
47
- HelpText = "Additional headers to send with the request, one per line in `Name: Value` format." ) ]
48
- public string ? OtherHeaders { get ; set ; }
49
-
50
- [ SeqAppSetting (
51
- DisplayName = "Bypass HTTP caching" ,
52
- IsOptional = true ,
53
- HelpText = "If selected, the unique probe id will be appended to the target URL query string as " +
54
- "`" + HttpHealthCheck . ProbeIdParameterName + "`, in order to disable any " +
55
- "intermediary HTTP caching. The `Cache-Control: no-store` header will also be sent." ) ]
56
- public bool BypassHttpCaching { get ; set ; }
57
-
58
- [ SeqAppSetting (
59
- DisplayName = "Interval (seconds)" ,
60
- IsOptional = true ,
61
- HelpText = "The time between checks; the default is 60." ) ]
62
- public int IntervalSeconds { get ; set ; } = 60 ;
63
-
64
- [ SeqAppSetting (
65
- DisplayName = "Data extraction expression" ,
66
- IsOptional = true ,
67
- HelpText = "A Seq query language expression used to extract information from JSON responses. " +
68
- "The expression will be evaluated against the response to produce a `Data` property" +
69
- " on the resulting event. Use the special value `@Properties` to capture the whole " +
70
- "response. The response must be UTF-8 `application/json` for this to be applied." ) ]
71
- public string ? DataExtractionExpression { get ; set ; }
72
-
73
- public void Start ( TextWriter inputWriter )
74
- {
75
- _httpClient = HttpHealthCheckClient . Create ( ) ;
76
- var reporter = new HealthCheckReporter ( inputWriter ) ;
77
-
78
- JsonDataExtractor ? extractor = null ;
79
- if ( ! string . IsNullOrWhiteSpace ( DataExtractionExpression ) )
80
- extractor = new JsonDataExtractor ( DataExtractionExpression ) ;
81
-
82
- var targetUrls = TargetUrl . Split ( new [ ] { '\r ' , '\n ' } , StringSplitOptions . RemoveEmptyEntries ) ;
83
- foreach ( var targetUrl in targetUrls )
84
- {
85
- var healthCheck = new HttpHealthCheck (
86
- _httpClient ,
87
- App . Title ,
88
- targetUrl ,
89
- HeaderSettingFormat . FromSettings ( AuthenticationHeader , OtherHeaders ) ,
90
- extractor ,
91
- BypassHttpCaching ) ;
92
-
93
- _healthCheckTasks . Add ( new HealthCheckTask (
94
- healthCheck ,
95
- TimeSpan . FromSeconds ( IntervalSeconds ) ,
96
- reporter ,
97
- Log ) ) ;
98
- }
99
- }
83
+ _httpClient = HttpHealthCheckClient . Create ( ) ;
84
+ var reporter = new HealthCheckReporter ( inputWriter ) ;
100
85
101
- public void Stop ( )
102
- {
103
- foreach ( var task in _healthCheckTasks )
104
- task . Stop ( ) ;
105
- }
86
+ JsonDataExtractor ? extractor = null ;
87
+ if ( ! string . IsNullOrWhiteSpace ( DataExtractionExpression ) )
88
+ extractor = new JsonDataExtractor ( DataExtractionExpression ) ;
106
89
107
- public void Dispose ( )
90
+ var targetUrls = TargetUrl . Split ( new [ ] { '\r ' , '\n ' } , StringSplitOptions . RemoveEmptyEntries ) ;
91
+ foreach ( var targetUrl in targetUrls )
108
92
{
109
- foreach ( var task in _healthCheckTasks )
110
- task . Dispose ( ) ;
93
+ var healthCheck = new HttpHealthCheck (
94
+ _httpClient ,
95
+ App . Title ,
96
+ targetUrl ,
97
+ HeaderSettingFormat . FromSettings ( AuthenticationHeader , OtherHeaders ) ,
98
+ extractor ,
99
+ BypassHttpCaching ,
100
+ FollowRedirects ) ;
111
101
112
- _httpClient ? . Dispose ( ) ;
102
+ _healthCheckTasks . Add ( new HealthCheckTask (
103
+ healthCheck ,
104
+ TimeSpan . FromSeconds ( IntervalSeconds ) ,
105
+ reporter ,
106
+ Log ) ) ;
113
107
}
114
108
}
115
- }
109
+
110
+ public void Stop ( )
111
+ {
112
+ foreach ( var task in _healthCheckTasks )
113
+ task . Stop ( ) ;
114
+ }
115
+
116
+ public void Dispose ( )
117
+ {
118
+ foreach ( var task in _healthCheckTasks )
119
+ task . Dispose ( ) ;
120
+
121
+ _httpClient ? . Dispose ( ) ;
122
+ }
123
+ }
0 commit comments