Mercurial > servermonitor
comparison ServerMonitor/Objects/Check.cs @ 1:9e92780ebc0f
Additional validation for SSH check
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Tue, 01 Jan 2019 21:14:47 -0500 |
parents | 3e1a2131f897 |
children |
comparison
equal
deleted
inserted
replaced
0:3e1a2131f897 | 1:9e92780ebc0f |
---|---|
167 match = re.IsMatch(resultValue); | 167 match = re.IsMatch(resultValue); |
168 } | 168 } |
169 else | 169 else |
170 { | 170 { |
171 if (matchType.In(MatchType.Equals, MatchType.NotEquals)) | 171 if (matchType.In(MatchType.Equals, MatchType.NotEquals)) |
172 { | |
172 match = expectedPattern == resultValue; | 173 match = expectedPattern == resultValue; |
173 else | 174 } |
175 else if (matchType.In(MatchType.Contains, MatchType.NotContains)) | |
176 { | |
174 match = resultValue.Contains(expectedPattern); | 177 match = resultValue.Contains(expectedPattern); |
178 } | |
179 else | |
180 { | |
181 if (decimal.TryParse(expectedPattern, out decimal expectedNumeric) && | |
182 decimal.TryParse(resultValue, out decimal resultNumeric)) | |
183 { | |
184 match = (matchType == MatchType.GreaterThan && resultNumeric > expectedNumeric) || | |
185 (matchType == MatchType.LessThan && resultNumeric < expectedNumeric); | |
186 } | |
187 else | |
188 { | |
189 return Fail(string.Format("{0} is not numeric: {1}", description, resultValue)); | |
190 } | |
191 } | |
175 } | 192 } |
176 | 193 |
177 if (matchType.In(MatchType.Equals, MatchType.Contains)) | 194 if (matchType.In(MatchType.Equals, MatchType.Contains)) |
178 { | 195 { |
179 if (match) | 196 if (match) |
180 return Pass(string.Format("{0} {1} the pattern: {2}", description, matchType.ToString().ToLower(), expectedPattern)); | 197 return Pass(string.Format("{0} {1} the pattern: {2}", description, matchType.ToString().ToLower(), expectedPattern)); |
181 else | 198 else |
182 return Fail(string.Format("{0} does not {1} the pattern: {2} ({0}: {3})", description, matchType.ToString().ToLower().TrimEnd('s'), expectedPattern, resultValue)); | 199 return Fail(string.Format("{0} does not {1} the pattern: {2} ({0}: {3})", description, matchType.ToString().ToLower().TrimEnd('s'), expectedPattern, resultValue)); |
183 } | 200 } |
184 else | 201 else if (matchType.In(MatchType.NotEquals, MatchType.NotContains)) |
185 { | 202 { |
186 if (match) | 203 if (match) |
187 return Fail(string.Format("{0} {1} the pattern: {2} ({0}: {3})", description, matchType.ToString().ToLower().Replace("not", ""), expectedPattern, resultValue)); | 204 return Fail(string.Format("{0} {1} the pattern: {2} ({0}: {3})", description, matchType.ToString().ToLower().Replace("not", ""), expectedPattern, resultValue)); |
188 else | 205 else |
189 return Pass(string.Format("{0} does not {1} the pattern: {2}", description, matchType.ToString().ToLower().TrimEnd('s').Replace("not", ""), expectedPattern)); | 206 return Pass(string.Format("{0} does not {1} the pattern: {2}", description, matchType.ToString().ToLower().TrimEnd('s').Replace("not", ""), expectedPattern)); |
207 } | |
208 else | |
209 { | |
210 if (match) | |
211 return Pass(string.Format("{0} ({1}) is {2} {3}", description, resultValue, matchType.ToString().ToLower().Replace("than", " than"), expectedPattern)); | |
212 else | |
213 return Fail(string.Format("{0} ({1}) is not {2} {3}", description, resultValue, matchType.ToString().ToLower().Replace("than", " than"), expectedPattern)); | |
190 } | 214 } |
191 } | 215 } |
192 | 216 |
193 protected CheckResult MergeResults(params CheckResult[] results) | 217 protected CheckResult MergeResults(params CheckResult[] results) |
194 { | 218 { |