comparison ServerMonitor/Objects/HttpCheck.cs @ 0:3e1a2131f897

Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
author Brad Greco <brad@bgreco.net>
date Mon, 31 Dec 2018 18:32:14 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3e1a2131f897
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Linq;
5 using System.Text;
6 using System.Text.RegularExpressions;
7 using System.Threading;
8 using System.Threading.Tasks;
9
10 namespace ServerMonitorApp
11 {
12 [DisplayName("HTTP check"), Description("Check the result of an HTTP request"), DisplayWeight(1)]
13 public class HttpCheck : Check
14 {
15 public string Url { get; set; }
16
17 public bool CheckResponseCode { get; set; }
18
19 public int ResponseCode { get; set; }
20
21 public bool CheckResponseLength { get; set; }
22
23 public string ResponseLengthMin { get; set; }
24
25 public string ResponseLengthMax { get; set; }
26
27 public bool CheckResponseBody { get; set; }
28
29 public MatchType ResponseBodyMatchType { get; set; }
30
31 public string ResponseBodyPattern { get; set; }
32
33 public bool ResponseBodyUseRegex { get; set; }
34
35 protected override Task<CheckResult> ExecuteCheckAsync(CancellationToken token)
36 {
37 throw new NotImplementedException();
38 }
39
40 public override string Validate(bool saving = true)
41 {
42 string message = base.Validate();
43 if (Url.IsNullOrEmpty())
44 message += "URL cannot be blank." + Environment.NewLine;
45 if (!CheckResponseCode && !CheckResponseLength && !CheckResponseBody)
46 message += "At least one check must be enabled." + Environment.NewLine;
47 if (CheckResponseBody && ResponseBodyUseRegex)
48 {
49 try
50 {
51 Regex re = new Regex(ResponseBodyPattern);
52 }
53 catch (ArgumentException)
54 {
55 message += "Invalid regular expression for response body." + Environment.NewLine;
56 }
57 }
58 return message;
59 }
60
61 //protected override CheckResult GetIntResult(int expectedValue, int resultValue, string description)
62 //{
63 // CheckResult result = base.GetIntResult(expectedValue, resultValue, description);
64
65 //}
66
67 /*
68 100 Continue[RFC7231, Section 6.2.1]
69 101 Switching Protocols[RFC7231, Section 6.2.2]
70 102 Processing[RFC2518]
71 103 Early Hints[RFC8297]
72 200 OK[RFC7231, Section 6.3.1]
73 201 Created[RFC7231, Section 6.3.2]
74 202 Accepted[RFC7231, Section 6.3.3]
75 203 Non-Authoritative Information[RFC7231, Section 6.3.4]
76 204 No Content[RFC7231, Section 6.3.5]
77 205 Reset Content[RFC7231, Section 6.3.6]
78 206 Partial Content[RFC7233, Section 4.1]
79 207 Multi-Status[RFC4918]
80 208 Already Reported[RFC5842]
81 226 IM Used[RFC3229]
82 300 Multiple Choices[RFC7231, Section 6.4.1]
83 301 Moved Permanently[RFC7231, Section 6.4.2]
84 302 Found[RFC7231, Section 6.4.3]
85 303 See Other[RFC7231, Section 6.4.4]
86 304 Not Modified[RFC7232, Section 4.1]
87 305 Use Proxy[RFC7231, Section 6.4.5]
88 306 (Unused)[RFC7231, Section 6.4.6]
89 307 Temporary Redirect[RFC7231, Section 6.4.7]
90 308 Permanent Redirect[RFC7538]
91 400 Bad Request[RFC7231, Section 6.5.1]
92 401 Unauthorized[RFC7235, Section 3.1]
93 402 Payment Required[RFC7231, Section 6.5.2]
94 403 Forbidden[RFC7231, Section 6.5.3]
95 404 Not Found[RFC7231, Section 6.5.4]
96 405 Method Not Allowed[RFC7231, Section 6.5.5]
97 406 Not Acceptable[RFC7231, Section 6.5.6]
98 407 Proxy Authentication Required[RFC7235, Section 3.2]
99 408 Request Timeout[RFC7231, Section 6.5.7]
100 409 Conflict[RFC7231, Section 6.5.8]
101 410 Gone[RFC7231, Section 6.5.9]
102 411 Length Required[RFC7231, Section 6.5.10]
103 412 Precondition Failed[RFC7232, Section 4.2][RFC8144, Section 3.2]
104 413 Payload Too Large[RFC7231, Section 6.5.11]
105 414 URI Too Long[RFC7231, Section 6.5.12]
106 415 Unsupported Media Type[RFC7231, Section 6.5.13][RFC7694, Section 3]
107 416 Range Not Satisfiable[RFC7233, Section 4.4]
108 417 Expectation Failed[RFC7231, Section 6.5.14]
109 421 Misdirected Request[RFC7540, Section 9.1.2]
110 422 Unprocessable Entity[RFC4918]
111 423 Locked[RFC4918]
112 424 Failed Dependency[RFC4918]
113 425 Too Early[RFC8470]
114 426 Upgrade Required[RFC7231, Section 6.5.15]
115 427 Unassigned
116 428 Precondition Required[RFC6585]
117 429 Too Many Requests[RFC6585]
118 430 Unassigned
119 431 Request Header Fields Too Large[RFC6585]
120 451 Unavailable For Legal Reasons[RFC7725]
121 500 Internal Server Error[RFC7231, Section 6.6.1]
122 501 Not Implemented[RFC7231, Section 6.6.2]
123 502 Bad Gateway[RFC7231, Section 6.6.3]
124 503 Service Unavailable[RFC7231, Section 6.6.4]
125 504 Gateway Timeout[RFC7231, Section 6.6.5]
126 505 HTTP Version Not Supported[RFC7231, Section 6.6.6]
127 506 Variant Also Negotiates[RFC2295]
128 507 Insufficient Storage[RFC4918]
129 508 Loop Detected[RFC5842]
130 509 Unassigned
131 510 Not Extended[RFC2774]
132 511 Network Authentication Required[RFC6585]
133 */
134 }
135 }