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/docs/monitor/deviation.md b/docs/monitor/deviation.md
index 14ae09e..ec3f814 100644
--- a/docs/monitor/deviation.md
+++ b/docs/monitor/deviation.md
@@ -1,9 +1,41 @@
# deviation
## Description
-
+The +/- percentage allowed for the sensors of a fan to deviate from any
+requested target before being deemed out-of-spec and not functioning as
+expected according to the target requested.
## Attribute Value(s)
+integer (0 - 100)
+Deviation is represented as a percentage, so only 0 to 100 are valid values.
## Example
+<pre><code>
+{
+ "fans": [
+ {
+ "inventory": "/system/chassis/motherboard/fan0",
+ "allowed_out_of_range_time": 30,
+ "functional_delay": 5,
+ <b><i>"deviation": 15</i></b>,
+ "num_sensors_nonfunc_for_fan_nonfunc": 1,
+ "monitor_start_delay": 30,
+ "fan_missing_error_delay": 20,
+ "nonfunc_rotor_error_delay": 0,
+ "sensors": [
+ {
+ "name": "fan0_0",
+ "has_target": true
+ },
+ {
+ "name": "fan0_1",
+ "has_target": false,
+ "factor": 1.45,
+ "offset": -909
+ }
+ ]
+ }
+ ]
+}
+</code></pre>
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));
}