sensor-mon: Check for threshold alarms on startup
Add the functionality to the ThresholdAlarmLogger class to check for any
active alarms on startup and make a createEventLog() call for them.
It also keeps track of the alarm values so that the propertiesChanged
handler can know if an alarm changed state or is just new.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I0dec7fc7c42d5007c1466700470faefbf6976dff
diff --git a/sensor-monitor/threshold_alarm_logger.hpp b/sensor-monitor/threshold_alarm_logger.hpp
index 89e460d..c95f396 100644
--- a/sensor-monitor/threshold_alarm_logger.hpp
+++ b/sensor-monitor/threshold_alarm_logger.hpp
@@ -22,6 +22,12 @@
namespace sensor::monitor
{
+using InterfaceName = std::string;
+using PropertyName = std::string;
+using ErrorName = std::string;
+using ObjectPath = std::string;
+using InterfaceKey = std::tuple<ObjectPath, InterfaceName>;
+
/**
* @class ThresholdAlarmLogger
*
@@ -69,6 +75,30 @@
void propertiesChanged(sdbusplus::message::message& msg);
/**
+ * @brief Checks for active alarms on the path and threshold interface
+ * passed in and creates event logs if necessary.
+ *
+ * @param[in] interface - The threshold interface
+ * @param[in] sensorPath - The sensor D-Bus path
+ * @param[in] service - The D-Bus service that owns the interface
+ */
+ void checkThresholds(const std::string& interface,
+ const std::string& sensorPath,
+ const std::string& service);
+
+ /**
+ * @brief Creates an event log for the alarm set/clear
+ *
+ * @param[in] sensorPath - The sensor object path
+ * @param[in] interface - The threshold interface
+ * @param[in] alarmProperty - The alarm property name
+ * @param[in] alarmValue - The alarm value
+ */
+ void createEventLog(const std::string& sensorPath,
+ const std::string& interface,
+ const std::string& alarmProperty, bool alarmValue);
+
+ /**
* @brief The sdbusplus bus object
*/
sdbusplus::bus::bus& bus;
@@ -92,6 +122,11 @@
* @brief The PerformanceLoss interface match object
*/
sdbusplus::bus::match::match perfLossMatch;
+
+ /**
+ * @brief The current alarm values
+ */
+ std::map<InterfaceKey, std::map<PropertyName, bool>> alarms;
};
} // namespace sensor::monitor