diff 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
line wrap: on
line diff
--- a/ServerMonitor/Objects/Check.cs	Mon Dec 31 18:32:14 2018 -0500
+++ b/ServerMonitor/Objects/Check.cs	Tue Jan 01 21:14:47 2019 -0500
@@ -169,9 +169,26 @@
             else
             {
                 if (matchType.In(MatchType.Equals, MatchType.NotEquals))
+                {
                     match = expectedPattern == resultValue;
+                }
+                else if (matchType.In(MatchType.Contains, MatchType.NotContains))
+                {
+                    match = resultValue.Contains(expectedPattern);
+                }
                 else
-                    match = resultValue.Contains(expectedPattern);
+                {
+                    if (decimal.TryParse(expectedPattern, out decimal expectedNumeric) &&
+                        decimal.TryParse(resultValue, out decimal resultNumeric))
+                    {
+                        match = (matchType == MatchType.GreaterThan && resultNumeric > expectedNumeric) ||
+                                (matchType == MatchType.LessThan    && resultNumeric < expectedNumeric);
+                    }
+                    else
+                    {
+                        return Fail(string.Format("{0} is not numeric: {1}", description, resultValue));
+                    }
+                }
             }
 
             if (matchType.In(MatchType.Equals, MatchType.Contains))
@@ -181,13 +198,20 @@
                 else
                     return Fail(string.Format("{0} does not {1} the pattern: {2} ({0}: {3})", description, matchType.ToString().ToLower().TrimEnd('s'), expectedPattern, resultValue));
             }
-            else
+            else if (matchType.In(MatchType.NotEquals, MatchType.NotContains))
             {
                 if (match)
                     return Fail(string.Format("{0} {1} the pattern: {2} ({0}: {3})", description, matchType.ToString().ToLower().Replace("not", ""), expectedPattern, resultValue));
                 else
                     return Pass(string.Format("{0} does not {1} the pattern: {2}", description, matchType.ToString().ToLower().TrimEnd('s').Replace("not", ""), expectedPattern));
             }
+            else
+            {
+                if (match)
+                    return Pass(string.Format("{0} ({1}) is {2} {3}", description, resultValue, matchType.ToString().ToLower().Replace("than", " than"), expectedPattern));
+                else
+                    return Fail(string.Format("{0} ({1}) is not {2} {3}", description, resultValue, matchType.ToString().ToLower().Replace("than", " than"), expectedPattern));
+            }
         }
 
         protected CheckResult MergeResults(params CheckResult[] results)