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
diff --git a/sensor-monitor/threshold_alarm_logger.hpp b/sensor-monitor/threshold_alarm_logger.hpp
index 07dce13..3e611d8 100644
--- a/sensor-monitor/threshold_alarm_logger.hpp
+++ b/sensor-monitor/threshold_alarm_logger.hpp
@@ -15,6 +15,8 @@
*/
#pragma once
+#include "power_state.hpp"
+
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
#include <sdeventplus/event.hpp>
@@ -42,6 +44,8 @@
*
* xyz.openbmc_project.Sensor.Threshold.Error.TemperatureWarningHigh
* xyz.openbmc_project.Sensor.Threshold.Error.TemperatureWarningHighClear
+ *
+ * Event logs are only created when the power is on.
*/
class ThresholdAlarmLogger
{
@@ -87,6 +91,13 @@
const std::string& service);
/**
+ * @brief Checks for all active alarms on all existing
+ * threshold interfaces and creates event logs
+ * if necessary.
+ */
+ void checkThresholds();
+
+ /**
* @brief Creates an event log for the alarm set/clear
*
* @param[in] sensorPath - The sensor object path
@@ -135,6 +146,15 @@
std::string getCallout(const std::string& sensorPath);
/**
+ * @brief The power state changed handler.
+ *
+ * Checks alarms when power is turned on.
+ *
+ * @param[in] powerStateOn - If the power is now on or off.
+ */
+ void powerStateChanged(bool powerStateOn);
+
+ /**
* @brief The sdbusplus bus object
*/
sdbusplus::bus::bus& bus;
@@ -145,6 +165,11 @@
sdeventplus::Event& event;
/**
+ * @brief The PowerState object to track power state changes.
+ */
+ std::unique_ptr<phosphor::fan::PowerState> _powerState;
+
+ /**
* @brief The Warning interface match object
*/
sdbusplus::bus::match::match warningMatch;