sensor-monitor: Threshold events only when on
Update the monitor that creates event logs for threshold alarms to only
create them when system power is on. When system power changes to on,
the code will look for any active alarms to create event logs for. If
an alarm deasserts when power is off, the informational event log will
not be created.
While it could be argued that if event logs aren't desired when power is
off then sensors shouldn't even be active on D-Bus then, there are
cases where it could still be useful to see the sensor value and even an
asserted threshold alarm on Redfish then, such as inlet temp and
altitude/pressure.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I34ce6d26d06dbf1d7cabc184074c0c1f6be65d49
diff --git a/sensor-monitor/threshold_alarm_logger.cpp b/sensor-monitor/threshold_alarm_logger.cpp
index f50fb6a..50ccf5e 100644
--- a/sensor-monitor/threshold_alarm_logger.cpp
+++ b/sensor-monitor/threshold_alarm_logger.cpp
@@ -28,6 +28,7 @@
using namespace sdbusplus::xyz::openbmc_project::Logging::server;
using namespace phosphor::logging;
+using namespace phosphor::fan;
using namespace phosphor::fan::util;
const std::string warningInterface =
@@ -84,7 +85,9 @@
ThresholdAlarmLogger::ThresholdAlarmLogger(sdbusplus::bus::bus& bus,
sdeventplus::Event& event) :
bus(bus),
- event(event),
+ event(event), _powerState(std::make_unique<PGoodState>(
+ bus, std::bind(&ThresholdAlarmLogger::powerStateChanged,
+ this, std::placeholders::_1))),
warningMatch(bus,
"type='signal',member='PropertiesChanged',"
"path_namespace='/xyz/openbmc_project/sensors',"
@@ -158,7 +161,12 @@
if (alarmValue != alarms[key][propertyName])
{
alarms[key][propertyName] = alarmValue;
- createEventLog(sensorPath, interface, propertyName, alarmValue);
+
+ if (_powerState->isPowerOn())
+ {
+ createEventLog(sensorPath, interface, propertyName,
+ alarmValue);
+ }
}
}
}
@@ -184,7 +192,7 @@
// This is just for checking alarms on startup,
// so only look for active alarms.
- if (alarmValue)
+ if (alarmValue && _powerState->isPowerOn())
{
createEventLog(sensorPath, interface, property, alarmValue);
}
@@ -330,4 +338,29 @@
return std::string{};
}
+void ThresholdAlarmLogger::powerStateChanged(bool powerStateOn)
+{
+ if (powerStateOn)
+ {
+ checkThresholds();
+ }
+}
+
+void ThresholdAlarmLogger::checkThresholds()
+{
+ for (const auto& [interfaceKey, alarmMap] : alarms)
+ {
+ for (const auto& [propertyName, alarmValue] : alarmMap)
+ {
+ if (alarmValue)
+ {
+ const auto& sensorPath = std::get<0>(interfaceKey);
+ const auto& interface = std::get<1>(interfaceKey);
+
+ createEventLog(sensorPath, interface, propertyName, alarmValue);
+ }
+ }
+ }
+}
+
} // namespace sensor::monitor