sensor-mon: Watch for InterfacesAdded

Start handling the InterfacesAdded signal for the threshold interfaces.
This is so that if a sensor has a threshold alarm set, but then restarts
and then doesn't have it set, sensor-monitor will get the update to the
new good value.

Previously, sensor-monitor would still log a threshold alarm on every
power on after a sensor daemon restarted and then showed no alarm.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I691c8949165bc29ac2eab4190e5dc9a9283bd2e6
diff --git a/sensor-monitor/threshold_alarm_logger.cpp b/sensor-monitor/threshold_alarm_logger.cpp
index b2fd7e8..03b35ba 100644
--- a/sensor-monitor/threshold_alarm_logger.cpp
+++ b/sensor-monitor/threshold_alarm_logger.cpp
@@ -44,6 +44,9 @@
 constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value";
 constexpr auto assocInterface = "xyz.openbmc_project.Association";
 
+const std::vector<std::string> thresholdIfaceNames{
+    warningInterface, criticalInterface, perfLossInterface};
+
 using ErrorData = std::tuple<ErrorName, Entry::Level>;
 
 /**
@@ -112,7 +115,12 @@
                        "type='signal',member='InterfacesRemoved',arg0path="
                        "'/xyz/openbmc_project/sensors/'",
                        std::bind(&ThresholdAlarmLogger::interfacesRemoved, this,
-                                 std::placeholders::_1))
+                                 std::placeholders::_1)),
+    ifacesAddedMatch(bus,
+                     "type='signal',member='InterfacesAdded',arg0path="
+                     "'/xyz/openbmc_project/sensors/'",
+                     std::bind(&ThresholdAlarmLogger::interfacesAdded, this,
+                               std::placeholders::_1))
 {
     _powerState->addCallback("thresholdMon",
                              std::bind(&ThresholdAlarmLogger::powerStateChanged,
@@ -143,6 +151,47 @@
 
     msg.read(interface, properties);
 
+    checkProperties(sensorPath, interface, properties);
+}
+
+void ThresholdAlarmLogger::interfacesRemoved(sdbusplus::message_t& msg)
+{
+    sdbusplus::message::object_path path;
+    std::vector<std::string> interfaces;
+
+    msg.read(path, interfaces);
+
+    for (const auto& interface : interfaces)
+    {
+        if (std::find(thresholdIfaceNames.begin(), thresholdIfaceNames.end(),
+                      interface) != thresholdIfaceNames.end())
+        {
+            alarms.erase(InterfaceKey{path, interface});
+        }
+    }
+}
+
+void ThresholdAlarmLogger::interfacesAdded(sdbusplus::message_t& msg)
+{
+    sdbusplus::message::object_path path;
+    std::map<std::string, std::map<std::string, std::variant<bool>>> interfaces;
+
+    msg.read(path, interfaces);
+
+    for (const auto& [interface, properties] : interfaces)
+    {
+        if (std::find(thresholdIfaceNames.begin(), thresholdIfaceNames.end(),
+                      interface) != thresholdIfaceNames.end())
+        {
+            checkProperties(path, interface, properties);
+        }
+    }
+}
+
+void ThresholdAlarmLogger::checkProperties(
+    const std::string& sensorPath, const std::string& interface,
+    const std::map<std::string, std::variant<bool>>& properties)
+{
     auto alarmProperties = thresholdData.find(interface);
     if (alarmProperties == thresholdData.end())
     {
@@ -180,25 +229,6 @@
     }
 }
 
-void ThresholdAlarmLogger::interfacesRemoved(sdbusplus::message_t& msg)
-{
-    static const std::vector<std::string> thresholdNames{
-        warningInterface, criticalInterface, perfLossInterface};
-    sdbusplus::message::object_path path;
-    std::vector<std::string> interfaces;
-
-    msg.read(path, interfaces);
-
-    for (const auto& interface : interfaces)
-    {
-        if (std::find(thresholdNames.begin(), thresholdNames.end(),
-                      interface) != thresholdNames.end())
-        {
-            alarms.erase(InterfaceKey{path, interface});
-        }
-    }
-}
-
 void ThresholdAlarmLogger::checkThresholds(const std::string& interface,
                                            const std::string& sensorPath,
                                            const std::string& service)