sensor_monitor: Watch for interfacesRemoved

Now that the hwmontempsensor app can remove sensors from D-Bus when the
entity-manager config goes away, the sensor monitor needs to deal with
it.  It does so by watching for a threshold interface to be removed from
a sensor and removing that entry from its map of alarms to watch.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I6b48b20eb4d158e5e44566e46469421550d21686
diff --git a/sensor-monitor/threshold_alarm_logger.cpp b/sensor-monitor/threshold_alarm_logger.cpp
index 78dbc55..69ecb10 100644
--- a/sensor-monitor/threshold_alarm_logger.cpp
+++ b/sensor-monitor/threshold_alarm_logger.cpp
@@ -107,7 +107,12 @@
                   "arg0='" +
                       perfLossInterface + "'",
                   std::bind(&ThresholdAlarmLogger::propertiesChanged, this,
-                            std::placeholders::_1))
+                            std::placeholders::_1)),
+    ifacesRemovedMatch(bus,
+                       "type='signal',member='InterfacesRemoved',arg0path="
+                       "'/xyz/openbmc_project/sensors/'",
+                       std::bind(&ThresholdAlarmLogger::interfacesRemoved, this,
+                                 std::placeholders::_1))
 {
     _powerState->addCallback("thresholdMon",
                              std::bind(&ThresholdAlarmLogger::powerStateChanged,
@@ -175,6 +180,25 @@
     }
 }
 
+void ThresholdAlarmLogger::interfacesRemoved(sdbusplus::message::message& 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)