Associate BMC health sensors with chassis

This change adds association between the sensors and the bmc, such
that the BMC health sensors are ready to be picked up by bmcweb.

Tested: Added a BMC in phosphor-inventory, made a few temporary
changes to bmcweb so it treats BMCs as a chassis and populates
/redfish/v1/Chassis/bmc/Sensor entries, set up webui-vue, saw
the sensor readings in browser.

Change-Id: I1b5b9e9c97b37ecdef916712cb9f345858eb1ada
Signed-off-by: Sui Chen <suichen6@gmail.com>
diff --git a/healthMonitor.cpp b/healthMonitor.cpp
index 8861403..fb9e180 100644
--- a/healthMonitor.cpp
+++ b/healthMonitor.cpp
@@ -2,7 +2,6 @@
 
 #include "healthMonitor.hpp"
 
-#include <phosphor-logging/log.hpp>
 #include <sdbusplus/server/manager.hpp>
 #include <sdeventplus/event.hpp>
 
@@ -222,7 +221,7 @@
     ValueIface::value(value);
 }
 
-void HealthSensor::initHealthSensor()
+void HealthSensor::initHealthSensor(const std::vector<std::string>& chassisIds)
 {
     std::string logMsg = sensorConfig.name + " Health Sensor initialized";
     log<level::INFO>(logMsg.c_str());
@@ -267,6 +266,14 @@
 
     setSensorValueToDbus(value);
 
+    // Associate the sensor to chassis
+    std::vector<AssociationTuple> associationTuples;
+    for (const auto& chassisId : chassisIds)
+    {
+        associationTuples.push_back({"bmc", "all_sensors", chassisId});
+    }
+    AssociationDefinitionInterface::associations(associationTuples);
+
     /* Start the timer for reading sensor data at regular interval */
     readTimer.restart(std::chrono::milliseconds(sensorConfig.freq * 1000));
 }
@@ -377,13 +384,13 @@
 }
 
 /* Create dbus utilization sensor object for each configured sensors */
-void HealthMon::createHealthSensors()
+void HealthMon::createHealthSensors(const std::vector<std::string>& chassisIds)
 {
     for (auto& cfg : sensorConfigs)
     {
         std::string objPath = std::string(HEALTH_SENSOR_PATH) + cfg.name;
-        auto healthSensor =
-            std::make_shared<HealthSensor>(bus, objPath.c_str(), cfg);
+        auto healthSensor = std::make_shared<HealthSensor>(bus, objPath.c_str(),
+                                                           cfg, chassisIds);
         healthSensors.emplace(cfg.name, healthSensor);
 
         std::string logMsg = cfg.name + " Health Sensor created";
@@ -508,7 +515,6 @@
  */
 int main()
 {
-
     // Get a default event loop
     auto event = sdeventplus::Event::get_default();