monitor: Deviation attribute details(docs) & enforce range

The `deviation` attribute contains the +/- percentage allowed for the
sensors to deviate from any requested target.

Also enforcing the `deviation` value provided in the JSON configuration
is between 0 and 100.

Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: I3064e9b407c2edec7fb0fd36a2d1cd3f53d3e397
diff --git a/monitor/json_parser.cpp b/monitor/json_parser.cpp
index 82fc621..9218634 100644
--- a/monitor/json_parser.cpp
+++ b/monitor/json_parser.cpp
@@ -190,6 +190,19 @@
             throw std::runtime_error(
                 "Missing required fan monitor definition parameters");
         }
+        // Valid deviation range is 0 - 100%
+        auto deviation = fan["deviation"].get<size_t>();
+        if (deviation < 0 || 100 < deviation)
+        {
+            auto msg =
+                fmt::format(
+                    "Invalid deviation of {} found, must be between 0 and 100",
+                    deviation)
+                    .c_str();
+            log<level::ERR>(msg);
+            throw std::runtime_error(msg);
+        }
+
         // Construct the sensor definitions for this fan
         auto sensorDefs = getSensorDefs(fan["sensors"]);
 
@@ -310,7 +323,7 @@
 
         fanDefs.emplace_back(std::tuple(
             fan["inventory"].get<std::string>(), method, funcDelay, timeout,
-            fan["deviation"].get<size_t>(), nonfuncSensorsCount, monitorDelay,
+            deviation, nonfuncSensorsCount, monitorDelay,
             nonfuncRotorErrorDelay, fanMissingErrorDelay, sensorDefs, cond));
     }