monitor: Allowing ignoring fan FRU func status
Make the 'num_sensors_nonfunc_for_fan_nonfunc' JSON entry be optional,
and if it isn't present then don't set the parent fan FRU inventory
object functional state when the tach sensor functional states change.
This is necessary because on some systems some other entity will be
managing the FRU level functional state.
This also adds a trace when the tach sensor functional state changes,
since if the FRU functional state updating is turned off then the
existing traces won't appear.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I1be9cc335c15a78d342e2e7ea4e5108a66d29de3
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 6abd2da..b5092c0 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -15,6 +15,7 @@
*/
#include "fan.hpp"
+#include "logging.hpp"
#include "sdbusplus.hpp"
#include "system.hpp"
#include "types.hpp"
@@ -55,7 +56,8 @@
std::bind(std::mem_fn(&Fan::presenceChanged), this,
std::placeholders::_1))
{
- // Start from a known state of functional
+ // Start from a known state of functional (even if
+ // _numSensorFailsForNonFunc is 0)
updateInventory(true);
// Setup tach sensors for monitoring
@@ -74,8 +76,11 @@
}
catch (InvalidSensorError& e)
{
- // Count the number of failed tach sensors
- if (++_numFailedSensor >= _numSensorFailsForNonFunc)
+ // Count the number of failed tach sensors, though if
+ // _numSensorFailsForNonFunc is zero that means the fan should not
+ // be set to nonfunctional.
+ if (_numSensorFailsForNonFunc &&
+ (++_numFailedSensor >= _numSensorFailsForNonFunc))
{
// Mark associated fan as nonfunctional
updateInventory(false);
@@ -212,30 +217,39 @@
{
sensor.setFunctional(!sensor.functional());
- // If the fan was nonfunctional and enough sensors are now OK,
- // the fan can go back to functional
- if (!_functional && !tooManySensorsNonfunctional())
+ getLogger().log(
+ fmt::format("Setting tach sensor {} functional state to {}. "
+ "Actual speed: {} Target speed: {}",
+ sensor.name(), sensor.functional(), sensor.getInput(),
+ sensor.getTarget()));
+
+ // A zero value for _numSensorFailsForNonFunc means we aren't dealing
+ // with fan FRU functional status, only sensor functional status.
+ if (_numSensorFailsForNonFunc)
{
- log<level::INFO>(
- fmt::format("Setting fan {} back to functional", _name).c_str());
+ // If the fan was nonfunctional and enough sensors are now OK,
+ // the fan can go back to functional
+ if (!_functional && !tooManySensorsNonfunctional())
+ {
+ getLogger().log(
+ fmt::format("Setting fan {} back to functional", _name));
- updateInventory(true);
- }
+ updateInventory(true);
+ }
- // If the fan is currently functional, but too many
- // contained sensors are now nonfunctional, update
- // the whole fan nonfunctional.
- if (_functional && tooManySensorsNonfunctional())
- {
- log<level::ERR>(fmt::format("Setting fan {} to nonfunctional "
- "Sensor: {} "
- "Actual speed: {} "
- "Target speed: {}",
- _name, sensor.name(), sensor.getInput(),
- sensor.getTarget())
- .c_str());
-
- updateInventory(false);
+ // If the fan is currently functional, but too many
+ // contained sensors are now nonfunctional, update
+ // the whole fan nonfunctional.
+ if (_functional && tooManySensorsNonfunctional())
+ {
+ getLogger().log(fmt::format("Setting fan {} to nonfunctional "
+ "Sensor: {} "
+ "Actual speed: {} "
+ "Target speed: {}",
+ _name, sensor.name(), sensor.getInput(),
+ sensor.getTarget()));
+ updateInventory(false);
+ }
}
_system.fanStatusChange(*this);
diff --git a/monitor/json_parser.cpp b/monitor/json_parser.cpp
index bd239c6..1c06f01 100644
--- a/monitor/json_parser.cpp
+++ b/monitor/json_parser.cpp
@@ -172,16 +172,14 @@
{
if (!fan.contains("inventory") ||
!fan.contains("allowed_out_of_range_time") ||
- !fan.contains("deviation") ||
- !fan.contains("num_sensors_nonfunc_for_fan_nonfunc") ||
- !fan.contains("sensors"))
+ !fan.contains("deviation") || !fan.contains("sensors"))
{
// Log error on missing required parameters
log<level::ERR>(
"Missing required fan monitor definition parameters",
entry("REQUIRED_PARAMETERS=%s",
"{inventory, allowed_out_of_range_time, deviation, "
- "num_sensors_nonfunc_for_fan_nonfunc, sensors}"));
+ "sensors}"));
throw std::runtime_error(
"Missing required fan monitor definition parameters");
}
@@ -202,6 +200,16 @@
monitorDelay = fan["monitor_start_delay"].get<size_t>();
}
+ // num_sensors_nonfunc_for_fan_nonfunc is optional and defaults
+ // to zero if not present, meaning the code will not set the
+ // parent fan to nonfunctional based on sensors.
+ size_t nonfuncSensorsCount = 0;
+ if (fan.contains("num_sensors_nonfunc_for_fan_nonfunc"))
+ {
+ nonfuncSensorsCount =
+ fan["num_sensors_nonfunc_for_fan_nonfunc"].get<size_t>();
+ }
+
// Handle optional conditions
auto cond = std::optional<Condition>();
if (fan.contains("condition"))
@@ -235,8 +243,7 @@
fanDefs.emplace_back(
std::tuple(fan["inventory"].get<std::string>(), funcDelay,
fan["allowed_out_of_range_time"].get<size_t>(),
- fan["deviation"].get<size_t>(),
- fan["num_sensors_nonfunc_for_fan_nonfunc"].get<size_t>(),
+ fan["deviation"].get<size_t>(), nonfuncSensorsCount,
monitorDelay, sensorDefs, cond));
}