xref: /openbmc/bmcweb/features/redfish/lib/sensors.hpp (revision 4bb3dc346522b5f1e3bf6241c64238837caff5d2)
108777fb0SLewanczyk, Dawid /*
208777fb0SLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation
308777fb0SLewanczyk, Dawid //
408777fb0SLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License");
508777fb0SLewanczyk, Dawid // you may not use this file except in compliance with the License.
608777fb0SLewanczyk, Dawid // You may obtain a copy of the License at
708777fb0SLewanczyk, Dawid //
808777fb0SLewanczyk, Dawid //      http://www.apache.org/licenses/LICENSE-2.0
908777fb0SLewanczyk, Dawid //
1008777fb0SLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software
1108777fb0SLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS,
1208777fb0SLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1308777fb0SLewanczyk, Dawid // See the License for the specific language governing permissions and
1408777fb0SLewanczyk, Dawid // limitations under the License.
1508777fb0SLewanczyk, Dawid */
1608777fb0SLewanczyk, Dawid #pragma once
1708777fb0SLewanczyk, Dawid 
1895a3ecadSAnthony Wilson #include "node.hpp"
1995a3ecadSAnthony Wilson 
2008777fb0SLewanczyk, Dawid #include <boost/algorithm/string/predicate.hpp>
2108777fb0SLewanczyk, Dawid #include <boost/algorithm/string/split.hpp>
2208777fb0SLewanczyk, Dawid #include <boost/container/flat_map.hpp>
2308777fb0SLewanczyk, Dawid #include <boost/range/algorithm/replace_copy_if.hpp>
249e27a22eSEd Tanous #include <cmath>
251abe55efSEd Tanous #include <dbus_singleton.hpp>
26413961deSRichard Marian Thomaiyar #include <utils/json_utils.hpp>
27abf2add6SEd Tanous #include <variant>
2808777fb0SLewanczyk, Dawid 
291abe55efSEd Tanous namespace redfish
301abe55efSEd Tanous {
3108777fb0SLewanczyk, Dawid 
3208777fb0SLewanczyk, Dawid using GetSubTreeType = std::vector<
3308777fb0SLewanczyk, Dawid     std::pair<std::string,
3408777fb0SLewanczyk, Dawid               std::vector<std::pair<std::string, std::vector<std::string>>>>>;
3508777fb0SLewanczyk, Dawid 
36adc4f0dbSShawn McCarney using SensorVariant =
37adc4f0dbSShawn McCarney     std::variant<int64_t, double, uint32_t, bool, std::string>;
38aa2e59c1SEd Tanous 
3908777fb0SLewanczyk, Dawid using ManagedObjectsVectorType = std::vector<std::pair<
40aa2e59c1SEd Tanous     sdbusplus::message::object_path,
4108777fb0SLewanczyk, Dawid     boost::container::flat_map<
42aa2e59c1SEd Tanous         std::string, boost::container::flat_map<std::string, SensorVariant>>>>;
4308777fb0SLewanczyk, Dawid 
4408777fb0SLewanczyk, Dawid /**
45588c3f0dSKowalski, Kamil  * SensorsAsyncResp
4608777fb0SLewanczyk, Dawid  * Gathers data needed for response processing after async calls are done
4708777fb0SLewanczyk, Dawid  */
481abe55efSEd Tanous class SensorsAsyncResp
491abe55efSEd Tanous {
5008777fb0SLewanczyk, Dawid   public:
51271584abSEd Tanous     SensorsAsyncResp(crow::Response& response, const std::string& chassisIdIn,
52271584abSEd Tanous                      const std::vector<const char*> typesIn,
532474adfaSEd Tanous                      const std::string& subNode) :
5443b761d0SEd Tanous         res(response),
55271584abSEd Tanous         chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode)
561abe55efSEd Tanous     {
5708777fb0SLewanczyk, Dawid     }
5808777fb0SLewanczyk, Dawid 
591abe55efSEd Tanous     ~SensorsAsyncResp()
601abe55efSEd Tanous     {
611abe55efSEd Tanous         if (res.result() == boost::beast::http::status::internal_server_error)
621abe55efSEd Tanous         {
631abe55efSEd Tanous             // Reset the json object to clear out any data that made it in
641abe55efSEd Tanous             // before the error happened todo(ed) handle error condition with
651abe55efSEd Tanous             // proper code
6655c7b7a2SEd Tanous             res.jsonValue = nlohmann::json::object();
6708777fb0SLewanczyk, Dawid         }
6808777fb0SLewanczyk, Dawid         res.end();
6908777fb0SLewanczyk, Dawid     }
70588c3f0dSKowalski, Kamil 
7155c7b7a2SEd Tanous     crow::Response& res;
72588c3f0dSKowalski, Kamil     std::string chassisId{};
7308777fb0SLewanczyk, Dawid     const std::vector<const char*> types;
742474adfaSEd Tanous     std::string chassisSubNode{};
7508777fb0SLewanczyk, Dawid };
7608777fb0SLewanczyk, Dawid 
7708777fb0SLewanczyk, Dawid /**
78d500549bSAnthony Wilson  * Possible states for physical inventory leds
79d500549bSAnthony Wilson  */
80d500549bSAnthony Wilson enum class LedState
81d500549bSAnthony Wilson {
82d500549bSAnthony Wilson     OFF,
83d500549bSAnthony Wilson     ON,
84d500549bSAnthony Wilson     BLINK,
85d500549bSAnthony Wilson     UNKNOWN
86d500549bSAnthony Wilson };
87d500549bSAnthony Wilson 
88d500549bSAnthony Wilson /**
89adc4f0dbSShawn McCarney  * D-Bus inventory item associated with one or more sensors.
90adc4f0dbSShawn McCarney  */
91adc4f0dbSShawn McCarney class InventoryItem
92adc4f0dbSShawn McCarney {
93adc4f0dbSShawn McCarney   public:
94adc4f0dbSShawn McCarney     InventoryItem(const std::string& objPath) :
95adc4f0dbSShawn McCarney         objectPath(objPath), name(), isPresent(true), isFunctional(true),
96adc4f0dbSShawn McCarney         isPowerSupply(false), manufacturer(), model(), partNumber(),
97d500549bSAnthony Wilson         serialNumber(), sensors(), ledObjectPath(""),
98d500549bSAnthony Wilson         ledState(LedState::UNKNOWN)
99adc4f0dbSShawn McCarney     {
100adc4f0dbSShawn McCarney         // Set inventory item name to last node of object path
101adc4f0dbSShawn McCarney         auto pos = objectPath.rfind('/');
102adc4f0dbSShawn McCarney         if ((pos != std::string::npos) && ((pos + 1) < objectPath.size()))
103adc4f0dbSShawn McCarney         {
104adc4f0dbSShawn McCarney             name = objectPath.substr(pos + 1);
105adc4f0dbSShawn McCarney         }
106adc4f0dbSShawn McCarney     }
107adc4f0dbSShawn McCarney 
108adc4f0dbSShawn McCarney     std::string objectPath;
109adc4f0dbSShawn McCarney     std::string name;
110adc4f0dbSShawn McCarney     bool isPresent;
111adc4f0dbSShawn McCarney     bool isFunctional;
112adc4f0dbSShawn McCarney     bool isPowerSupply;
113adc4f0dbSShawn McCarney     std::string manufacturer;
114adc4f0dbSShawn McCarney     std::string model;
115adc4f0dbSShawn McCarney     std::string partNumber;
116adc4f0dbSShawn McCarney     std::string serialNumber;
117adc4f0dbSShawn McCarney     std::set<std::string> sensors;
118d500549bSAnthony Wilson     std::string ledObjectPath;
119d500549bSAnthony Wilson     LedState ledState;
120adc4f0dbSShawn McCarney };
121adc4f0dbSShawn McCarney 
122adc4f0dbSShawn McCarney /**
123413961deSRichard Marian Thomaiyar  * @brief Get objects with connection necessary for sensors
124588c3f0dSKowalski, Kamil  * @param SensorsAsyncResp Pointer to object holding response data
12508777fb0SLewanczyk, Dawid  * @param sensorNames Sensors retrieved from chassis
12608777fb0SLewanczyk, Dawid  * @param callback Callback for processing gathered connections
12708777fb0SLewanczyk, Dawid  */
12808777fb0SLewanczyk, Dawid template <typename Callback>
129413961deSRichard Marian Thomaiyar void getObjectsWithConnection(
130413961deSRichard Marian Thomaiyar     std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
13149c53ac9SJohnathan Mantey     const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
1321abe55efSEd Tanous     Callback&& callback)
1331abe55efSEd Tanous {
134413961deSRichard Marian Thomaiyar     BMCWEB_LOG_DEBUG << "getObjectsWithConnection enter";
13503b5bae3SJames Feist     const std::string path = "/xyz/openbmc_project/sensors";
13608777fb0SLewanczyk, Dawid     const std::array<std::string, 1> interfaces = {
13708777fb0SLewanczyk, Dawid         "xyz.openbmc_project.Sensor.Value"};
13808777fb0SLewanczyk, Dawid 
13908777fb0SLewanczyk, Dawid     // Response handler for parsing objects subtree
1401abe55efSEd Tanous     auto respHandler = [callback{std::move(callback)}, SensorsAsyncResp,
1411abe55efSEd Tanous                         sensorNames](const boost::system::error_code ec,
1421abe55efSEd Tanous                                      const GetSubTreeType& subtree) {
143413961deSRichard Marian Thomaiyar         BMCWEB_LOG_DEBUG << "getObjectsWithConnection resp_handler enter";
1441abe55efSEd Tanous         if (ec)
1451abe55efSEd Tanous         {
1465f7d88c4SEd Tanous             messages::internalError(SensorsAsyncResp->res);
147413961deSRichard Marian Thomaiyar             BMCWEB_LOG_ERROR
148413961deSRichard Marian Thomaiyar                 << "getObjectsWithConnection resp_handler: Dbus error " << ec;
14908777fb0SLewanczyk, Dawid             return;
15008777fb0SLewanczyk, Dawid         }
15108777fb0SLewanczyk, Dawid 
15255c7b7a2SEd Tanous         BMCWEB_LOG_DEBUG << "Found " << subtree.size() << " subtrees";
15308777fb0SLewanczyk, Dawid 
15408777fb0SLewanczyk, Dawid         // Make unique list of connections only for requested sensor types and
15508777fb0SLewanczyk, Dawid         // found in the chassis
15608777fb0SLewanczyk, Dawid         boost::container::flat_set<std::string> connections;
157413961deSRichard Marian Thomaiyar         std::set<std::pair<std::string, std::string>> objectsWithConnection;
1581abe55efSEd Tanous         // Intrinsic to avoid malloc.  Most systems will have < 8 sensor
1591abe55efSEd Tanous         // producers
16008777fb0SLewanczyk, Dawid         connections.reserve(8);
16108777fb0SLewanczyk, Dawid 
16249c53ac9SJohnathan Mantey         BMCWEB_LOG_DEBUG << "sensorNames list count: " << sensorNames->size();
16349c53ac9SJohnathan Mantey         for (const std::string& tsensor : *sensorNames)
1641abe55efSEd Tanous         {
16555c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "Sensor to find: " << tsensor;
16608777fb0SLewanczyk, Dawid         }
16708777fb0SLewanczyk, Dawid 
16808777fb0SLewanczyk, Dawid         for (const std::pair<
16908777fb0SLewanczyk, Dawid                  std::string,
17008777fb0SLewanczyk, Dawid                  std::vector<std::pair<std::string, std::vector<std::string>>>>&
1711abe55efSEd Tanous                  object : subtree)
1721abe55efSEd Tanous         {
17349c53ac9SJohnathan Mantey             if (sensorNames->find(object.first) != sensorNames->end())
1741abe55efSEd Tanous             {
17549c53ac9SJohnathan Mantey                 for (const std::pair<std::string, std::vector<std::string>>&
1761abe55efSEd Tanous                          objData : object.second)
1771abe55efSEd Tanous                 {
17849c53ac9SJohnathan Mantey                     BMCWEB_LOG_DEBUG << "Adding connection: " << objData.first;
17908777fb0SLewanczyk, Dawid                     connections.insert(objData.first);
180de629b6eSShawn McCarney                     objectsWithConnection.insert(
181de629b6eSShawn McCarney                         std::make_pair(object.first, objData.first));
18208777fb0SLewanczyk, Dawid                 }
18308777fb0SLewanczyk, Dawid             }
18408777fb0SLewanczyk, Dawid         }
18555c7b7a2SEd Tanous         BMCWEB_LOG_DEBUG << "Found " << connections.size() << " connections";
186413961deSRichard Marian Thomaiyar         callback(std::move(connections), std::move(objectsWithConnection));
187413961deSRichard Marian Thomaiyar         BMCWEB_LOG_DEBUG << "getObjectsWithConnection resp_handler exit";
18808777fb0SLewanczyk, Dawid     };
18908777fb0SLewanczyk, Dawid     // Make call to ObjectMapper to find all sensors objects
19055c7b7a2SEd Tanous     crow::connections::systemBus->async_method_call(
19155c7b7a2SEd Tanous         std::move(respHandler), "xyz.openbmc_project.ObjectMapper",
1921abe55efSEd Tanous         "/xyz/openbmc_project/object_mapper",
1931abe55efSEd Tanous         "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 2, interfaces);
194413961deSRichard Marian Thomaiyar     BMCWEB_LOG_DEBUG << "getObjectsWithConnection exit";
195413961deSRichard Marian Thomaiyar }
196413961deSRichard Marian Thomaiyar 
197413961deSRichard Marian Thomaiyar /**
198413961deSRichard Marian Thomaiyar  * @brief Create connections necessary for sensors
199413961deSRichard Marian Thomaiyar  * @param SensorsAsyncResp Pointer to object holding response data
200413961deSRichard Marian Thomaiyar  * @param sensorNames Sensors retrieved from chassis
201413961deSRichard Marian Thomaiyar  * @param callback Callback for processing gathered connections
202413961deSRichard Marian Thomaiyar  */
203413961deSRichard Marian Thomaiyar template <typename Callback>
20449c53ac9SJohnathan Mantey void getConnections(
20549c53ac9SJohnathan Mantey     std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
20649c53ac9SJohnathan Mantey     const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
207413961deSRichard Marian Thomaiyar     Callback&& callback)
208413961deSRichard Marian Thomaiyar {
209413961deSRichard Marian Thomaiyar     auto objectsWithConnectionCb =
210413961deSRichard Marian Thomaiyar         [callback](const boost::container::flat_set<std::string>& connections,
211413961deSRichard Marian Thomaiyar                    const std::set<std::pair<std::string, std::string>>&
212413961deSRichard Marian Thomaiyar                        objectsWithConnection) {
213413961deSRichard Marian Thomaiyar             callback(std::move(connections));
214413961deSRichard Marian Thomaiyar         };
215413961deSRichard Marian Thomaiyar     getObjectsWithConnection(SensorsAsyncResp, sensorNames,
216413961deSRichard Marian Thomaiyar                              std::move(objectsWithConnectionCb));
21708777fb0SLewanczyk, Dawid }
21808777fb0SLewanczyk, Dawid 
21908777fb0SLewanczyk, Dawid /**
22049c53ac9SJohnathan Mantey  * @brief Shrinks the list of sensors for processing
22149c53ac9SJohnathan Mantey  * @param SensorsAysncResp  The class holding the Redfish response
22249c53ac9SJohnathan Mantey  * @param allSensors  A list of all the sensors associated to the
22349c53ac9SJohnathan Mantey  * chassis element (i.e. baseboard, front panel, etc...)
22449c53ac9SJohnathan Mantey  * @param activeSensors A list that is a reduction of the incoming
22549c53ac9SJohnathan Mantey  * allSensors list.  Eliminate Thermal sensors when a Power request is
22649c53ac9SJohnathan Mantey  * made, and eliminate Power sensors when a Thermal request is made.
22749c53ac9SJohnathan Mantey  */
22849c53ac9SJohnathan Mantey void reduceSensorList(
22949c53ac9SJohnathan Mantey     std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
23049c53ac9SJohnathan Mantey     const std::vector<std::string>* allSensors,
23149c53ac9SJohnathan Mantey     std::shared_ptr<boost::container::flat_set<std::string>> activeSensors)
23249c53ac9SJohnathan Mantey {
23349c53ac9SJohnathan Mantey     if (SensorsAsyncResp == nullptr)
23449c53ac9SJohnathan Mantey     {
23549c53ac9SJohnathan Mantey         return;
23649c53ac9SJohnathan Mantey     }
23749c53ac9SJohnathan Mantey     if ((allSensors == nullptr) || (activeSensors == nullptr))
23849c53ac9SJohnathan Mantey     {
23949c53ac9SJohnathan Mantey         messages::resourceNotFound(
24049c53ac9SJohnathan Mantey             SensorsAsyncResp->res, SensorsAsyncResp->chassisSubNode,
24149c53ac9SJohnathan Mantey             SensorsAsyncResp->chassisSubNode == "Thermal" ? "Temperatures"
24249c53ac9SJohnathan Mantey                                                           : "Voltages");
24349c53ac9SJohnathan Mantey 
24449c53ac9SJohnathan Mantey         return;
24549c53ac9SJohnathan Mantey     }
24649c53ac9SJohnathan Mantey     if (allSensors->empty())
24749c53ac9SJohnathan Mantey     {
24849c53ac9SJohnathan Mantey         // Nothing to do, the activeSensors object is also empty
24949c53ac9SJohnathan Mantey         return;
25049c53ac9SJohnathan Mantey     }
25149c53ac9SJohnathan Mantey 
25249c53ac9SJohnathan Mantey     for (const char* type : SensorsAsyncResp->types)
25349c53ac9SJohnathan Mantey     {
25449c53ac9SJohnathan Mantey         for (const std::string& sensor : *allSensors)
25549c53ac9SJohnathan Mantey         {
25649c53ac9SJohnathan Mantey             if (boost::starts_with(sensor, type))
25749c53ac9SJohnathan Mantey             {
25849c53ac9SJohnathan Mantey                 activeSensors->emplace(sensor);
25949c53ac9SJohnathan Mantey             }
26049c53ac9SJohnathan Mantey         }
26149c53ac9SJohnathan Mantey     }
26249c53ac9SJohnathan Mantey }
26349c53ac9SJohnathan Mantey 
26449c53ac9SJohnathan Mantey /**
265*4bb3dc34SCarol Wang  * @brief Retrieves valid chassis path
266*4bb3dc34SCarol Wang  * @param asyncResp   Pointer to object holding response data
267*4bb3dc34SCarol Wang  * @param callback  Callback for next step to get valid chassis path
268*4bb3dc34SCarol Wang  */
269*4bb3dc34SCarol Wang template <typename Callback>
270*4bb3dc34SCarol Wang void getValidChassisPath(std::shared_ptr<SensorsAsyncResp> asyncResp,
271*4bb3dc34SCarol Wang                          Callback&& callback)
272*4bb3dc34SCarol Wang {
273*4bb3dc34SCarol Wang     BMCWEB_LOG_DEBUG << "checkChassisId enter";
274*4bb3dc34SCarol Wang     const std::array<const char*, 2> interfaces = {
275*4bb3dc34SCarol Wang         "xyz.openbmc_project.Inventory.Item.Board",
276*4bb3dc34SCarol Wang         "xyz.openbmc_project.Inventory.Item.Chassis"};
277*4bb3dc34SCarol Wang 
278*4bb3dc34SCarol Wang     auto respHandler =
279*4bb3dc34SCarol Wang         [callback{std::move(callback)},
280*4bb3dc34SCarol Wang          asyncResp](const boost::system::error_code ec,
281*4bb3dc34SCarol Wang                     const std::vector<std::string>& chassisPaths) mutable {
282*4bb3dc34SCarol Wang             BMCWEB_LOG_DEBUG << "getValidChassisPath respHandler enter";
283*4bb3dc34SCarol Wang             if (ec)
284*4bb3dc34SCarol Wang             {
285*4bb3dc34SCarol Wang                 BMCWEB_LOG_ERROR
286*4bb3dc34SCarol Wang                     << "getValidChassisPath respHandler DBUS error: " << ec;
287*4bb3dc34SCarol Wang                 messages::internalError(asyncResp->res);
288*4bb3dc34SCarol Wang                 return;
289*4bb3dc34SCarol Wang             }
290*4bb3dc34SCarol Wang 
291*4bb3dc34SCarol Wang             std::optional<std::string> chassisPath;
292*4bb3dc34SCarol Wang             std::string chassisName;
293*4bb3dc34SCarol Wang             for (const std::string& chassis : chassisPaths)
294*4bb3dc34SCarol Wang             {
295*4bb3dc34SCarol Wang                 std::size_t lastPos = chassis.rfind("/");
296*4bb3dc34SCarol Wang                 if (lastPos == std::string::npos)
297*4bb3dc34SCarol Wang                 {
298*4bb3dc34SCarol Wang                     BMCWEB_LOG_ERROR << "Failed to find '/' in " << chassis;
299*4bb3dc34SCarol Wang                     continue;
300*4bb3dc34SCarol Wang                 }
301*4bb3dc34SCarol Wang                 chassisName = chassis.substr(lastPos + 1);
302*4bb3dc34SCarol Wang                 if (chassisName == asyncResp->chassisId)
303*4bb3dc34SCarol Wang                 {
304*4bb3dc34SCarol Wang                     chassisPath = chassis;
305*4bb3dc34SCarol Wang                     break;
306*4bb3dc34SCarol Wang                 }
307*4bb3dc34SCarol Wang             }
308*4bb3dc34SCarol Wang             callback(chassisPath);
309*4bb3dc34SCarol Wang         };
310*4bb3dc34SCarol Wang 
311*4bb3dc34SCarol Wang     // Get the Chassis Collection
312*4bb3dc34SCarol Wang     crow::connections::systemBus->async_method_call(
313*4bb3dc34SCarol Wang         respHandler, "xyz.openbmc_project.ObjectMapper",
314*4bb3dc34SCarol Wang         "/xyz/openbmc_project/object_mapper",
315*4bb3dc34SCarol Wang         "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
316*4bb3dc34SCarol Wang         "/xyz/openbmc_project/inventory", 0, interfaces);
317*4bb3dc34SCarol Wang     BMCWEB_LOG_DEBUG << "checkChassisId exit";
318*4bb3dc34SCarol Wang }
319*4bb3dc34SCarol Wang 
320*4bb3dc34SCarol Wang /**
32108777fb0SLewanczyk, Dawid  * @brief Retrieves requested chassis sensors and redundancy data from DBus .
322588c3f0dSKowalski, Kamil  * @param SensorsAsyncResp   Pointer to object holding response data
32308777fb0SLewanczyk, Dawid  * @param callback  Callback for next step in gathered sensor processing
32408777fb0SLewanczyk, Dawid  */
32508777fb0SLewanczyk, Dawid template <typename Callback>
32649c53ac9SJohnathan Mantey void getChassis(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
3271abe55efSEd Tanous                 Callback&& callback)
3281abe55efSEd Tanous {
32955c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "getChassis enter";
330adc4f0dbSShawn McCarney     const std::array<const char*, 2> interfaces = {
33149c53ac9SJohnathan Mantey         "xyz.openbmc_project.Inventory.Item.Board",
332adc4f0dbSShawn McCarney         "xyz.openbmc_project.Inventory.Item.Chassis"};
33349c53ac9SJohnathan Mantey     auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp](
33449c53ac9SJohnathan Mantey                            const boost::system::error_code ec,
33549c53ac9SJohnathan Mantey                            const std::vector<std::string>& chassisPaths) {
33655c7b7a2SEd Tanous         BMCWEB_LOG_DEBUG << "getChassis respHandler enter";
3371abe55efSEd Tanous         if (ec)
3381abe55efSEd Tanous         {
33955c7b7a2SEd Tanous             BMCWEB_LOG_ERROR << "getChassis respHandler DBUS error: " << ec;
34049c53ac9SJohnathan Mantey             messages::internalError(sensorsAsyncResp->res);
34108777fb0SLewanczyk, Dawid             return;
34208777fb0SLewanczyk, Dawid         }
34308777fb0SLewanczyk, Dawid 
34449c53ac9SJohnathan Mantey         const std::string* chassisPath = nullptr;
34549c53ac9SJohnathan Mantey         std::string chassisName;
34649c53ac9SJohnathan Mantey         for (const std::string& chassis : chassisPaths)
3471abe55efSEd Tanous         {
34849c53ac9SJohnathan Mantey             std::size_t lastPos = chassis.rfind("/");
34949c53ac9SJohnathan Mantey             if (lastPos == std::string::npos)
3501abe55efSEd Tanous             {
35149c53ac9SJohnathan Mantey                 BMCWEB_LOG_ERROR << "Failed to find '/' in " << chassis;
352daf36e2eSEd Tanous                 continue;
353daf36e2eSEd Tanous             }
35449c53ac9SJohnathan Mantey             chassisName = chassis.substr(lastPos + 1);
35549c53ac9SJohnathan Mantey             if (chassisName == sensorsAsyncResp->chassisId)
3561abe55efSEd Tanous             {
35749c53ac9SJohnathan Mantey                 chassisPath = &chassis;
35849c53ac9SJohnathan Mantey                 break;
359daf36e2eSEd Tanous             }
36049c53ac9SJohnathan Mantey         }
36149c53ac9SJohnathan Mantey         if (chassisPath == nullptr)
3621abe55efSEd Tanous         {
36349c53ac9SJohnathan Mantey             messages::resourceNotFound(sensorsAsyncResp->res, "Chassis",
36449c53ac9SJohnathan Mantey                                        sensorsAsyncResp->chassisId);
36549c53ac9SJohnathan Mantey             return;
3661abe55efSEd Tanous         }
36708777fb0SLewanczyk, Dawid 
36849c53ac9SJohnathan Mantey         const std::string& chassisSubNode = sensorsAsyncResp->chassisSubNode;
36949c53ac9SJohnathan Mantey         if (chassisSubNode == "Power")
37049c53ac9SJohnathan Mantey         {
37149c53ac9SJohnathan Mantey             sensorsAsyncResp->res.jsonValue["@odata.type"] =
37249c53ac9SJohnathan Mantey                 "#Power.v1_5_2.Power";
37349c53ac9SJohnathan Mantey         }
37449c53ac9SJohnathan Mantey         else if (chassisSubNode == "Thermal")
37549c53ac9SJohnathan Mantey         {
37649c53ac9SJohnathan Mantey             sensorsAsyncResp->res.jsonValue["@odata.type"] =
37749c53ac9SJohnathan Mantey                 "#Thermal.v1_4_0.Thermal";
3784f9a2130SJennifer Lee             sensorsAsyncResp->res.jsonValue["Fans"] = nlohmann::json::array();
3794f9a2130SJennifer Lee             sensorsAsyncResp->res.jsonValue["Temperatures"] =
3804f9a2130SJennifer Lee                 nlohmann::json::array();
38149c53ac9SJohnathan Mantey         }
38295a3ecadSAnthony Wilson         else if (chassisSubNode == "Sensors")
38395a3ecadSAnthony Wilson         {
38495a3ecadSAnthony Wilson             sensorsAsyncResp->res.jsonValue["@odata.type"] =
38595a3ecadSAnthony Wilson                 "#SensorCollection.SensorCollection";
38695a3ecadSAnthony Wilson             sensorsAsyncResp->res.jsonValue["@odata.context"] =
38795a3ecadSAnthony Wilson                 "/redfish/v1/$metadata#SensorCollection.SensorCollection";
38895a3ecadSAnthony Wilson             sensorsAsyncResp->res.jsonValue["Description"] =
38995a3ecadSAnthony Wilson                 "Collection of Sensors for this Chassis";
39095a3ecadSAnthony Wilson             sensorsAsyncResp->res.jsonValue["Members"] =
39195a3ecadSAnthony Wilson                 nlohmann::json::array();
39295a3ecadSAnthony Wilson             sensorsAsyncResp->res.jsonValue["Members@odata.count"] = 0;
39395a3ecadSAnthony Wilson         }
39495a3ecadSAnthony Wilson 
39595a3ecadSAnthony Wilson         if (chassisSubNode != "Sensors")
39695a3ecadSAnthony Wilson         {
39795a3ecadSAnthony Wilson             sensorsAsyncResp->res.jsonValue["Id"] = chassisSubNode;
39895a3ecadSAnthony Wilson             sensorsAsyncResp->res.jsonValue["@odata.context"] =
39995a3ecadSAnthony Wilson                 "/redfish/v1/$metadata#" + chassisSubNode + "." +
40095a3ecadSAnthony Wilson                 chassisSubNode;
40195a3ecadSAnthony Wilson         }
40295a3ecadSAnthony Wilson 
40349c53ac9SJohnathan Mantey         sensorsAsyncResp->res.jsonValue["@odata.id"] =
40449c53ac9SJohnathan Mantey             "/redfish/v1/Chassis/" + sensorsAsyncResp->chassisId + "/" +
40549c53ac9SJohnathan Mantey             chassisSubNode;
40649c53ac9SJohnathan Mantey         sensorsAsyncResp->res.jsonValue["Name"] = chassisSubNode;
40749c53ac9SJohnathan Mantey 
4088fb49dd6SShawn McCarney         // Get the list of all sensors for this Chassis element
4098fb49dd6SShawn McCarney         std::string sensorPath = *chassisPath + "/all_sensors";
41055c7b7a2SEd Tanous         crow::connections::systemBus->async_method_call(
41149c53ac9SJohnathan Mantey             [sensorsAsyncResp, callback{std::move(callback)}](
412271584abSEd Tanous                 const boost::system::error_code& e,
41349c53ac9SJohnathan Mantey                 const std::variant<std::vector<std::string>>&
41449c53ac9SJohnathan Mantey                     variantEndpoints) {
415271584abSEd Tanous                 if (e)
41649c53ac9SJohnathan Mantey                 {
417271584abSEd Tanous                     if (e.value() != EBADR)
41849c53ac9SJohnathan Mantey                     {
41949c53ac9SJohnathan Mantey                         messages::internalError(sensorsAsyncResp->res);
42049c53ac9SJohnathan Mantey                         return;
42149c53ac9SJohnathan Mantey                     }
42249c53ac9SJohnathan Mantey                 }
42349c53ac9SJohnathan Mantey                 const std::vector<std::string>* nodeSensorList =
42449c53ac9SJohnathan Mantey                     std::get_if<std::vector<std::string>>(&(variantEndpoints));
42549c53ac9SJohnathan Mantey                 if (nodeSensorList == nullptr)
42649c53ac9SJohnathan Mantey                 {
42749c53ac9SJohnathan Mantey                     messages::resourceNotFound(
42849c53ac9SJohnathan Mantey                         sensorsAsyncResp->res, sensorsAsyncResp->chassisSubNode,
42949c53ac9SJohnathan Mantey                         sensorsAsyncResp->chassisSubNode == "Thermal"
43049c53ac9SJohnathan Mantey                             ? "Temperatures"
43195a3ecadSAnthony Wilson                             : sensorsAsyncResp->chassisSubNode == "Power"
43295a3ecadSAnthony Wilson                                   ? "Voltages"
43395a3ecadSAnthony Wilson                                   : "Sensors");
43449c53ac9SJohnathan Mantey                     return;
43549c53ac9SJohnathan Mantey                 }
43649c53ac9SJohnathan Mantey                 const std::shared_ptr<boost::container::flat_set<std::string>>
43749c53ac9SJohnathan Mantey                     culledSensorList = std::make_shared<
43849c53ac9SJohnathan Mantey                         boost::container::flat_set<std::string>>();
43949c53ac9SJohnathan Mantey                 reduceSensorList(sensorsAsyncResp, nodeSensorList,
44049c53ac9SJohnathan Mantey                                  culledSensorList);
44149c53ac9SJohnathan Mantey                 callback(culledSensorList);
44249c53ac9SJohnathan Mantey             },
44349c53ac9SJohnathan Mantey             "xyz.openbmc_project.ObjectMapper", sensorPath,
44449c53ac9SJohnathan Mantey             "org.freedesktop.DBus.Properties", "Get",
44549c53ac9SJohnathan Mantey             "xyz.openbmc_project.Association", "endpoints");
44649c53ac9SJohnathan Mantey     };
44749c53ac9SJohnathan Mantey 
44849c53ac9SJohnathan Mantey     // Get the Chassis Collection
44949c53ac9SJohnathan Mantey     crow::connections::systemBus->async_method_call(
45049c53ac9SJohnathan Mantey         respHandler, "xyz.openbmc_project.ObjectMapper",
45149c53ac9SJohnathan Mantey         "/xyz/openbmc_project/object_mapper",
45249c53ac9SJohnathan Mantey         "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
453271584abSEd Tanous         "/xyz/openbmc_project/inventory", 0, interfaces);
45455c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "getChassis exit";
45508777fb0SLewanczyk, Dawid }
45608777fb0SLewanczyk, Dawid 
45708777fb0SLewanczyk, Dawid /**
458de629b6eSShawn McCarney  * @brief Finds all DBus object paths that implement ObjectManager.
459de629b6eSShawn McCarney  *
460de629b6eSShawn McCarney  * Creates a mapping from the associated connection name to the object path.
461de629b6eSShawn McCarney  *
462de629b6eSShawn McCarney  * Finds the object paths asynchronously.  Invokes callback when information has
463de629b6eSShawn McCarney  * been obtained.
464de629b6eSShawn McCarney  *
465de629b6eSShawn McCarney  * The callback must have the following signature:
466de629b6eSShawn McCarney  *   @code
4678fb49dd6SShawn McCarney  *   callback(std::shared_ptr<boost::container::flat_map<std::string,
4688fb49dd6SShawn McCarney  *                std::string>> objectMgrPaths)
469de629b6eSShawn McCarney  *   @endcode
470de629b6eSShawn McCarney  *
47149c53ac9SJohnathan Mantey  * @param sensorsAsyncResp Pointer to object holding response data.
472de629b6eSShawn McCarney  * @param callback Callback to invoke when object paths obtained.
473de629b6eSShawn McCarney  */
474de629b6eSShawn McCarney template <typename Callback>
475de629b6eSShawn McCarney void getObjectManagerPaths(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
476de629b6eSShawn McCarney                            Callback&& callback)
477de629b6eSShawn McCarney {
478de629b6eSShawn McCarney     BMCWEB_LOG_DEBUG << "getObjectManagerPaths enter";
479de629b6eSShawn McCarney     const std::array<std::string, 1> interfaces = {
480de629b6eSShawn McCarney         "org.freedesktop.DBus.ObjectManager"};
481de629b6eSShawn McCarney 
482de629b6eSShawn McCarney     // Response handler for GetSubTree DBus method
483de629b6eSShawn McCarney     auto respHandler = [callback{std::move(callback)},
484de629b6eSShawn McCarney                         SensorsAsyncResp](const boost::system::error_code ec,
485de629b6eSShawn McCarney                                           const GetSubTreeType& subtree) {
486de629b6eSShawn McCarney         BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler enter";
487de629b6eSShawn McCarney         if (ec)
488de629b6eSShawn McCarney         {
489de629b6eSShawn McCarney             messages::internalError(SensorsAsyncResp->res);
490de629b6eSShawn McCarney             BMCWEB_LOG_ERROR << "getObjectManagerPaths respHandler: DBus error "
491de629b6eSShawn McCarney                              << ec;
492de629b6eSShawn McCarney             return;
493de629b6eSShawn McCarney         }
494de629b6eSShawn McCarney 
495de629b6eSShawn McCarney         // Loop over returned object paths
4968fb49dd6SShawn McCarney         std::shared_ptr<boost::container::flat_map<std::string, std::string>>
4978fb49dd6SShawn McCarney             objectMgrPaths = std::make_shared<
4988fb49dd6SShawn McCarney                 boost::container::flat_map<std::string, std::string>>();
499de629b6eSShawn McCarney         for (const std::pair<
500de629b6eSShawn McCarney                  std::string,
501de629b6eSShawn McCarney                  std::vector<std::pair<std::string, std::vector<std::string>>>>&
502de629b6eSShawn McCarney                  object : subtree)
503de629b6eSShawn McCarney         {
504de629b6eSShawn McCarney             // Loop over connections for current object path
505de629b6eSShawn McCarney             const std::string& objectPath = object.first;
506de629b6eSShawn McCarney             for (const std::pair<std::string, std::vector<std::string>>&
507de629b6eSShawn McCarney                      objData : object.second)
508de629b6eSShawn McCarney             {
509de629b6eSShawn McCarney                 // Add mapping from connection to object path
510de629b6eSShawn McCarney                 const std::string& connection = objData.first;
5118fb49dd6SShawn McCarney                 (*objectMgrPaths)[connection] = objectPath;
512de629b6eSShawn McCarney                 BMCWEB_LOG_DEBUG << "Added mapping " << connection << " -> "
513de629b6eSShawn McCarney                                  << objectPath;
514de629b6eSShawn McCarney             }
515de629b6eSShawn McCarney         }
5168fb49dd6SShawn McCarney         callback(objectMgrPaths);
517de629b6eSShawn McCarney         BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler exit";
518de629b6eSShawn McCarney     };
519de629b6eSShawn McCarney 
520de629b6eSShawn McCarney     // Query mapper for all DBus object paths that implement ObjectManager
521de629b6eSShawn McCarney     crow::connections::systemBus->async_method_call(
522de629b6eSShawn McCarney         std::move(respHandler), "xyz.openbmc_project.ObjectMapper",
523de629b6eSShawn McCarney         "/xyz/openbmc_project/object_mapper",
524271584abSEd Tanous         "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, interfaces);
525de629b6eSShawn McCarney     BMCWEB_LOG_DEBUG << "getObjectManagerPaths exit";
526de629b6eSShawn McCarney }
527de629b6eSShawn McCarney 
528de629b6eSShawn McCarney /**
529adc4f0dbSShawn McCarney  * @brief Returns the Redfish State value for the specified inventory item.
530adc4f0dbSShawn McCarney  * @param inventoryItem D-Bus inventory item associated with a sensor.
531adc4f0dbSShawn McCarney  * @return State value for inventory item.
53234dd179eSJames Feist  */
533adc4f0dbSShawn McCarney static std::string getState(const InventoryItem* inventoryItem)
534adc4f0dbSShawn McCarney {
535adc4f0dbSShawn McCarney     if ((inventoryItem != nullptr) && !(inventoryItem->isPresent))
536adc4f0dbSShawn McCarney     {
537adc4f0dbSShawn McCarney         return "Absent";
538adc4f0dbSShawn McCarney     }
53934dd179eSJames Feist 
540adc4f0dbSShawn McCarney     return "Enabled";
541adc4f0dbSShawn McCarney }
542adc4f0dbSShawn McCarney 
543adc4f0dbSShawn McCarney /**
544adc4f0dbSShawn McCarney  * @brief Returns the Redfish Health value for the specified sensor.
545adc4f0dbSShawn McCarney  * @param sensorJson Sensor JSON object.
546adc4f0dbSShawn McCarney  * @param interfacesDict Map of all sensor interfaces.
547adc4f0dbSShawn McCarney  * @param inventoryItem D-Bus inventory item associated with the sensor.  Will
548adc4f0dbSShawn McCarney  * be nullptr if no associated inventory item was found.
549adc4f0dbSShawn McCarney  * @return Health value for sensor.
550adc4f0dbSShawn McCarney  */
55134dd179eSJames Feist static std::string getHealth(
552adc4f0dbSShawn McCarney     nlohmann::json& sensorJson,
55334dd179eSJames Feist     const boost::container::flat_map<
55434dd179eSJames Feist         std::string, boost::container::flat_map<std::string, SensorVariant>>&
555adc4f0dbSShawn McCarney         interfacesDict,
556adc4f0dbSShawn McCarney     const InventoryItem* inventoryItem)
55734dd179eSJames Feist {
558adc4f0dbSShawn McCarney     // Get current health value (if any) in the sensor JSON object.  Some JSON
559adc4f0dbSShawn McCarney     // objects contain multiple sensors (such as PowerSupplies).  We want to set
560adc4f0dbSShawn McCarney     // the overall health to be the most severe of any of the sensors.
561adc4f0dbSShawn McCarney     std::string currentHealth;
562adc4f0dbSShawn McCarney     auto statusIt = sensorJson.find("Status");
563adc4f0dbSShawn McCarney     if (statusIt != sensorJson.end())
564adc4f0dbSShawn McCarney     {
565adc4f0dbSShawn McCarney         auto healthIt = statusIt->find("Health");
566adc4f0dbSShawn McCarney         if (healthIt != statusIt->end())
567adc4f0dbSShawn McCarney         {
568adc4f0dbSShawn McCarney             std::string* health = healthIt->get_ptr<std::string*>();
569adc4f0dbSShawn McCarney             if (health != nullptr)
570adc4f0dbSShawn McCarney             {
571adc4f0dbSShawn McCarney                 currentHealth = *health;
572adc4f0dbSShawn McCarney             }
573adc4f0dbSShawn McCarney         }
574adc4f0dbSShawn McCarney     }
575adc4f0dbSShawn McCarney 
576adc4f0dbSShawn McCarney     // If current health in JSON object is already Critical, return that.  This
577adc4f0dbSShawn McCarney     // should override the sensor health, which might be less severe.
578adc4f0dbSShawn McCarney     if (currentHealth == "Critical")
579adc4f0dbSShawn McCarney     {
580adc4f0dbSShawn McCarney         return "Critical";
581adc4f0dbSShawn McCarney     }
582adc4f0dbSShawn McCarney 
583adc4f0dbSShawn McCarney     // Check if sensor has critical threshold alarm
58434dd179eSJames Feist     auto criticalThresholdIt =
58534dd179eSJames Feist         interfacesDict.find("xyz.openbmc_project.Sensor.Threshold.Critical");
58634dd179eSJames Feist     if (criticalThresholdIt != interfacesDict.end())
58734dd179eSJames Feist     {
58834dd179eSJames Feist         auto thresholdHighIt =
58934dd179eSJames Feist             criticalThresholdIt->second.find("CriticalAlarmHigh");
59034dd179eSJames Feist         auto thresholdLowIt =
59134dd179eSJames Feist             criticalThresholdIt->second.find("CriticalAlarmLow");
59234dd179eSJames Feist         if (thresholdHighIt != criticalThresholdIt->second.end())
59334dd179eSJames Feist         {
59434dd179eSJames Feist             const bool* asserted = std::get_if<bool>(&thresholdHighIt->second);
59534dd179eSJames Feist             if (asserted == nullptr)
59634dd179eSJames Feist             {
59734dd179eSJames Feist                 BMCWEB_LOG_ERROR << "Illegal sensor threshold";
59834dd179eSJames Feist             }
59934dd179eSJames Feist             else if (*asserted)
60034dd179eSJames Feist             {
60134dd179eSJames Feist                 return "Critical";
60234dd179eSJames Feist             }
60334dd179eSJames Feist         }
60434dd179eSJames Feist         if (thresholdLowIt != criticalThresholdIt->second.end())
60534dd179eSJames Feist         {
60634dd179eSJames Feist             const bool* asserted = std::get_if<bool>(&thresholdLowIt->second);
60734dd179eSJames Feist             if (asserted == nullptr)
60834dd179eSJames Feist             {
60934dd179eSJames Feist                 BMCWEB_LOG_ERROR << "Illegal sensor threshold";
61034dd179eSJames Feist             }
61134dd179eSJames Feist             else if (*asserted)
61234dd179eSJames Feist             {
61334dd179eSJames Feist                 return "Critical";
61434dd179eSJames Feist             }
61534dd179eSJames Feist         }
61634dd179eSJames Feist     }
61734dd179eSJames Feist 
618adc4f0dbSShawn McCarney     // Check if associated inventory item is not functional
619adc4f0dbSShawn McCarney     if ((inventoryItem != nullptr) && !(inventoryItem->isFunctional))
620adc4f0dbSShawn McCarney     {
621adc4f0dbSShawn McCarney         return "Critical";
622adc4f0dbSShawn McCarney     }
623adc4f0dbSShawn McCarney 
624adc4f0dbSShawn McCarney     // If current health in JSON object is already Warning, return that.  This
625adc4f0dbSShawn McCarney     // should override the sensor status, which might be less severe.
626adc4f0dbSShawn McCarney     if (currentHealth == "Warning")
627adc4f0dbSShawn McCarney     {
628adc4f0dbSShawn McCarney         return "Warning";
629adc4f0dbSShawn McCarney     }
630adc4f0dbSShawn McCarney 
631adc4f0dbSShawn McCarney     // Check if sensor has warning threshold alarm
63234dd179eSJames Feist     auto warningThresholdIt =
63334dd179eSJames Feist         interfacesDict.find("xyz.openbmc_project.Sensor.Threshold.Warning");
63434dd179eSJames Feist     if (warningThresholdIt != interfacesDict.end())
63534dd179eSJames Feist     {
63634dd179eSJames Feist         auto thresholdHighIt =
63734dd179eSJames Feist             warningThresholdIt->second.find("WarningAlarmHigh");
63834dd179eSJames Feist         auto thresholdLowIt =
63934dd179eSJames Feist             warningThresholdIt->second.find("WarningAlarmLow");
64034dd179eSJames Feist         if (thresholdHighIt != warningThresholdIt->second.end())
64134dd179eSJames Feist         {
64234dd179eSJames Feist             const bool* asserted = std::get_if<bool>(&thresholdHighIt->second);
64334dd179eSJames Feist             if (asserted == nullptr)
64434dd179eSJames Feist             {
64534dd179eSJames Feist                 BMCWEB_LOG_ERROR << "Illegal sensor threshold";
64634dd179eSJames Feist             }
64734dd179eSJames Feist             else if (*asserted)
64834dd179eSJames Feist             {
64934dd179eSJames Feist                 return "Warning";
65034dd179eSJames Feist             }
65134dd179eSJames Feist         }
65234dd179eSJames Feist         if (thresholdLowIt != warningThresholdIt->second.end())
65334dd179eSJames Feist         {
65434dd179eSJames Feist             const bool* asserted = std::get_if<bool>(&thresholdLowIt->second);
65534dd179eSJames Feist             if (asserted == nullptr)
65634dd179eSJames Feist             {
65734dd179eSJames Feist                 BMCWEB_LOG_ERROR << "Illegal sensor threshold";
65834dd179eSJames Feist             }
65934dd179eSJames Feist             else if (*asserted)
66034dd179eSJames Feist             {
66134dd179eSJames Feist                 return "Warning";
66234dd179eSJames Feist             }
66334dd179eSJames Feist         }
66434dd179eSJames Feist     }
665adc4f0dbSShawn McCarney 
66634dd179eSJames Feist     return "OK";
66734dd179eSJames Feist }
66834dd179eSJames Feist 
669d500549bSAnthony Wilson static void setLedState(nlohmann::json& sensorJson,
670d500549bSAnthony Wilson                         const InventoryItem* inventoryItem)
671d500549bSAnthony Wilson {
672d500549bSAnthony Wilson     if (inventoryItem != nullptr && !inventoryItem->ledObjectPath.empty())
673d500549bSAnthony Wilson     {
674d500549bSAnthony Wilson         switch (inventoryItem->ledState)
675d500549bSAnthony Wilson         {
676d500549bSAnthony Wilson             case LedState::OFF:
677d500549bSAnthony Wilson                 sensorJson["IndicatorLED"] = "Off";
678d500549bSAnthony Wilson                 break;
679d500549bSAnthony Wilson             case LedState::ON:
680d500549bSAnthony Wilson                 sensorJson["IndicatorLED"] = "Lit";
681d500549bSAnthony Wilson                 break;
682d500549bSAnthony Wilson             case LedState::BLINK:
683d500549bSAnthony Wilson                 sensorJson["IndicatorLED"] = "Blinking";
684d500549bSAnthony Wilson                 break;
685d500549bSAnthony Wilson             default:
686d500549bSAnthony Wilson                 break;
687d500549bSAnthony Wilson         }
688d500549bSAnthony Wilson     }
689d500549bSAnthony Wilson }
690d500549bSAnthony Wilson 
69134dd179eSJames Feist /**
69208777fb0SLewanczyk, Dawid  * @brief Builds a json sensor representation of a sensor.
69308777fb0SLewanczyk, Dawid  * @param sensorName  The name of the sensor to be built
694274fad5aSGunnar Mills  * @param sensorType  The type (temperature, fan_tach, etc) of the sensor to
69508777fb0SLewanczyk, Dawid  * build
69695a3ecadSAnthony Wilson  * @param sensorSchema  The schema (Power, Thermal, etc) being associated with
69795a3ecadSAnthony Wilson  * the sensor to build
69808777fb0SLewanczyk, Dawid  * @param interfacesDict  A dictionary of the interfaces and properties of said
69908777fb0SLewanczyk, Dawid  * interfaces to be built from
70008777fb0SLewanczyk, Dawid  * @param sensor_json  The json object to fill
701adc4f0dbSShawn McCarney  * @param inventoryItem D-Bus inventory item associated with the sensor.  Will
702adc4f0dbSShawn McCarney  * be nullptr if no associated inventory item was found.
70308777fb0SLewanczyk, Dawid  */
70408777fb0SLewanczyk, Dawid void objectInterfacesToJson(
70508777fb0SLewanczyk, Dawid     const std::string& sensorName, const std::string& sensorType,
70695a3ecadSAnthony Wilson     const std::string& sensorSchema,
70708777fb0SLewanczyk, Dawid     const boost::container::flat_map<
708aa2e59c1SEd Tanous         std::string, boost::container::flat_map<std::string, SensorVariant>>&
70908777fb0SLewanczyk, Dawid         interfacesDict,
710adc4f0dbSShawn McCarney     nlohmann::json& sensor_json, InventoryItem* inventoryItem)
7111abe55efSEd Tanous {
71208777fb0SLewanczyk, Dawid     // We need a value interface before we can do anything with it
71355c7b7a2SEd Tanous     auto valueIt = interfacesDict.find("xyz.openbmc_project.Sensor.Value");
7141abe55efSEd Tanous     if (valueIt == interfacesDict.end())
7151abe55efSEd Tanous     {
71655c7b7a2SEd Tanous         BMCWEB_LOG_ERROR << "Sensor doesn't have a value interface";
71708777fb0SLewanczyk, Dawid         return;
71808777fb0SLewanczyk, Dawid     }
71908777fb0SLewanczyk, Dawid 
72008777fb0SLewanczyk, Dawid     // Assume values exist as is (10^0 == 1) if no scale exists
72108777fb0SLewanczyk, Dawid     int64_t scaleMultiplier = 0;
72208777fb0SLewanczyk, Dawid 
72355c7b7a2SEd Tanous     auto scaleIt = valueIt->second.find("Scale");
72408777fb0SLewanczyk, Dawid     // If a scale exists, pull value as int64, and use the scaling.
7251abe55efSEd Tanous     if (scaleIt != valueIt->second.end())
7261abe55efSEd Tanous     {
727abf2add6SEd Tanous         const int64_t* int64Value = std::get_if<int64_t>(&scaleIt->second);
7281abe55efSEd Tanous         if (int64Value != nullptr)
7291abe55efSEd Tanous         {
73008777fb0SLewanczyk, Dawid             scaleMultiplier = *int64Value;
73108777fb0SLewanczyk, Dawid         }
73208777fb0SLewanczyk, Dawid     }
73308777fb0SLewanczyk, Dawid 
73495a3ecadSAnthony Wilson     if (sensorSchema == "Sensors")
735adc4f0dbSShawn McCarney     {
73695a3ecadSAnthony Wilson         // For sensors in SensorCollection we set Id instead of MemberId,
73795a3ecadSAnthony Wilson         // including power sensors.
73895a3ecadSAnthony Wilson         sensor_json["Id"] = sensorName;
73995a3ecadSAnthony Wilson         sensor_json["Name"] = boost::replace_all_copy(sensorName, "_", " ");
74095a3ecadSAnthony Wilson     }
74195a3ecadSAnthony Wilson     else if (sensorType != "power")
74295a3ecadSAnthony Wilson     {
74395a3ecadSAnthony Wilson         // Set MemberId and Name for non-power sensors.  For PowerSupplies and
74495a3ecadSAnthony Wilson         // PowerControl, those properties have more general values because
74595a3ecadSAnthony Wilson         // multiple sensors can be stored in the same JSON object.
74608777fb0SLewanczyk, Dawid         sensor_json["MemberId"] = sensorName;
747e742b6ccSEd Tanous         sensor_json["Name"] = boost::replace_all_copy(sensorName, "_", " ");
748adc4f0dbSShawn McCarney     }
749e742b6ccSEd Tanous 
750adc4f0dbSShawn McCarney     sensor_json["Status"]["State"] = getState(inventoryItem);
751adc4f0dbSShawn McCarney     sensor_json["Status"]["Health"] =
752adc4f0dbSShawn McCarney         getHealth(sensor_json, interfacesDict, inventoryItem);
75308777fb0SLewanczyk, Dawid 
75408777fb0SLewanczyk, Dawid     // Parameter to set to override the type we get from dbus, and force it to
75508777fb0SLewanczyk, Dawid     // int, regardless of what is available.  This is used for schemas like fan,
75608777fb0SLewanczyk, Dawid     // that require integers, not floats.
75708777fb0SLewanczyk, Dawid     bool forceToInt = false;
75808777fb0SLewanczyk, Dawid 
7593929aca1SAnthony Wilson     nlohmann::json::json_pointer unit("/Reading");
76095a3ecadSAnthony Wilson     if (sensorSchema == "Sensors")
76195a3ecadSAnthony Wilson     {
76295a3ecadSAnthony Wilson         sensor_json["@odata.type"] = "#Sensor.v1_0_0.Sensor";
76395a3ecadSAnthony Wilson         sensor_json["@odata.context"] = "/redfish/v1/$metadata#Sensor.Sensor";
76495a3ecadSAnthony Wilson         if (sensorType == "power")
76595a3ecadSAnthony Wilson         {
76695a3ecadSAnthony Wilson             sensor_json["ReadingUnits"] = "Watts";
76795a3ecadSAnthony Wilson         }
76895a3ecadSAnthony Wilson         else if (sensorType == "current")
76995a3ecadSAnthony Wilson         {
77095a3ecadSAnthony Wilson             sensor_json["ReadingUnits"] = "Amperes";
77195a3ecadSAnthony Wilson         }
77295a3ecadSAnthony Wilson     }
77395a3ecadSAnthony Wilson     else if (sensorType == "temperature")
7741abe55efSEd Tanous     {
7753929aca1SAnthony Wilson         unit = "/ReadingCelsius"_json_pointer;
7767885954aSLewanczyk, Dawid         sensor_json["@odata.type"] = "#Thermal.v1_3_0.Temperature";
77708777fb0SLewanczyk, Dawid         // TODO(ed) Documentation says that path should be type fan_tach,
77808777fb0SLewanczyk, Dawid         // implementation seems to implement fan
7791abe55efSEd Tanous     }
7801abe55efSEd Tanous     else if (sensorType == "fan" || sensorType == "fan_tach")
7811abe55efSEd Tanous     {
7823929aca1SAnthony Wilson         unit = "/Reading"_json_pointer;
78308777fb0SLewanczyk, Dawid         sensor_json["ReadingUnits"] = "RPM";
7847885954aSLewanczyk, Dawid         sensor_json["@odata.type"] = "#Thermal.v1_3_0.Fan";
785d500549bSAnthony Wilson         setLedState(sensor_json, inventoryItem);
78608777fb0SLewanczyk, Dawid         forceToInt = true;
7871abe55efSEd Tanous     }
7886f6d0d32SEd Tanous     else if (sensorType == "fan_pwm")
7896f6d0d32SEd Tanous     {
7903929aca1SAnthony Wilson         unit = "/Reading"_json_pointer;
7916f6d0d32SEd Tanous         sensor_json["ReadingUnits"] = "Percent";
7926f6d0d32SEd Tanous         sensor_json["@odata.type"] = "#Thermal.v1_3_0.Fan";
793d500549bSAnthony Wilson         setLedState(sensor_json, inventoryItem);
7946f6d0d32SEd Tanous         forceToInt = true;
7956f6d0d32SEd Tanous     }
7961abe55efSEd Tanous     else if (sensorType == "voltage")
7971abe55efSEd Tanous     {
7983929aca1SAnthony Wilson         unit = "/ReadingVolts"_json_pointer;
7997885954aSLewanczyk, Dawid         sensor_json["@odata.type"] = "#Power.v1_0_0.Voltage";
8001abe55efSEd Tanous     }
8012474adfaSEd Tanous     else if (sensorType == "power")
8022474adfaSEd Tanous     {
80349c53ac9SJohnathan Mantey         std::string sensorNameLower =
80449c53ac9SJohnathan Mantey             boost::algorithm::to_lower_copy(sensorName);
80549c53ac9SJohnathan Mantey 
806028f7ebcSEddie James         if (!sensorName.compare("total_power"))
807028f7ebcSEddie James         {
8087ab06f49SGunnar Mills             sensor_json["@odata.type"] = "#Power.v1_0_0.PowerControl";
8097ab06f49SGunnar Mills             // Put multiple "sensors" into a single PowerControl, so have
8107ab06f49SGunnar Mills             // generic names for MemberId and Name. Follows Redfish mockup.
8117ab06f49SGunnar Mills             sensor_json["MemberId"] = "0";
8127ab06f49SGunnar Mills             sensor_json["Name"] = "Chassis Power Control";
8133929aca1SAnthony Wilson             unit = "/PowerConsumedWatts"_json_pointer;
814028f7ebcSEddie James         }
815028f7ebcSEddie James         else if (sensorNameLower.find("input") != std::string::npos)
81649c53ac9SJohnathan Mantey         {
8173929aca1SAnthony Wilson             unit = "/PowerInputWatts"_json_pointer;
81849c53ac9SJohnathan Mantey         }
81949c53ac9SJohnathan Mantey         else
82049c53ac9SJohnathan Mantey         {
8213929aca1SAnthony Wilson             unit = "/PowerOutputWatts"_json_pointer;
82249c53ac9SJohnathan Mantey         }
8232474adfaSEd Tanous     }
8241abe55efSEd Tanous     else
8251abe55efSEd Tanous     {
82655c7b7a2SEd Tanous         BMCWEB_LOG_ERROR << "Redfish cannot map object type for " << sensorName;
82708777fb0SLewanczyk, Dawid         return;
82808777fb0SLewanczyk, Dawid     }
82908777fb0SLewanczyk, Dawid     // Map of dbus interface name, dbus property name and redfish property_name
8303929aca1SAnthony Wilson     std::vector<
8313929aca1SAnthony Wilson         std::tuple<const char*, const char*, nlohmann::json::json_pointer>>
8323929aca1SAnthony Wilson         properties;
83308777fb0SLewanczyk, Dawid     properties.reserve(7);
83408777fb0SLewanczyk, Dawid 
83508777fb0SLewanczyk, Dawid     properties.emplace_back("xyz.openbmc_project.Sensor.Value", "Value", unit);
836de629b6eSShawn McCarney 
8373929aca1SAnthony Wilson     if (sensorSchema == "Sensors")
8383929aca1SAnthony Wilson     {
8393929aca1SAnthony Wilson         properties.emplace_back(
8403929aca1SAnthony Wilson             "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningHigh",
8413929aca1SAnthony Wilson             "/Thresholds/UpperCaution/Reading"_json_pointer);
8423929aca1SAnthony Wilson         properties.emplace_back(
8433929aca1SAnthony Wilson             "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningLow",
8443929aca1SAnthony Wilson             "/Thresholds/LowerCaution/Reading"_json_pointer);
8453929aca1SAnthony Wilson         properties.emplace_back(
8463929aca1SAnthony Wilson             "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalHigh",
8473929aca1SAnthony Wilson             "/Thresholds/UpperCritical/Reading"_json_pointer);
8483929aca1SAnthony Wilson         properties.emplace_back(
8493929aca1SAnthony Wilson             "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalLow",
8503929aca1SAnthony Wilson             "/Thresholds/LowerCritical/Reading"_json_pointer);
8513929aca1SAnthony Wilson     }
8523929aca1SAnthony Wilson     else if (sensorType != "power")
853de629b6eSShawn McCarney     {
85408777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning",
8553929aca1SAnthony Wilson                                 "WarningHigh",
8563929aca1SAnthony Wilson                                 "/UpperThresholdNonCritical"_json_pointer);
85708777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning",
8583929aca1SAnthony Wilson                                 "WarningLow",
8593929aca1SAnthony Wilson                                 "/LowerThresholdNonCritical"_json_pointer);
86008777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical",
8613929aca1SAnthony Wilson                                 "CriticalHigh",
8623929aca1SAnthony Wilson                                 "/UpperThresholdCritical"_json_pointer);
86308777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical",
8643929aca1SAnthony Wilson                                 "CriticalLow",
8653929aca1SAnthony Wilson                                 "/LowerThresholdCritical"_json_pointer);
866de629b6eSShawn McCarney     }
86708777fb0SLewanczyk, Dawid 
8682474adfaSEd Tanous     // TODO Need to get UpperThresholdFatal and LowerThresholdFatal
8692474adfaSEd Tanous 
87095a3ecadSAnthony Wilson     if (sensorSchema == "Sensors")
87195a3ecadSAnthony Wilson     {
87295a3ecadSAnthony Wilson         properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
8733929aca1SAnthony Wilson                                 "/ReadingRangeMin"_json_pointer);
87495a3ecadSAnthony Wilson         properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
8753929aca1SAnthony Wilson                                 "/ReadingRangeMax"_json_pointer);
87695a3ecadSAnthony Wilson     }
87795a3ecadSAnthony Wilson     else if (sensorType == "temperature")
8781abe55efSEd Tanous     {
87908777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
8803929aca1SAnthony Wilson                                 "/MinReadingRangeTemp"_json_pointer);
88108777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
8823929aca1SAnthony Wilson                                 "/MaxReadingRangeTemp"_json_pointer);
8831abe55efSEd Tanous     }
884adc4f0dbSShawn McCarney     else if (sensorType != "power")
8851abe55efSEd Tanous     {
88608777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
8873929aca1SAnthony Wilson                                 "/MinReadingRange"_json_pointer);
88808777fb0SLewanczyk, Dawid         properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
8893929aca1SAnthony Wilson                                 "/MaxReadingRange"_json_pointer);
89008777fb0SLewanczyk, Dawid     }
89108777fb0SLewanczyk, Dawid 
8923929aca1SAnthony Wilson     for (const std::tuple<const char*, const char*,
8933929aca1SAnthony Wilson                           nlohmann::json::json_pointer>& p : properties)
8941abe55efSEd Tanous     {
89508777fb0SLewanczyk, Dawid         auto interfaceProperties = interfacesDict.find(std::get<0>(p));
8961abe55efSEd Tanous         if (interfaceProperties != interfacesDict.end())
8971abe55efSEd Tanous         {
898271584abSEd Tanous             auto thisValueIt = interfaceProperties->second.find(std::get<1>(p));
899271584abSEd Tanous             if (thisValueIt != interfaceProperties->second.end())
9001abe55efSEd Tanous             {
901271584abSEd Tanous                 const SensorVariant& valueVariant = thisValueIt->second;
9023929aca1SAnthony Wilson 
9033929aca1SAnthony Wilson                 // The property we want to set may be nested json, so use
9043929aca1SAnthony Wilson                 // a json_pointer for easy indexing into the json structure.
9053929aca1SAnthony Wilson                 const nlohmann::json::json_pointer& key = std::get<2>(p);
9063929aca1SAnthony Wilson 
90708777fb0SLewanczyk, Dawid                 // Attempt to pull the int64 directly
908abf2add6SEd Tanous                 const int64_t* int64Value = std::get_if<int64_t>(&valueVariant);
90908777fb0SLewanczyk, Dawid 
910abf2add6SEd Tanous                 const double* doubleValue = std::get_if<double>(&valueVariant);
911028f7ebcSEddie James                 const uint32_t* uValue = std::get_if<uint32_t>(&valueVariant);
9126f6d0d32SEd Tanous                 double temp = 0.0;
9136f6d0d32SEd Tanous                 if (int64Value != nullptr)
9141abe55efSEd Tanous                 {
915271584abSEd Tanous                     temp = static_cast<double>(*int64Value);
9166f6d0d32SEd Tanous                 }
9176f6d0d32SEd Tanous                 else if (doubleValue != nullptr)
9181abe55efSEd Tanous                 {
9196f6d0d32SEd Tanous                     temp = *doubleValue;
9201abe55efSEd Tanous                 }
921028f7ebcSEddie James                 else if (uValue != nullptr)
922028f7ebcSEddie James                 {
923028f7ebcSEddie James                     temp = *uValue;
924028f7ebcSEddie James                 }
9251abe55efSEd Tanous                 else
9261abe55efSEd Tanous                 {
9276f6d0d32SEd Tanous                     BMCWEB_LOG_ERROR
9286f6d0d32SEd Tanous                         << "Got value interface that wasn't int or double";
9296f6d0d32SEd Tanous                     continue;
93008777fb0SLewanczyk, Dawid                 }
9316f6d0d32SEd Tanous                 temp = temp * std::pow(10, scaleMultiplier);
9326f6d0d32SEd Tanous                 if (forceToInt)
9336f6d0d32SEd Tanous                 {
9343929aca1SAnthony Wilson                     sensor_json[key] = static_cast<int64_t>(temp);
9356f6d0d32SEd Tanous                 }
9366f6d0d32SEd Tanous                 else
9376f6d0d32SEd Tanous                 {
9383929aca1SAnthony Wilson                     sensor_json[key] = temp;
93908777fb0SLewanczyk, Dawid                 }
94008777fb0SLewanczyk, Dawid             }
94108777fb0SLewanczyk, Dawid         }
94208777fb0SLewanczyk, Dawid     }
94355c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "Added sensor " << sensorName;
94408777fb0SLewanczyk, Dawid }
94508777fb0SLewanczyk, Dawid 
9468bd25ccdSJames Feist static void
9478bd25ccdSJames Feist     populateFanRedundancy(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp)
9488bd25ccdSJames Feist {
9498bd25ccdSJames Feist     crow::connections::systemBus->async_method_call(
9508bd25ccdSJames Feist         [sensorsAsyncResp](const boost::system::error_code ec,
9518bd25ccdSJames Feist                            const GetSubTreeType& resp) {
9528bd25ccdSJames Feist             if (ec)
9538bd25ccdSJames Feist             {
9548bd25ccdSJames Feist                 return; // don't have to have this interface
9558bd25ccdSJames Feist             }
956e278c18fSEd Tanous             for (const std::pair<std::string,
957e278c18fSEd Tanous                                  std::vector<std::pair<
958e278c18fSEd Tanous                                      std::string, std::vector<std::string>>>>&
959e278c18fSEd Tanous                      pathPair : resp)
9608bd25ccdSJames Feist             {
961e278c18fSEd Tanous                 const std::string& path = pathPair.first;
962e278c18fSEd Tanous                 const std::vector<
963e278c18fSEd Tanous                     std::pair<std::string, std::vector<std::string>>>& objDict =
964e278c18fSEd Tanous                     pathPair.second;
9658bd25ccdSJames Feist                 if (objDict.empty())
9668bd25ccdSJames Feist                 {
9678bd25ccdSJames Feist                     continue; // this should be impossible
9688bd25ccdSJames Feist                 }
9698bd25ccdSJames Feist 
9708bd25ccdSJames Feist                 const std::string& owner = objDict.begin()->first;
9718bd25ccdSJames Feist                 crow::connections::systemBus->async_method_call(
9728bd25ccdSJames Feist                     [path, owner,
973271584abSEd Tanous                      sensorsAsyncResp](const boost::system::error_code e,
9748bd25ccdSJames Feist                                        std::variant<std::vector<std::string>>
9758bd25ccdSJames Feist                                            variantEndpoints) {
976271584abSEd Tanous                         if (e)
9778bd25ccdSJames Feist                         {
9788bd25ccdSJames Feist                             return; // if they don't have an association we
9798bd25ccdSJames Feist                                     // can't tell what chassis is
9808bd25ccdSJames Feist                         }
9818bd25ccdSJames Feist                         // verify part of the right chassis
9828bd25ccdSJames Feist                         auto endpoints = std::get_if<std::vector<std::string>>(
9838bd25ccdSJames Feist                             &variantEndpoints);
9848bd25ccdSJames Feist 
9858bd25ccdSJames Feist                         if (endpoints == nullptr)
9868bd25ccdSJames Feist                         {
9878bd25ccdSJames Feist                             BMCWEB_LOG_ERROR << "Invalid association interface";
9888bd25ccdSJames Feist                             messages::internalError(sensorsAsyncResp->res);
9898bd25ccdSJames Feist                             return;
9908bd25ccdSJames Feist                         }
9918bd25ccdSJames Feist 
9928bd25ccdSJames Feist                         auto found = std::find_if(
9938bd25ccdSJames Feist                             endpoints->begin(), endpoints->end(),
9948bd25ccdSJames Feist                             [sensorsAsyncResp](const std::string& entry) {
9958bd25ccdSJames Feist                                 return entry.find(
9968bd25ccdSJames Feist                                            sensorsAsyncResp->chassisId) !=
9978bd25ccdSJames Feist                                        std::string::npos;
9988bd25ccdSJames Feist                             });
9998bd25ccdSJames Feist 
10008bd25ccdSJames Feist                         if (found == endpoints->end())
10018bd25ccdSJames Feist                         {
10028bd25ccdSJames Feist                             return;
10038bd25ccdSJames Feist                         }
10048bd25ccdSJames Feist                         crow::connections::systemBus->async_method_call(
10058bd25ccdSJames Feist                             [path, sensorsAsyncResp](
1006271584abSEd Tanous                                 const boost::system::error_code& err,
10078bd25ccdSJames Feist                                 const boost::container::flat_map<
10088bd25ccdSJames Feist                                     std::string,
10098bd25ccdSJames Feist                                     std::variant<uint8_t,
10108bd25ccdSJames Feist                                                  std::vector<std::string>,
10118bd25ccdSJames Feist                                                  std::string>>& ret) {
1012271584abSEd Tanous                                 if (err)
10138bd25ccdSJames Feist                                 {
10148bd25ccdSJames Feist                                     return; // don't have to have this
10158bd25ccdSJames Feist                                             // interface
10168bd25ccdSJames Feist                                 }
10178bd25ccdSJames Feist                                 auto findFailures = ret.find("AllowedFailures");
10188bd25ccdSJames Feist                                 auto findCollection = ret.find("Collection");
10198bd25ccdSJames Feist                                 auto findStatus = ret.find("Status");
10208bd25ccdSJames Feist 
10218bd25ccdSJames Feist                                 if (findFailures == ret.end() ||
10228bd25ccdSJames Feist                                     findCollection == ret.end() ||
10238bd25ccdSJames Feist                                     findStatus == ret.end())
10248bd25ccdSJames Feist                                 {
10258bd25ccdSJames Feist                                     BMCWEB_LOG_ERROR
10268bd25ccdSJames Feist                                         << "Invalid redundancy interface";
10278bd25ccdSJames Feist                                     messages::internalError(
10288bd25ccdSJames Feist                                         sensorsAsyncResp->res);
10298bd25ccdSJames Feist                                     return;
10308bd25ccdSJames Feist                                 }
10318bd25ccdSJames Feist 
10328bd25ccdSJames Feist                                 auto allowedFailures = std::get_if<uint8_t>(
10338bd25ccdSJames Feist                                     &(findFailures->second));
10348bd25ccdSJames Feist                                 auto collection =
10358bd25ccdSJames Feist                                     std::get_if<std::vector<std::string>>(
10368bd25ccdSJames Feist                                         &(findCollection->second));
10378bd25ccdSJames Feist                                 auto status = std::get_if<std::string>(
10388bd25ccdSJames Feist                                     &(findStatus->second));
10398bd25ccdSJames Feist 
10408bd25ccdSJames Feist                                 if (allowedFailures == nullptr ||
10418bd25ccdSJames Feist                                     collection == nullptr || status == nullptr)
10428bd25ccdSJames Feist                                 {
10438bd25ccdSJames Feist 
10448bd25ccdSJames Feist                                     BMCWEB_LOG_ERROR
10458bd25ccdSJames Feist                                         << "Invalid redundancy interface "
10468bd25ccdSJames Feist                                            "types";
10478bd25ccdSJames Feist                                     messages::internalError(
10488bd25ccdSJames Feist                                         sensorsAsyncResp->res);
10498bd25ccdSJames Feist                                     return;
10508bd25ccdSJames Feist                                 }
10518bd25ccdSJames Feist                                 size_t lastSlash = path.rfind("/");
10528bd25ccdSJames Feist                                 if (lastSlash == std::string::npos)
10538bd25ccdSJames Feist                                 {
10548bd25ccdSJames Feist                                     // this should be impossible
10558bd25ccdSJames Feist                                     messages::internalError(
10568bd25ccdSJames Feist                                         sensorsAsyncResp->res);
10578bd25ccdSJames Feist                                     return;
10588bd25ccdSJames Feist                                 }
10598bd25ccdSJames Feist                                 std::string name = path.substr(lastSlash + 1);
10608bd25ccdSJames Feist                                 std::replace(name.begin(), name.end(), '_',
10618bd25ccdSJames Feist                                              ' ');
10628bd25ccdSJames Feist 
10638bd25ccdSJames Feist                                 std::string health;
10648bd25ccdSJames Feist 
10658bd25ccdSJames Feist                                 if (boost::ends_with(*status, "Full"))
10668bd25ccdSJames Feist                                 {
10678bd25ccdSJames Feist                                     health = "OK";
10688bd25ccdSJames Feist                                 }
10698bd25ccdSJames Feist                                 else if (boost::ends_with(*status, "Degraded"))
10708bd25ccdSJames Feist                                 {
10718bd25ccdSJames Feist                                     health = "Warning";
10728bd25ccdSJames Feist                                 }
10738bd25ccdSJames Feist                                 else
10748bd25ccdSJames Feist                                 {
10758bd25ccdSJames Feist                                     health = "Critical";
10768bd25ccdSJames Feist                                 }
10778bd25ccdSJames Feist                                 std::vector<nlohmann::json> redfishCollection;
10788bd25ccdSJames Feist                                 const auto& fanRedfish =
10798bd25ccdSJames Feist                                     sensorsAsyncResp->res.jsonValue["Fans"];
10808bd25ccdSJames Feist                                 for (const std::string& item : *collection)
10818bd25ccdSJames Feist                                 {
10828bd25ccdSJames Feist                                     lastSlash = item.rfind("/");
10838bd25ccdSJames Feist                                     // make a copy as collection is const
10848bd25ccdSJames Feist                                     std::string itemName =
10858bd25ccdSJames Feist                                         item.substr(lastSlash + 1);
10868bd25ccdSJames Feist                                     /*
10878bd25ccdSJames Feist                                     todo(ed): merge patch that fixes the names
10888bd25ccdSJames Feist                                     std::replace(itemName.begin(),
10898bd25ccdSJames Feist                                                  itemName.end(), '_', ' ');*/
10908bd25ccdSJames Feist                                     auto schemaItem = std::find_if(
10918bd25ccdSJames Feist                                         fanRedfish.begin(), fanRedfish.end(),
10928bd25ccdSJames Feist                                         [itemName](const nlohmann::json& fan) {
10938bd25ccdSJames Feist                                             return fan["MemberId"] == itemName;
10948bd25ccdSJames Feist                                         });
10958bd25ccdSJames Feist                                     if (schemaItem != fanRedfish.end())
10968bd25ccdSJames Feist                                     {
10978bd25ccdSJames Feist                                         redfishCollection.push_back(
10988bd25ccdSJames Feist                                             {{"@odata.id",
10998bd25ccdSJames Feist                                               (*schemaItem)["@odata.id"]}});
11008bd25ccdSJames Feist                                     }
11018bd25ccdSJames Feist                                     else
11028bd25ccdSJames Feist                                     {
11038bd25ccdSJames Feist                                         BMCWEB_LOG_ERROR
11048bd25ccdSJames Feist                                             << "failed to find fan in schema";
11058bd25ccdSJames Feist                                         messages::internalError(
11068bd25ccdSJames Feist                                             sensorsAsyncResp->res);
11078bd25ccdSJames Feist                                         return;
11088bd25ccdSJames Feist                                     }
11098bd25ccdSJames Feist                                 }
11108bd25ccdSJames Feist 
1111271584abSEd Tanous                                 nlohmann::json& jResp =
1112271584abSEd Tanous                                     sensorsAsyncResp->res
11138bd25ccdSJames Feist                                         .jsonValue["Redundancy"];
1114271584abSEd Tanous                                 jResp.push_back(
11158bd25ccdSJames Feist                                     {{"@odata.id",
1116717794d5SAppaRao Puli                                       "/redfish/v1/Chassis/" +
11178bd25ccdSJames Feist                                           sensorsAsyncResp->chassisId + "/" +
11188bd25ccdSJames Feist                                           sensorsAsyncResp->chassisSubNode +
11198bd25ccdSJames Feist                                           "#/Redundancy/" +
1120271584abSEd Tanous                                           std::to_string(jResp.size())},
11218bd25ccdSJames Feist                                      {"@odata.type",
11228bd25ccdSJames Feist                                       "#Redundancy.v1_3_2.Redundancy"},
11238bd25ccdSJames Feist                                      {"MinNumNeeded",
11248bd25ccdSJames Feist                                       collection->size() - *allowedFailures},
11258bd25ccdSJames Feist                                      {"MemberId", name},
11268bd25ccdSJames Feist                                      {"Mode", "N+m"},
11278bd25ccdSJames Feist                                      {"Name", name},
11288bd25ccdSJames Feist                                      {"RedundancySet", redfishCollection},
11298bd25ccdSJames Feist                                      {"Status",
11308bd25ccdSJames Feist                                       {{"Health", health},
11318bd25ccdSJames Feist                                        {"State", "Enabled"}}}});
11328bd25ccdSJames Feist                             },
11338bd25ccdSJames Feist                             owner, path, "org.freedesktop.DBus.Properties",
11348bd25ccdSJames Feist                             "GetAll",
11358bd25ccdSJames Feist                             "xyz.openbmc_project.Control.FanRedundancy");
11368bd25ccdSJames Feist                     },
113702e92e32SJames Feist                     "xyz.openbmc_project.ObjectMapper", path + "/chassis",
11388bd25ccdSJames Feist                     "org.freedesktop.DBus.Properties", "Get",
11398bd25ccdSJames Feist                     "xyz.openbmc_project.Association", "endpoints");
11408bd25ccdSJames Feist             }
11418bd25ccdSJames Feist         },
11428bd25ccdSJames Feist         "xyz.openbmc_project.ObjectMapper",
11438bd25ccdSJames Feist         "/xyz/openbmc_project/object_mapper",
11448bd25ccdSJames Feist         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
11458bd25ccdSJames Feist         "/xyz/openbmc_project/control", 2,
11468bd25ccdSJames Feist         std::array<const char*, 1>{
11478bd25ccdSJames Feist             "xyz.openbmc_project.Control.FanRedundancy"});
11488bd25ccdSJames Feist }
11498bd25ccdSJames Feist 
115049c53ac9SJohnathan Mantey void sortJSONResponse(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
115149c53ac9SJohnathan Mantey {
115249c53ac9SJohnathan Mantey     nlohmann::json& response = SensorsAsyncResp->res.jsonValue;
115349c53ac9SJohnathan Mantey     std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"};
115449c53ac9SJohnathan Mantey     if (SensorsAsyncResp->chassisSubNode == "Power")
115549c53ac9SJohnathan Mantey     {
115649c53ac9SJohnathan Mantey         sensorHeaders = {"Voltages", "PowerSupplies"};
115749c53ac9SJohnathan Mantey     }
115849c53ac9SJohnathan Mantey     for (const std::string& sensorGroup : sensorHeaders)
115949c53ac9SJohnathan Mantey     {
116049c53ac9SJohnathan Mantey         nlohmann::json::iterator entry = response.find(sensorGroup);
116149c53ac9SJohnathan Mantey         if (entry != response.end())
116249c53ac9SJohnathan Mantey         {
116349c53ac9SJohnathan Mantey             std::sort(entry->begin(), entry->end(),
116449c53ac9SJohnathan Mantey                       [](nlohmann::json& c1, nlohmann::json& c2) {
116549c53ac9SJohnathan Mantey                           return c1["Name"] < c2["Name"];
116649c53ac9SJohnathan Mantey                       });
116749c53ac9SJohnathan Mantey 
116849c53ac9SJohnathan Mantey             // add the index counts to the end of each entry
116949c53ac9SJohnathan Mantey             size_t count = 0;
117049c53ac9SJohnathan Mantey             for (nlohmann::json& sensorJson : *entry)
117149c53ac9SJohnathan Mantey             {
117249c53ac9SJohnathan Mantey                 nlohmann::json::iterator odata = sensorJson.find("@odata.id");
117349c53ac9SJohnathan Mantey                 if (odata == sensorJson.end())
117449c53ac9SJohnathan Mantey                 {
117549c53ac9SJohnathan Mantey                     continue;
117649c53ac9SJohnathan Mantey                 }
117749c53ac9SJohnathan Mantey                 std::string* value = odata->get_ptr<std::string*>();
117849c53ac9SJohnathan Mantey                 if (value != nullptr)
117949c53ac9SJohnathan Mantey                 {
118049c53ac9SJohnathan Mantey                     *value += std::to_string(count);
118149c53ac9SJohnathan Mantey                     count++;
118249c53ac9SJohnathan Mantey                 }
118349c53ac9SJohnathan Mantey             }
118449c53ac9SJohnathan Mantey         }
118549c53ac9SJohnathan Mantey     }
118649c53ac9SJohnathan Mantey }
118749c53ac9SJohnathan Mantey 
118808777fb0SLewanczyk, Dawid /**
1189adc4f0dbSShawn McCarney  * @brief Finds the inventory item with the specified object path.
1190adc4f0dbSShawn McCarney  * @param inventoryItems D-Bus inventory items associated with sensors.
1191adc4f0dbSShawn McCarney  * @param invItemObjPath D-Bus object path of inventory item.
1192adc4f0dbSShawn McCarney  * @return Inventory item within vector, or nullptr if no match found.
11938fb49dd6SShawn McCarney  */
1194adc4f0dbSShawn McCarney static InventoryItem* findInventoryItem(
1195adc4f0dbSShawn McCarney     std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
1196adc4f0dbSShawn McCarney     const std::string& invItemObjPath)
11978fb49dd6SShawn McCarney {
1198adc4f0dbSShawn McCarney     for (InventoryItem& inventoryItem : *inventoryItems)
11998fb49dd6SShawn McCarney     {
1200adc4f0dbSShawn McCarney         if (inventoryItem.objectPath == invItemObjPath)
12018fb49dd6SShawn McCarney         {
1202adc4f0dbSShawn McCarney             return &inventoryItem;
12038fb49dd6SShawn McCarney         }
12048fb49dd6SShawn McCarney     }
12058fb49dd6SShawn McCarney     return nullptr;
12068fb49dd6SShawn McCarney }
12078fb49dd6SShawn McCarney 
12088fb49dd6SShawn McCarney /**
1209adc4f0dbSShawn McCarney  * @brief Finds the inventory item associated with the specified sensor.
1210adc4f0dbSShawn McCarney  * @param inventoryItems D-Bus inventory items associated with sensors.
1211adc4f0dbSShawn McCarney  * @param sensorObjPath D-Bus object path of sensor.
1212adc4f0dbSShawn McCarney  * @return Inventory item within vector, or nullptr if no match found.
12138fb49dd6SShawn McCarney  */
1214adc4f0dbSShawn McCarney static InventoryItem* findInventoryItemForSensor(
1215adc4f0dbSShawn McCarney     std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
1216adc4f0dbSShawn McCarney     const std::string& sensorObjPath)
1217adc4f0dbSShawn McCarney {
1218adc4f0dbSShawn McCarney     for (InventoryItem& inventoryItem : *inventoryItems)
1219adc4f0dbSShawn McCarney     {
1220adc4f0dbSShawn McCarney         if (inventoryItem.sensors.count(sensorObjPath) > 0)
1221adc4f0dbSShawn McCarney         {
1222adc4f0dbSShawn McCarney             return &inventoryItem;
1223adc4f0dbSShawn McCarney         }
1224adc4f0dbSShawn McCarney     }
1225adc4f0dbSShawn McCarney     return nullptr;
1226adc4f0dbSShawn McCarney }
1227adc4f0dbSShawn McCarney 
1228adc4f0dbSShawn McCarney /**
1229d500549bSAnthony Wilson  * @brief Finds the inventory item associated with the specified led path.
1230d500549bSAnthony Wilson  * @param inventoryItems D-Bus inventory items associated with sensors.
1231d500549bSAnthony Wilson  * @param ledObjPath D-Bus object path of led.
1232d500549bSAnthony Wilson  * @return Inventory item within vector, or nullptr if no match found.
1233d500549bSAnthony Wilson  */
1234d500549bSAnthony Wilson inline InventoryItem*
1235d500549bSAnthony Wilson     findInventoryItemForLed(std::vector<InventoryItem>& inventoryItems,
1236d500549bSAnthony Wilson                             const std::string& ledObjPath)
1237d500549bSAnthony Wilson {
1238d500549bSAnthony Wilson     for (InventoryItem& inventoryItem : inventoryItems)
1239d500549bSAnthony Wilson     {
1240d500549bSAnthony Wilson         if (inventoryItem.ledObjectPath == ledObjPath)
1241d500549bSAnthony Wilson         {
1242d500549bSAnthony Wilson             return &inventoryItem;
1243d500549bSAnthony Wilson         }
1244d500549bSAnthony Wilson     }
1245d500549bSAnthony Wilson     return nullptr;
1246d500549bSAnthony Wilson }
1247d500549bSAnthony Wilson 
1248d500549bSAnthony Wilson /**
1249adc4f0dbSShawn McCarney  * @brief Adds inventory item and associated sensor to specified vector.
1250adc4f0dbSShawn McCarney  *
1251adc4f0dbSShawn McCarney  * Adds a new InventoryItem to the vector if necessary.  Searches for an
1252adc4f0dbSShawn McCarney  * existing InventoryItem with the specified object path.  If not found, one is
1253adc4f0dbSShawn McCarney  * added to the vector.
1254adc4f0dbSShawn McCarney  *
1255adc4f0dbSShawn McCarney  * Next, the specified sensor is added to the set of sensors associated with the
1256adc4f0dbSShawn McCarney  * InventoryItem.
1257adc4f0dbSShawn McCarney  *
1258adc4f0dbSShawn McCarney  * @param inventoryItems D-Bus inventory items associated with sensors.
1259adc4f0dbSShawn McCarney  * @param invItemObjPath D-Bus object path of inventory item.
1260adc4f0dbSShawn McCarney  * @param sensorObjPath D-Bus object path of sensor
1261adc4f0dbSShawn McCarney  */
1262adc4f0dbSShawn McCarney static void
1263adc4f0dbSShawn McCarney     addInventoryItem(std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
1264adc4f0dbSShawn McCarney                      const std::string& invItemObjPath,
1265adc4f0dbSShawn McCarney                      const std::string& sensorObjPath)
1266adc4f0dbSShawn McCarney {
1267adc4f0dbSShawn McCarney     // Look for inventory item in vector
1268adc4f0dbSShawn McCarney     InventoryItem* inventoryItem =
1269adc4f0dbSShawn McCarney         findInventoryItem(inventoryItems, invItemObjPath);
1270adc4f0dbSShawn McCarney 
1271adc4f0dbSShawn McCarney     // If inventory item doesn't exist in vector, add it
1272adc4f0dbSShawn McCarney     if (inventoryItem == nullptr)
1273adc4f0dbSShawn McCarney     {
1274adc4f0dbSShawn McCarney         inventoryItems->emplace_back(invItemObjPath);
1275adc4f0dbSShawn McCarney         inventoryItem = &(inventoryItems->back());
1276adc4f0dbSShawn McCarney     }
1277adc4f0dbSShawn McCarney 
1278adc4f0dbSShawn McCarney     // Add sensor to set of sensors associated with inventory item
1279adc4f0dbSShawn McCarney     inventoryItem->sensors.emplace(sensorObjPath);
1280adc4f0dbSShawn McCarney }
1281adc4f0dbSShawn McCarney 
1282adc4f0dbSShawn McCarney /**
1283adc4f0dbSShawn McCarney  * @brief Stores D-Bus data in the specified inventory item.
1284adc4f0dbSShawn McCarney  *
1285adc4f0dbSShawn McCarney  * Finds D-Bus data in the specified map of interfaces.  Stores the data in the
1286adc4f0dbSShawn McCarney  * specified InventoryItem.
1287adc4f0dbSShawn McCarney  *
1288adc4f0dbSShawn McCarney  * This data is later used to provide sensor property values in the JSON
1289adc4f0dbSShawn McCarney  * response.
1290adc4f0dbSShawn McCarney  *
1291adc4f0dbSShawn McCarney  * @param inventoryItem Inventory item where data will be stored.
1292adc4f0dbSShawn McCarney  * @param interfacesDict Map containing D-Bus interfaces and their properties
1293adc4f0dbSShawn McCarney  * for the specified inventory item.
1294adc4f0dbSShawn McCarney  */
1295adc4f0dbSShawn McCarney static void storeInventoryItemData(
1296adc4f0dbSShawn McCarney     InventoryItem& inventoryItem,
12978fb49dd6SShawn McCarney     const boost::container::flat_map<
12988fb49dd6SShawn McCarney         std::string, boost::container::flat_map<std::string, SensorVariant>>&
12998fb49dd6SShawn McCarney         interfacesDict)
13008fb49dd6SShawn McCarney {
1301adc4f0dbSShawn McCarney     // Get properties from Inventory.Item interface
1302adc4f0dbSShawn McCarney     auto interfaceIt =
1303adc4f0dbSShawn McCarney         interfacesDict.find("xyz.openbmc_project.Inventory.Item");
1304adc4f0dbSShawn McCarney     if (interfaceIt != interfacesDict.end())
13058fb49dd6SShawn McCarney     {
1306adc4f0dbSShawn McCarney         auto propertyIt = interfaceIt->second.find("Present");
1307adc4f0dbSShawn McCarney         if (propertyIt != interfaceIt->second.end())
13088fb49dd6SShawn McCarney         {
1309adc4f0dbSShawn McCarney             const bool* value = std::get_if<bool>(&propertyIt->second);
1310adc4f0dbSShawn McCarney             if (value != nullptr)
13118fb49dd6SShawn McCarney             {
1312adc4f0dbSShawn McCarney                 inventoryItem.isPresent = *value;
13138fb49dd6SShawn McCarney             }
13148fb49dd6SShawn McCarney         }
13158fb49dd6SShawn McCarney     }
13168fb49dd6SShawn McCarney 
1317adc4f0dbSShawn McCarney     // Check if Inventory.Item.PowerSupply interface is present
1318adc4f0dbSShawn McCarney     interfaceIt =
1319adc4f0dbSShawn McCarney         interfacesDict.find("xyz.openbmc_project.Inventory.Item.PowerSupply");
1320adc4f0dbSShawn McCarney     if (interfaceIt != interfacesDict.end())
13218fb49dd6SShawn McCarney     {
1322adc4f0dbSShawn McCarney         inventoryItem.isPowerSupply = true;
13238fb49dd6SShawn McCarney     }
1324adc4f0dbSShawn McCarney 
1325adc4f0dbSShawn McCarney     // Get properties from Inventory.Decorator.Asset interface
1326adc4f0dbSShawn McCarney     interfaceIt =
1327adc4f0dbSShawn McCarney         interfacesDict.find("xyz.openbmc_project.Inventory.Decorator.Asset");
1328adc4f0dbSShawn McCarney     if (interfaceIt != interfacesDict.end())
1329adc4f0dbSShawn McCarney     {
1330adc4f0dbSShawn McCarney         auto propertyIt = interfaceIt->second.find("Manufacturer");
1331adc4f0dbSShawn McCarney         if (propertyIt != interfaceIt->second.end())
1332adc4f0dbSShawn McCarney         {
1333adc4f0dbSShawn McCarney             const std::string* value =
1334adc4f0dbSShawn McCarney                 std::get_if<std::string>(&propertyIt->second);
1335adc4f0dbSShawn McCarney             if (value != nullptr)
1336adc4f0dbSShawn McCarney             {
1337adc4f0dbSShawn McCarney                 inventoryItem.manufacturer = *value;
1338adc4f0dbSShawn McCarney             }
1339adc4f0dbSShawn McCarney         }
1340adc4f0dbSShawn McCarney 
1341adc4f0dbSShawn McCarney         propertyIt = interfaceIt->second.find("Model");
1342adc4f0dbSShawn McCarney         if (propertyIt != interfaceIt->second.end())
1343adc4f0dbSShawn McCarney         {
1344adc4f0dbSShawn McCarney             const std::string* value =
1345adc4f0dbSShawn McCarney                 std::get_if<std::string>(&propertyIt->second);
1346adc4f0dbSShawn McCarney             if (value != nullptr)
1347adc4f0dbSShawn McCarney             {
1348adc4f0dbSShawn McCarney                 inventoryItem.model = *value;
1349adc4f0dbSShawn McCarney             }
1350adc4f0dbSShawn McCarney         }
1351adc4f0dbSShawn McCarney 
1352adc4f0dbSShawn McCarney         propertyIt = interfaceIt->second.find("PartNumber");
1353adc4f0dbSShawn McCarney         if (propertyIt != interfaceIt->second.end())
1354adc4f0dbSShawn McCarney         {
1355adc4f0dbSShawn McCarney             const std::string* value =
1356adc4f0dbSShawn McCarney                 std::get_if<std::string>(&propertyIt->second);
1357adc4f0dbSShawn McCarney             if (value != nullptr)
1358adc4f0dbSShawn McCarney             {
1359adc4f0dbSShawn McCarney                 inventoryItem.partNumber = *value;
1360adc4f0dbSShawn McCarney             }
1361adc4f0dbSShawn McCarney         }
1362adc4f0dbSShawn McCarney 
1363adc4f0dbSShawn McCarney         propertyIt = interfaceIt->second.find("SerialNumber");
1364adc4f0dbSShawn McCarney         if (propertyIt != interfaceIt->second.end())
1365adc4f0dbSShawn McCarney         {
1366adc4f0dbSShawn McCarney             const std::string* value =
1367adc4f0dbSShawn McCarney                 std::get_if<std::string>(&propertyIt->second);
1368adc4f0dbSShawn McCarney             if (value != nullptr)
1369adc4f0dbSShawn McCarney             {
1370adc4f0dbSShawn McCarney                 inventoryItem.serialNumber = *value;
1371adc4f0dbSShawn McCarney             }
1372adc4f0dbSShawn McCarney         }
1373adc4f0dbSShawn McCarney     }
1374adc4f0dbSShawn McCarney 
1375adc4f0dbSShawn McCarney     // Get properties from State.Decorator.OperationalStatus interface
1376adc4f0dbSShawn McCarney     interfaceIt = interfacesDict.find(
1377adc4f0dbSShawn McCarney         "xyz.openbmc_project.State.Decorator.OperationalStatus");
1378adc4f0dbSShawn McCarney     if (interfaceIt != interfacesDict.end())
1379adc4f0dbSShawn McCarney     {
1380adc4f0dbSShawn McCarney         auto propertyIt = interfaceIt->second.find("Functional");
1381adc4f0dbSShawn McCarney         if (propertyIt != interfaceIt->second.end())
1382adc4f0dbSShawn McCarney         {
1383adc4f0dbSShawn McCarney             const bool* value = std::get_if<bool>(&propertyIt->second);
1384adc4f0dbSShawn McCarney             if (value != nullptr)
1385adc4f0dbSShawn McCarney             {
1386adc4f0dbSShawn McCarney                 inventoryItem.isFunctional = *value;
13878fb49dd6SShawn McCarney             }
13888fb49dd6SShawn McCarney         }
13898fb49dd6SShawn McCarney     }
13908fb49dd6SShawn McCarney }
13918fb49dd6SShawn McCarney 
13928fb49dd6SShawn McCarney /**
1393adc4f0dbSShawn McCarney  * @brief Gets D-Bus data for inventory items associated with sensors.
13948fb49dd6SShawn McCarney  *
1395adc4f0dbSShawn McCarney  * Uses the specified connections (services) to obtain D-Bus data for inventory
1396adc4f0dbSShawn McCarney  * items associated with sensors.  Stores the resulting data in the
1397adc4f0dbSShawn McCarney  * inventoryItems vector.
13988fb49dd6SShawn McCarney  *
1399adc4f0dbSShawn McCarney  * This data is later used to provide sensor property values in the JSON
1400adc4f0dbSShawn McCarney  * response.
1401adc4f0dbSShawn McCarney  *
1402adc4f0dbSShawn McCarney  * Finds the inventory item data asynchronously.  Invokes callback when data has
1403adc4f0dbSShawn McCarney  * been obtained.
1404adc4f0dbSShawn McCarney  *
1405adc4f0dbSShawn McCarney  * The callback must have the following signature:
1406adc4f0dbSShawn McCarney  *   @code
1407d500549bSAnthony Wilson  *   callback(void)
1408adc4f0dbSShawn McCarney  *   @endcode
1409adc4f0dbSShawn McCarney  *
1410adc4f0dbSShawn McCarney  * This function is called recursively, obtaining data asynchronously from one
1411adc4f0dbSShawn McCarney  * connection in each call.  This ensures the callback is not invoked until the
1412adc4f0dbSShawn McCarney  * last asynchronous function has completed.
14138fb49dd6SShawn McCarney  *
14148fb49dd6SShawn McCarney  * @param sensorsAsyncResp Pointer to object holding response data.
1415adc4f0dbSShawn McCarney  * @param inventoryItems D-Bus inventory items associated with sensors.
1416adc4f0dbSShawn McCarney  * @param invConnections Connections that provide data for the inventory items.
14178fb49dd6SShawn McCarney  * @param objectMgrPaths Mappings from connection name to DBus object path that
14188fb49dd6SShawn McCarney  * implements ObjectManager.
1419adc4f0dbSShawn McCarney  * @param callback Callback to invoke when inventory data has been obtained.
1420adc4f0dbSShawn McCarney  * @param invConnectionsIndex Current index in invConnections.  Only specified
1421adc4f0dbSShawn McCarney  * in recursive calls to this function.
14228fb49dd6SShawn McCarney  */
1423adc4f0dbSShawn McCarney template <typename Callback>
1424adc4f0dbSShawn McCarney static void getInventoryItemsData(
14258fb49dd6SShawn McCarney     std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1426adc4f0dbSShawn McCarney     std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
14278fb49dd6SShawn McCarney     std::shared_ptr<boost::container::flat_set<std::string>> invConnections,
14288fb49dd6SShawn McCarney     std::shared_ptr<boost::container::flat_map<std::string, std::string>>
1429adc4f0dbSShawn McCarney         objectMgrPaths,
1430271584abSEd Tanous     Callback&& callback, size_t invConnectionsIndex = 0)
14318fb49dd6SShawn McCarney {
1432adc4f0dbSShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItemsData enter";
14338fb49dd6SShawn McCarney 
1434adc4f0dbSShawn McCarney     // If no more connections left, call callback
1435adc4f0dbSShawn McCarney     if (invConnectionsIndex >= invConnections->size())
14368fb49dd6SShawn McCarney     {
1437d500549bSAnthony Wilson         callback();
1438adc4f0dbSShawn McCarney         BMCWEB_LOG_DEBUG << "getInventoryItemsData exit";
1439adc4f0dbSShawn McCarney         return;
1440adc4f0dbSShawn McCarney     }
1441adc4f0dbSShawn McCarney 
1442adc4f0dbSShawn McCarney     // Get inventory item data from current connection
1443adc4f0dbSShawn McCarney     auto it = invConnections->nth(invConnectionsIndex);
1444adc4f0dbSShawn McCarney     if (it != invConnections->end())
1445adc4f0dbSShawn McCarney     {
1446adc4f0dbSShawn McCarney         const std::string& invConnection = *it;
1447adc4f0dbSShawn McCarney 
14488fb49dd6SShawn McCarney         // Response handler for GetManagedObjects
1449adc4f0dbSShawn McCarney         auto respHandler = [sensorsAsyncResp, inventoryItems, invConnections,
1450adc4f0dbSShawn McCarney                             objectMgrPaths, callback{std::move(callback)},
1451adc4f0dbSShawn McCarney                             invConnectionsIndex](
1452adc4f0dbSShawn McCarney                                const boost::system::error_code ec,
14538fb49dd6SShawn McCarney                                ManagedObjectsVectorType& resp) {
1454adc4f0dbSShawn McCarney             BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler enter";
14558fb49dd6SShawn McCarney             if (ec)
14568fb49dd6SShawn McCarney             {
14578fb49dd6SShawn McCarney                 BMCWEB_LOG_ERROR
1458adc4f0dbSShawn McCarney                     << "getInventoryItemsData respHandler DBus error " << ec;
14598fb49dd6SShawn McCarney                 messages::internalError(sensorsAsyncResp->res);
14608fb49dd6SShawn McCarney                 return;
14618fb49dd6SShawn McCarney             }
14628fb49dd6SShawn McCarney 
14638fb49dd6SShawn McCarney             // Loop through returned object paths
14648fb49dd6SShawn McCarney             for (const auto& objDictEntry : resp)
14658fb49dd6SShawn McCarney             {
14668fb49dd6SShawn McCarney                 const std::string& objPath =
14678fb49dd6SShawn McCarney                     static_cast<const std::string&>(objDictEntry.first);
14688fb49dd6SShawn McCarney 
1469adc4f0dbSShawn McCarney                 // If this object path is one of the specified inventory items
1470adc4f0dbSShawn McCarney                 InventoryItem* inventoryItem =
1471adc4f0dbSShawn McCarney                     findInventoryItem(inventoryItems, objPath);
1472adc4f0dbSShawn McCarney                 if (inventoryItem != nullptr)
14738fb49dd6SShawn McCarney                 {
1474adc4f0dbSShawn McCarney                     // Store inventory data in InventoryItem
1475adc4f0dbSShawn McCarney                     storeInventoryItemData(*inventoryItem, objDictEntry.second);
14768fb49dd6SShawn McCarney                 }
14778fb49dd6SShawn McCarney             }
14788fb49dd6SShawn McCarney 
1479adc4f0dbSShawn McCarney             // Recurse to get inventory item data from next connection
1480adc4f0dbSShawn McCarney             getInventoryItemsData(sensorsAsyncResp, inventoryItems,
1481adc4f0dbSShawn McCarney                                   invConnections, objectMgrPaths,
1482adc4f0dbSShawn McCarney                                   std::move(callback), invConnectionsIndex + 1);
1483adc4f0dbSShawn McCarney 
1484adc4f0dbSShawn McCarney             BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler exit";
14858fb49dd6SShawn McCarney         };
14868fb49dd6SShawn McCarney 
14878fb49dd6SShawn McCarney         // Find DBus object path that implements ObjectManager for the current
14888fb49dd6SShawn McCarney         // connection.  If no mapping found, default to "/".
14898fb49dd6SShawn McCarney         auto iter = objectMgrPaths->find(invConnection);
14908fb49dd6SShawn McCarney         const std::string& objectMgrPath =
14918fb49dd6SShawn McCarney             (iter != objectMgrPaths->end()) ? iter->second : "/";
14928fb49dd6SShawn McCarney         BMCWEB_LOG_DEBUG << "ObjectManager path for " << invConnection << " is "
14938fb49dd6SShawn McCarney                          << objectMgrPath;
14948fb49dd6SShawn McCarney 
14958fb49dd6SShawn McCarney         // Get all object paths and their interfaces for current connection
14968fb49dd6SShawn McCarney         crow::connections::systemBus->async_method_call(
14978fb49dd6SShawn McCarney             std::move(respHandler), invConnection, objectMgrPath,
14988fb49dd6SShawn McCarney             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
14998fb49dd6SShawn McCarney     }
15008fb49dd6SShawn McCarney 
1501adc4f0dbSShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItemsData exit";
15028fb49dd6SShawn McCarney }
15038fb49dd6SShawn McCarney 
15048fb49dd6SShawn McCarney /**
1505adc4f0dbSShawn McCarney  * @brief Gets connections that provide D-Bus data for inventory items.
15068fb49dd6SShawn McCarney  *
1507adc4f0dbSShawn McCarney  * Gets the D-Bus connections (services) that provide data for the inventory
1508adc4f0dbSShawn McCarney  * items that are associated with sensors.
15098fb49dd6SShawn McCarney  *
15108fb49dd6SShawn McCarney  * Finds the connections asynchronously.  Invokes callback when information has
15118fb49dd6SShawn McCarney  * been obtained.
15128fb49dd6SShawn McCarney  *
15138fb49dd6SShawn McCarney  * The callback must have the following signature:
15148fb49dd6SShawn McCarney  *   @code
15158fb49dd6SShawn McCarney  *   callback(std::shared_ptr<boost::container::flat_set<std::string>>
15168fb49dd6SShawn McCarney  *            invConnections)
15178fb49dd6SShawn McCarney  *   @endcode
15188fb49dd6SShawn McCarney  *
15198fb49dd6SShawn McCarney  * @param sensorsAsyncResp Pointer to object holding response data.
1520adc4f0dbSShawn McCarney  * @param inventoryItems D-Bus inventory items associated with sensors.
15218fb49dd6SShawn McCarney  * @param callback Callback to invoke when connections have been obtained.
15228fb49dd6SShawn McCarney  */
15238fb49dd6SShawn McCarney template <typename Callback>
15248fb49dd6SShawn McCarney static void getInventoryItemsConnections(
15258fb49dd6SShawn McCarney     std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1526adc4f0dbSShawn McCarney     std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
15278fb49dd6SShawn McCarney     Callback&& callback)
15288fb49dd6SShawn McCarney {
15298fb49dd6SShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItemsConnections enter";
15308fb49dd6SShawn McCarney 
15318fb49dd6SShawn McCarney     const std::string path = "/xyz/openbmc_project/inventory";
1532adc4f0dbSShawn McCarney     const std::array<std::string, 4> interfaces = {
15338fb49dd6SShawn McCarney         "xyz.openbmc_project.Inventory.Item",
1534adc4f0dbSShawn McCarney         "xyz.openbmc_project.Inventory.Item.PowerSupply",
1535adc4f0dbSShawn McCarney         "xyz.openbmc_project.Inventory.Decorator.Asset",
15368fb49dd6SShawn McCarney         "xyz.openbmc_project.State.Decorator.OperationalStatus"};
15378fb49dd6SShawn McCarney 
15388fb49dd6SShawn McCarney     // Response handler for parsing output from GetSubTree
15398fb49dd6SShawn McCarney     auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
1540adc4f0dbSShawn McCarney                         inventoryItems](const boost::system::error_code ec,
15418fb49dd6SShawn McCarney                                         const GetSubTreeType& subtree) {
15428fb49dd6SShawn McCarney         BMCWEB_LOG_DEBUG << "getInventoryItemsConnections respHandler enter";
15438fb49dd6SShawn McCarney         if (ec)
15448fb49dd6SShawn McCarney         {
15458fb49dd6SShawn McCarney             messages::internalError(sensorsAsyncResp->res);
15468fb49dd6SShawn McCarney             BMCWEB_LOG_ERROR
15478fb49dd6SShawn McCarney                 << "getInventoryItemsConnections respHandler DBus error " << ec;
15488fb49dd6SShawn McCarney             return;
15498fb49dd6SShawn McCarney         }
15508fb49dd6SShawn McCarney 
15518fb49dd6SShawn McCarney         // Make unique list of connections for desired inventory items
15528fb49dd6SShawn McCarney         std::shared_ptr<boost::container::flat_set<std::string>>
15538fb49dd6SShawn McCarney             invConnections =
15548fb49dd6SShawn McCarney                 std::make_shared<boost::container::flat_set<std::string>>();
15558fb49dd6SShawn McCarney         invConnections->reserve(8);
15568fb49dd6SShawn McCarney 
15578fb49dd6SShawn McCarney         // Loop through objects from GetSubTree
15588fb49dd6SShawn McCarney         for (const std::pair<
15598fb49dd6SShawn McCarney                  std::string,
15608fb49dd6SShawn McCarney                  std::vector<std::pair<std::string, std::vector<std::string>>>>&
15618fb49dd6SShawn McCarney                  object : subtree)
15628fb49dd6SShawn McCarney         {
1563adc4f0dbSShawn McCarney             // Check if object path is one of the specified inventory items
15648fb49dd6SShawn McCarney             const std::string& objPath = object.first;
1565adc4f0dbSShawn McCarney             if (findInventoryItem(inventoryItems, objPath) != nullptr)
15668fb49dd6SShawn McCarney             {
15678fb49dd6SShawn McCarney                 // Store all connections to inventory item
15688fb49dd6SShawn McCarney                 for (const std::pair<std::string, std::vector<std::string>>&
15698fb49dd6SShawn McCarney                          objData : object.second)
15708fb49dd6SShawn McCarney                 {
15718fb49dd6SShawn McCarney                     const std::string& invConnection = objData.first;
15728fb49dd6SShawn McCarney                     invConnections->insert(invConnection);
15738fb49dd6SShawn McCarney                 }
15748fb49dd6SShawn McCarney             }
15758fb49dd6SShawn McCarney         }
1576d500549bSAnthony Wilson 
15778fb49dd6SShawn McCarney         callback(invConnections);
15788fb49dd6SShawn McCarney         BMCWEB_LOG_DEBUG << "getInventoryItemsConnections respHandler exit";
15798fb49dd6SShawn McCarney     };
15808fb49dd6SShawn McCarney 
15818fb49dd6SShawn McCarney     // Make call to ObjectMapper to find all inventory items
15828fb49dd6SShawn McCarney     crow::connections::systemBus->async_method_call(
15838fb49dd6SShawn McCarney         std::move(respHandler), "xyz.openbmc_project.ObjectMapper",
15848fb49dd6SShawn McCarney         "/xyz/openbmc_project/object_mapper",
15858fb49dd6SShawn McCarney         "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 0, interfaces);
15868fb49dd6SShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItemsConnections exit";
15878fb49dd6SShawn McCarney }
15888fb49dd6SShawn McCarney 
15898fb49dd6SShawn McCarney /**
1590adc4f0dbSShawn McCarney  * @brief Gets associations from sensors to inventory items.
15918fb49dd6SShawn McCarney  *
15928fb49dd6SShawn McCarney  * Looks for ObjectMapper associations from the specified sensors to related
1593d500549bSAnthony Wilson  * inventory items. Then finds the associations from those inventory items to
1594d500549bSAnthony Wilson  * their LEDs, if any.
15958fb49dd6SShawn McCarney  *
15968fb49dd6SShawn McCarney  * Finds the inventory items asynchronously.  Invokes callback when information
15978fb49dd6SShawn McCarney  * has been obtained.
15988fb49dd6SShawn McCarney  *
15998fb49dd6SShawn McCarney  * The callback must have the following signature:
16008fb49dd6SShawn McCarney  *   @code
1601adc4f0dbSShawn McCarney  *   callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
16028fb49dd6SShawn McCarney  *   @endcode
16038fb49dd6SShawn McCarney  *
16048fb49dd6SShawn McCarney  * @param sensorsAsyncResp Pointer to object holding response data.
16058fb49dd6SShawn McCarney  * @param sensorNames All sensors within the current chassis.
16068fb49dd6SShawn McCarney  * @param objectMgrPaths Mappings from connection name to DBus object path that
16078fb49dd6SShawn McCarney  * implements ObjectManager.
16088fb49dd6SShawn McCarney  * @param callback Callback to invoke when inventory items have been obtained.
16098fb49dd6SShawn McCarney  */
16108fb49dd6SShawn McCarney template <typename Callback>
1611adc4f0dbSShawn McCarney static void getInventoryItemAssociations(
16128fb49dd6SShawn McCarney     std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
16138fb49dd6SShawn McCarney     const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
16148fb49dd6SShawn McCarney     std::shared_ptr<boost::container::flat_map<std::string, std::string>>
16158fb49dd6SShawn McCarney         objectMgrPaths,
16168fb49dd6SShawn McCarney     Callback&& callback)
16178fb49dd6SShawn McCarney {
1618adc4f0dbSShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItemAssociations enter";
16198fb49dd6SShawn McCarney 
16208fb49dd6SShawn McCarney     // Response handler for GetManagedObjects
16218fb49dd6SShawn McCarney     auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
16228fb49dd6SShawn McCarney                         sensorNames](const boost::system::error_code ec,
16238fb49dd6SShawn McCarney                                      dbus::utility::ManagedObjectType& resp) {
1624adc4f0dbSShawn McCarney         BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler enter";
16258fb49dd6SShawn McCarney         if (ec)
16268fb49dd6SShawn McCarney         {
1627adc4f0dbSShawn McCarney             BMCWEB_LOG_ERROR
1628adc4f0dbSShawn McCarney                 << "getInventoryItemAssociations respHandler DBus error " << ec;
16298fb49dd6SShawn McCarney             messages::internalError(sensorsAsyncResp->res);
16308fb49dd6SShawn McCarney             return;
16318fb49dd6SShawn McCarney         }
16328fb49dd6SShawn McCarney 
1633adc4f0dbSShawn McCarney         // Create vector to hold list of inventory items
1634adc4f0dbSShawn McCarney         std::shared_ptr<std::vector<InventoryItem>> inventoryItems =
1635adc4f0dbSShawn McCarney             std::make_shared<std::vector<InventoryItem>>();
1636adc4f0dbSShawn McCarney 
16378fb49dd6SShawn McCarney         // Loop through returned object paths
16388fb49dd6SShawn McCarney         std::string sensorAssocPath;
16398fb49dd6SShawn McCarney         sensorAssocPath.reserve(128); // avoid memory allocations
16408fb49dd6SShawn McCarney         for (const auto& objDictEntry : resp)
16418fb49dd6SShawn McCarney         {
16428fb49dd6SShawn McCarney             const std::string& objPath =
16438fb49dd6SShawn McCarney                 static_cast<const std::string&>(objDictEntry.first);
16448fb49dd6SShawn McCarney             const boost::container::flat_map<
16458fb49dd6SShawn McCarney                 std::string, boost::container::flat_map<
16468fb49dd6SShawn McCarney                                  std::string, dbus::utility::DbusVariantType>>&
16478fb49dd6SShawn McCarney                 interfacesDict = objDictEntry.second;
16488fb49dd6SShawn McCarney 
16498fb49dd6SShawn McCarney             // If path is inventory association for one of the specified sensors
16508fb49dd6SShawn McCarney             for (const std::string& sensorName : *sensorNames)
16518fb49dd6SShawn McCarney             {
16528fb49dd6SShawn McCarney                 sensorAssocPath = sensorName;
16538fb49dd6SShawn McCarney                 sensorAssocPath += "/inventory";
16548fb49dd6SShawn McCarney                 if (objPath == sensorAssocPath)
16558fb49dd6SShawn McCarney                 {
16568fb49dd6SShawn McCarney                     // Get Association interface for object path
16578fb49dd6SShawn McCarney                     auto assocIt =
16588fb49dd6SShawn McCarney                         interfacesDict.find("xyz.openbmc_project.Association");
16598fb49dd6SShawn McCarney                     if (assocIt != interfacesDict.end())
16608fb49dd6SShawn McCarney                     {
16618fb49dd6SShawn McCarney                         // Get inventory item from end point
16628fb49dd6SShawn McCarney                         auto endpointsIt = assocIt->second.find("endpoints");
16638fb49dd6SShawn McCarney                         if (endpointsIt != assocIt->second.end())
16648fb49dd6SShawn McCarney                         {
16658fb49dd6SShawn McCarney                             const std::vector<std::string>* endpoints =
16668fb49dd6SShawn McCarney                                 std::get_if<std::vector<std::string>>(
16678fb49dd6SShawn McCarney                                     &endpointsIt->second);
16688fb49dd6SShawn McCarney                             if ((endpoints != nullptr) && !endpoints->empty())
16698fb49dd6SShawn McCarney                             {
1670adc4f0dbSShawn McCarney                                 // Add inventory item to vector
1671adc4f0dbSShawn McCarney                                 const std::string& invItemPath =
1672adc4f0dbSShawn McCarney                                     endpoints->front();
1673adc4f0dbSShawn McCarney                                 addInventoryItem(inventoryItems, invItemPath,
1674adc4f0dbSShawn McCarney                                                  sensorName);
16758fb49dd6SShawn McCarney                             }
16768fb49dd6SShawn McCarney                         }
16778fb49dd6SShawn McCarney                     }
16788fb49dd6SShawn McCarney                     break;
16798fb49dd6SShawn McCarney                 }
16808fb49dd6SShawn McCarney             }
16818fb49dd6SShawn McCarney         }
16828fb49dd6SShawn McCarney 
1683d500549bSAnthony Wilson         // Now loop through the returned object paths again, this time to
1684d500549bSAnthony Wilson         // find the leds associated with the inventory items we just found
1685d500549bSAnthony Wilson         std::string inventoryAssocPath;
1686d500549bSAnthony Wilson         inventoryAssocPath.reserve(128); // avoid memory allocations
1687d500549bSAnthony Wilson         for (const auto& objDictEntry : resp)
1688d500549bSAnthony Wilson         {
1689d500549bSAnthony Wilson             const std::string& objPath =
1690d500549bSAnthony Wilson                 static_cast<const std::string&>(objDictEntry.first);
1691d500549bSAnthony Wilson             const boost::container::flat_map<
1692d500549bSAnthony Wilson                 std::string, boost::container::flat_map<
1693d500549bSAnthony Wilson                                  std::string, dbus::utility::DbusVariantType>>&
1694d500549bSAnthony Wilson                 interfacesDict = objDictEntry.second;
1695d500549bSAnthony Wilson 
1696d500549bSAnthony Wilson             for (InventoryItem& inventoryItem : *inventoryItems)
1697d500549bSAnthony Wilson             {
1698d500549bSAnthony Wilson                 inventoryAssocPath = inventoryItem.objectPath;
1699d500549bSAnthony Wilson                 inventoryAssocPath += "/leds";
1700d500549bSAnthony Wilson                 if (objPath == inventoryAssocPath)
1701d500549bSAnthony Wilson                 {
1702d500549bSAnthony Wilson                     // Get Association interface for object path
1703d500549bSAnthony Wilson                     auto assocIt =
1704d500549bSAnthony Wilson                         interfacesDict.find("xyz.openbmc_project.Association");
1705d500549bSAnthony Wilson                     if (assocIt != interfacesDict.end())
1706d500549bSAnthony Wilson                     {
1707d500549bSAnthony Wilson                         // Get inventory item from end point
1708d500549bSAnthony Wilson                         auto endpointsIt = assocIt->second.find("endpoints");
1709d500549bSAnthony Wilson                         if (endpointsIt != assocIt->second.end())
1710d500549bSAnthony Wilson                         {
1711d500549bSAnthony Wilson                             const std::vector<std::string>* endpoints =
1712d500549bSAnthony Wilson                                 std::get_if<std::vector<std::string>>(
1713d500549bSAnthony Wilson                                     &endpointsIt->second);
1714d500549bSAnthony Wilson                             if ((endpoints != nullptr) && !endpoints->empty())
1715d500549bSAnthony Wilson                             {
1716d500549bSAnthony Wilson                                 // Store LED path in inventory item
1717d500549bSAnthony Wilson                                 const std::string& ledPath = endpoints->front();
1718d500549bSAnthony Wilson                                 inventoryItem.ledObjectPath = ledPath;
1719d500549bSAnthony Wilson                             }
1720d500549bSAnthony Wilson                         }
1721d500549bSAnthony Wilson                     }
1722d500549bSAnthony Wilson                     break;
1723d500549bSAnthony Wilson                 }
1724d500549bSAnthony Wilson             }
1725d500549bSAnthony Wilson         }
1726adc4f0dbSShawn McCarney         callback(inventoryItems);
1727adc4f0dbSShawn McCarney         BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler exit";
17288fb49dd6SShawn McCarney     };
17298fb49dd6SShawn McCarney 
17308fb49dd6SShawn McCarney     // Find DBus object path that implements ObjectManager for ObjectMapper
17318fb49dd6SShawn McCarney     std::string connection = "xyz.openbmc_project.ObjectMapper";
17328fb49dd6SShawn McCarney     auto iter = objectMgrPaths->find(connection);
17338fb49dd6SShawn McCarney     const std::string& objectMgrPath =
17348fb49dd6SShawn McCarney         (iter != objectMgrPaths->end()) ? iter->second : "/";
17358fb49dd6SShawn McCarney     BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is "
17368fb49dd6SShawn McCarney                      << objectMgrPath;
17378fb49dd6SShawn McCarney 
17388fb49dd6SShawn McCarney     // Call GetManagedObjects on the ObjectMapper to get all associations
17398fb49dd6SShawn McCarney     crow::connections::systemBus->async_method_call(
17408fb49dd6SShawn McCarney         std::move(respHandler), connection, objectMgrPath,
17418fb49dd6SShawn McCarney         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
17428fb49dd6SShawn McCarney 
1743adc4f0dbSShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItemAssociations exit";
17448fb49dd6SShawn McCarney }
17458fb49dd6SShawn McCarney 
17468fb49dd6SShawn McCarney /**
1747d500549bSAnthony Wilson  * @brief Gets D-Bus data for inventory item leds associated with sensors.
1748d500549bSAnthony Wilson  *
1749d500549bSAnthony Wilson  * Uses the specified connections (services) to obtain D-Bus data for inventory
1750d500549bSAnthony Wilson  * item leds associated with sensors.  Stores the resulting data in the
1751d500549bSAnthony Wilson  * inventoryItems vector.
1752d500549bSAnthony Wilson  *
1753d500549bSAnthony Wilson  * This data is later used to provide sensor property values in the JSON
1754d500549bSAnthony Wilson  * response.
1755d500549bSAnthony Wilson  *
1756d500549bSAnthony Wilson  * Finds the inventory item led data asynchronously.  Invokes callback when data
1757d500549bSAnthony Wilson  * has been obtained.
1758d500549bSAnthony Wilson  *
1759d500549bSAnthony Wilson  * The callback must have the following signature:
1760d500549bSAnthony Wilson  *   @code
1761d500549bSAnthony Wilson  *   callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
1762d500549bSAnthony Wilson  *   @endcode
1763d500549bSAnthony Wilson  *
1764d500549bSAnthony Wilson  * This function is called recursively, obtaining data asynchronously from one
1765d500549bSAnthony Wilson  * connection in each call.  This ensures the callback is not invoked until the
1766d500549bSAnthony Wilson  * last asynchronous function has completed.
1767d500549bSAnthony Wilson  *
1768d500549bSAnthony Wilson  * @param sensorsAsyncResp Pointer to object holding response data.
1769d500549bSAnthony Wilson  * @param inventoryItems D-Bus inventory items associated with sensors.
1770d500549bSAnthony Wilson  * @param ledConnections Connections that provide data for the inventory leds.
1771d500549bSAnthony Wilson  * @param callback Callback to invoke when inventory data has been obtained.
1772d500549bSAnthony Wilson  * @param ledConnectionsIndex Current index in ledConnections.  Only specified
1773d500549bSAnthony Wilson  * in recursive calls to this function.
1774d500549bSAnthony Wilson  */
1775d500549bSAnthony Wilson template <typename Callback>
1776d500549bSAnthony Wilson void getInventoryLedData(
1777d500549bSAnthony Wilson     std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1778d500549bSAnthony Wilson     std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
1779d500549bSAnthony Wilson     std::shared_ptr<boost::container::flat_map<std::string, std::string>>
1780d500549bSAnthony Wilson         ledConnections,
1781d500549bSAnthony Wilson     Callback&& callback, size_t ledConnectionsIndex = 0)
1782d500549bSAnthony Wilson {
1783d500549bSAnthony Wilson     BMCWEB_LOG_DEBUG << "getInventoryLedData enter";
1784d500549bSAnthony Wilson 
1785d500549bSAnthony Wilson     // If no more connections left, call callback
1786d500549bSAnthony Wilson     if (ledConnectionsIndex >= ledConnections->size())
1787d500549bSAnthony Wilson     {
1788d500549bSAnthony Wilson         callback(inventoryItems);
1789d500549bSAnthony Wilson         BMCWEB_LOG_DEBUG << "getInventoryLedData exit";
1790d500549bSAnthony Wilson         return;
1791d500549bSAnthony Wilson     }
1792d500549bSAnthony Wilson 
1793d500549bSAnthony Wilson     // Get inventory item data from current connection
1794d500549bSAnthony Wilson     auto it = ledConnections->nth(ledConnectionsIndex);
1795d500549bSAnthony Wilson     if (it != ledConnections->end())
1796d500549bSAnthony Wilson     {
1797d500549bSAnthony Wilson         const std::string& ledPath = (*it).first;
1798d500549bSAnthony Wilson         const std::string& ledConnection = (*it).second;
1799d500549bSAnthony Wilson         // Response handler for Get State property
1800d500549bSAnthony Wilson         auto respHandler =
1801d500549bSAnthony Wilson             [sensorsAsyncResp, inventoryItems, ledConnections, ledPath,
1802d500549bSAnthony Wilson              callback{std::move(callback)},
1803d500549bSAnthony Wilson              ledConnectionsIndex](const boost::system::error_code ec,
1804d500549bSAnthony Wilson                                   const std::variant<std::string>& ledState) {
1805d500549bSAnthony Wilson                 BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter";
1806d500549bSAnthony Wilson                 if (ec)
1807d500549bSAnthony Wilson                 {
1808d500549bSAnthony Wilson                     BMCWEB_LOG_ERROR
1809d500549bSAnthony Wilson                         << "getInventoryLedData respHandler DBus error " << ec;
1810d500549bSAnthony Wilson                     messages::internalError(sensorsAsyncResp->res);
1811d500549bSAnthony Wilson                     return;
1812d500549bSAnthony Wilson                 }
1813d500549bSAnthony Wilson 
1814d500549bSAnthony Wilson                 const std::string* state = std::get_if<std::string>(&ledState);
1815d500549bSAnthony Wilson                 if (state != nullptr)
1816d500549bSAnthony Wilson                 {
1817d500549bSAnthony Wilson                     BMCWEB_LOG_DEBUG << "Led state: " << *state;
1818d500549bSAnthony Wilson                     // Find inventory item with this LED object path
1819d500549bSAnthony Wilson                     InventoryItem* inventoryItem =
1820d500549bSAnthony Wilson                         findInventoryItemForLed(*inventoryItems, ledPath);
1821d500549bSAnthony Wilson                     if (inventoryItem != nullptr)
1822d500549bSAnthony Wilson                     {
1823d500549bSAnthony Wilson                         // Store LED state in InventoryItem
1824d500549bSAnthony Wilson                         if (boost::ends_with(*state, "On"))
1825d500549bSAnthony Wilson                         {
1826d500549bSAnthony Wilson                             inventoryItem->ledState = LedState::ON;
1827d500549bSAnthony Wilson                         }
1828d500549bSAnthony Wilson                         else if (boost::ends_with(*state, "Blink"))
1829d500549bSAnthony Wilson                         {
1830d500549bSAnthony Wilson                             inventoryItem->ledState = LedState::BLINK;
1831d500549bSAnthony Wilson                         }
1832d500549bSAnthony Wilson                         else if (boost::ends_with(*state, "Off"))
1833d500549bSAnthony Wilson                         {
1834d500549bSAnthony Wilson                             inventoryItem->ledState = LedState::OFF;
1835d500549bSAnthony Wilson                         }
1836d500549bSAnthony Wilson                         else
1837d500549bSAnthony Wilson                         {
1838d500549bSAnthony Wilson                             inventoryItem->ledState = LedState::UNKNOWN;
1839d500549bSAnthony Wilson                         }
1840d500549bSAnthony Wilson                     }
1841d500549bSAnthony Wilson                 }
1842d500549bSAnthony Wilson                 else
1843d500549bSAnthony Wilson                 {
1844d500549bSAnthony Wilson                     BMCWEB_LOG_DEBUG << "Failed to find State data for LED: "
1845d500549bSAnthony Wilson                                      << ledPath;
1846d500549bSAnthony Wilson                 }
1847d500549bSAnthony Wilson 
1848d500549bSAnthony Wilson                 // Recurse to get LED data from next connection
1849d500549bSAnthony Wilson                 getInventoryLedData(sensorsAsyncResp, inventoryItems,
1850d500549bSAnthony Wilson                                     ledConnections, std::move(callback),
1851d500549bSAnthony Wilson                                     ledConnectionsIndex + 1);
1852d500549bSAnthony Wilson 
1853d500549bSAnthony Wilson                 BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler exit";
1854d500549bSAnthony Wilson             };
1855d500549bSAnthony Wilson 
1856d500549bSAnthony Wilson         // Get the State property for the current LED
1857d500549bSAnthony Wilson         crow::connections::systemBus->async_method_call(
1858d500549bSAnthony Wilson             std::move(respHandler), ledConnection, ledPath,
1859d500549bSAnthony Wilson             "org.freedesktop.DBus.Properties", "Get",
1860d500549bSAnthony Wilson             "xyz.openbmc_project.Led.Physical", "State");
1861d500549bSAnthony Wilson     }
1862d500549bSAnthony Wilson 
1863d500549bSAnthony Wilson     BMCWEB_LOG_DEBUG << "getInventoryLedData exit";
1864d500549bSAnthony Wilson }
1865d500549bSAnthony Wilson 
1866d500549bSAnthony Wilson /**
1867d500549bSAnthony Wilson  * @brief Gets LED data for LEDs associated with given inventory items.
1868d500549bSAnthony Wilson  *
1869d500549bSAnthony Wilson  * Gets the D-Bus connections (services) that provide LED data for the LEDs
1870d500549bSAnthony Wilson  * associated with the specified inventory items.  Then gets the LED data from
1871d500549bSAnthony Wilson  * each connection and stores it in the inventory item.
1872d500549bSAnthony Wilson  *
1873d500549bSAnthony Wilson  * This data is later used to provide sensor property values in the JSON
1874d500549bSAnthony Wilson  * response.
1875d500549bSAnthony Wilson  *
1876d500549bSAnthony Wilson  * Finds the LED data asynchronously.  Invokes callback when information has
1877d500549bSAnthony Wilson  * been obtained.
1878d500549bSAnthony Wilson  *
1879d500549bSAnthony Wilson  * The callback must have the following signature:
1880d500549bSAnthony Wilson  *   @code
1881d500549bSAnthony Wilson  *   callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
1882d500549bSAnthony Wilson  *   @endcode
1883d500549bSAnthony Wilson  *
1884d500549bSAnthony Wilson  * @param sensorsAsyncResp Pointer to object holding response data.
1885d500549bSAnthony Wilson  * @param inventoryItems D-Bus inventory items associated with sensors.
1886d500549bSAnthony Wilson  * @param callback Callback to invoke when inventory items have been obtained.
1887d500549bSAnthony Wilson  */
1888d500549bSAnthony Wilson template <typename Callback>
1889d500549bSAnthony Wilson void getInventoryLeds(
1890d500549bSAnthony Wilson     std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1891d500549bSAnthony Wilson     std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
1892d500549bSAnthony Wilson     Callback&& callback)
1893d500549bSAnthony Wilson {
1894d500549bSAnthony Wilson     BMCWEB_LOG_DEBUG << "getInventoryLeds enter";
1895d500549bSAnthony Wilson 
1896d500549bSAnthony Wilson     const std::string path = "/xyz/openbmc_project";
1897d500549bSAnthony Wilson     const std::array<std::string, 1> interfaces = {
1898d500549bSAnthony Wilson         "xyz.openbmc_project.Led.Physical"};
1899d500549bSAnthony Wilson 
1900d500549bSAnthony Wilson     // Response handler for parsing output from GetSubTree
1901d500549bSAnthony Wilson     auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp,
1902d500549bSAnthony Wilson                         inventoryItems](const boost::system::error_code ec,
1903d500549bSAnthony Wilson                                         const GetSubTreeType& subtree) {
1904d500549bSAnthony Wilson         BMCWEB_LOG_DEBUG << "getInventoryLeds respHandler enter";
1905d500549bSAnthony Wilson         if (ec)
1906d500549bSAnthony Wilson         {
1907d500549bSAnthony Wilson             messages::internalError(sensorsAsyncResp->res);
1908d500549bSAnthony Wilson             BMCWEB_LOG_ERROR << "getInventoryLeds respHandler DBus error "
1909d500549bSAnthony Wilson                              << ec;
1910d500549bSAnthony Wilson             return;
1911d500549bSAnthony Wilson         }
1912d500549bSAnthony Wilson 
1913d500549bSAnthony Wilson         // Build map of LED object paths to connections
1914d500549bSAnthony Wilson         std::shared_ptr<boost::container::flat_map<std::string, std::string>>
1915d500549bSAnthony Wilson             ledConnections = std::make_shared<
1916d500549bSAnthony Wilson                 boost::container::flat_map<std::string, std::string>>();
1917d500549bSAnthony Wilson 
1918d500549bSAnthony Wilson         // Loop through objects from GetSubTree
1919d500549bSAnthony Wilson         for (const std::pair<
1920d500549bSAnthony Wilson                  std::string,
1921d500549bSAnthony Wilson                  std::vector<std::pair<std::string, std::vector<std::string>>>>&
1922d500549bSAnthony Wilson                  object : subtree)
1923d500549bSAnthony Wilson         {
1924d500549bSAnthony Wilson             // Check if object path is LED for one of the specified inventory
1925d500549bSAnthony Wilson             // items
1926d500549bSAnthony Wilson             const std::string& ledPath = object.first;
1927d500549bSAnthony Wilson             if (findInventoryItemForLed(*inventoryItems, ledPath) != nullptr)
1928d500549bSAnthony Wilson             {
1929d500549bSAnthony Wilson                 // Add mapping from ledPath to connection
1930d500549bSAnthony Wilson                 const std::string& connection = object.second.begin()->first;
1931d500549bSAnthony Wilson                 (*ledConnections)[ledPath] = connection;
1932d500549bSAnthony Wilson                 BMCWEB_LOG_DEBUG << "Added mapping " << ledPath << " -> "
1933d500549bSAnthony Wilson                                  << connection;
1934d500549bSAnthony Wilson             }
1935d500549bSAnthony Wilson         }
1936d500549bSAnthony Wilson 
1937d500549bSAnthony Wilson         getInventoryLedData(sensorsAsyncResp, inventoryItems, ledConnections,
1938d500549bSAnthony Wilson                             std::move(callback));
1939d500549bSAnthony Wilson         BMCWEB_LOG_DEBUG << "getInventoryLeds respHandler exit";
1940d500549bSAnthony Wilson     };
1941d500549bSAnthony Wilson     // Make call to ObjectMapper to find all inventory items
1942d500549bSAnthony Wilson     crow::connections::systemBus->async_method_call(
1943d500549bSAnthony Wilson         std::move(respHandler), "xyz.openbmc_project.ObjectMapper",
1944d500549bSAnthony Wilson         "/xyz/openbmc_project/object_mapper",
1945d500549bSAnthony Wilson         "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 0, interfaces);
1946d500549bSAnthony Wilson     BMCWEB_LOG_DEBUG << "getInventoryLeds exit";
1947d500549bSAnthony Wilson }
1948d500549bSAnthony Wilson 
1949d500549bSAnthony Wilson /**
1950adc4f0dbSShawn McCarney  * @brief Gets inventory items associated with sensors.
19518fb49dd6SShawn McCarney  *
19528fb49dd6SShawn McCarney  * Finds the inventory items that are associated with the specified sensors.
1953adc4f0dbSShawn McCarney  * Then gets D-Bus data for the inventory items, such as presence and VPD.
19548fb49dd6SShawn McCarney  *
1955adc4f0dbSShawn McCarney  * This data is later used to provide sensor property values in the JSON
1956adc4f0dbSShawn McCarney  * response.
19578fb49dd6SShawn McCarney  *
1958adc4f0dbSShawn McCarney  * Finds the inventory items asynchronously.  Invokes callback when the
1959adc4f0dbSShawn McCarney  * inventory items have been obtained.
1960adc4f0dbSShawn McCarney  *
1961adc4f0dbSShawn McCarney  * The callback must have the following signature:
1962adc4f0dbSShawn McCarney  *   @code
1963adc4f0dbSShawn McCarney  *   callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
1964adc4f0dbSShawn McCarney  *   @endcode
19658fb49dd6SShawn McCarney  *
19668fb49dd6SShawn McCarney  * @param sensorsAsyncResp Pointer to object holding response data.
19678fb49dd6SShawn McCarney  * @param sensorNames All sensors within the current chassis.
19688fb49dd6SShawn McCarney  * @param objectMgrPaths Mappings from connection name to DBus object path that
19698fb49dd6SShawn McCarney  * implements ObjectManager.
1970adc4f0dbSShawn McCarney  * @param callback Callback to invoke when inventory items have been obtained.
19718fb49dd6SShawn McCarney  */
1972adc4f0dbSShawn McCarney template <typename Callback>
1973adc4f0dbSShawn McCarney static void getInventoryItems(
19748fb49dd6SShawn McCarney     std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
19758fb49dd6SShawn McCarney     const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
19768fb49dd6SShawn McCarney     std::shared_ptr<boost::container::flat_map<std::string, std::string>>
1977adc4f0dbSShawn McCarney         objectMgrPaths,
1978adc4f0dbSShawn McCarney     Callback&& callback)
19798fb49dd6SShawn McCarney {
1980adc4f0dbSShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItems enter";
1981adc4f0dbSShawn McCarney     auto getInventoryItemAssociationsCb =
1982adc4f0dbSShawn McCarney         [sensorsAsyncResp, objectMgrPaths, callback{std::move(callback)}](
1983adc4f0dbSShawn McCarney             std::shared_ptr<std::vector<InventoryItem>> inventoryItems) {
1984adc4f0dbSShawn McCarney             BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb enter";
19858fb49dd6SShawn McCarney             auto getInventoryItemsConnectionsCb =
1986adc4f0dbSShawn McCarney                 [sensorsAsyncResp, inventoryItems, objectMgrPaths,
1987adc4f0dbSShawn McCarney                  callback{std::move(callback)}](
19888fb49dd6SShawn McCarney                     std::shared_ptr<boost::container::flat_set<std::string>>
19898fb49dd6SShawn McCarney                         invConnections) {
19908fb49dd6SShawn McCarney                     BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb enter";
1991d500549bSAnthony Wilson                     auto getInventoryItemsDataCb =
1992d500549bSAnthony Wilson                         [sensorsAsyncResp, inventoryItems,
1993d500549bSAnthony Wilson                          callback{std::move(callback)}]() {
1994d500549bSAnthony Wilson                             BMCWEB_LOG_DEBUG << "getInventoryItemsDataCb enter";
1995d500549bSAnthony Wilson                             // Find led connections and get the data
1996d500549bSAnthony Wilson                             getInventoryLeds(sensorsAsyncResp, inventoryItems,
1997d500549bSAnthony Wilson                                              std::move(callback));
1998d500549bSAnthony Wilson                             BMCWEB_LOG_DEBUG << "getInventoryItemsDataCb exit";
1999d500549bSAnthony Wilson                         };
20008fb49dd6SShawn McCarney 
2001adc4f0dbSShawn McCarney                     // Get inventory item data from connections
2002adc4f0dbSShawn McCarney                     getInventoryItemsData(sensorsAsyncResp, inventoryItems,
2003adc4f0dbSShawn McCarney                                           invConnections, objectMgrPaths,
2004d500549bSAnthony Wilson                                           std::move(getInventoryItemsDataCb));
20058fb49dd6SShawn McCarney                     BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb exit";
20068fb49dd6SShawn McCarney                 };
20078fb49dd6SShawn McCarney 
2008adc4f0dbSShawn McCarney             // Get connections that provide inventory item data
20098fb49dd6SShawn McCarney             getInventoryItemsConnections(
2010adc4f0dbSShawn McCarney                 sensorsAsyncResp, inventoryItems,
20118fb49dd6SShawn McCarney                 std::move(getInventoryItemsConnectionsCb));
2012adc4f0dbSShawn McCarney             BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb exit";
20138fb49dd6SShawn McCarney         };
20148fb49dd6SShawn McCarney 
2015adc4f0dbSShawn McCarney     // Get associations from sensors to inventory items
2016adc4f0dbSShawn McCarney     getInventoryItemAssociations(sensorsAsyncResp, sensorNames, objectMgrPaths,
2017adc4f0dbSShawn McCarney                                  std::move(getInventoryItemAssociationsCb));
2018adc4f0dbSShawn McCarney     BMCWEB_LOG_DEBUG << "getInventoryItems exit";
2019adc4f0dbSShawn McCarney }
2020adc4f0dbSShawn McCarney 
2021adc4f0dbSShawn McCarney /**
2022adc4f0dbSShawn McCarney  * @brief Returns JSON PowerSupply object for the specified inventory item.
2023adc4f0dbSShawn McCarney  *
2024adc4f0dbSShawn McCarney  * Searches for a JSON PowerSupply object that matches the specified inventory
2025adc4f0dbSShawn McCarney  * item.  If one is not found, a new PowerSupply object is added to the JSON
2026adc4f0dbSShawn McCarney  * array.
2027adc4f0dbSShawn McCarney  *
2028adc4f0dbSShawn McCarney  * Multiple sensors are often associated with one power supply inventory item.
2029adc4f0dbSShawn McCarney  * As a result, multiple sensor values are stored in one JSON PowerSupply
2030adc4f0dbSShawn McCarney  * object.
2031adc4f0dbSShawn McCarney  *
2032adc4f0dbSShawn McCarney  * @param powerSupplyArray JSON array containing Redfish PowerSupply objects.
2033adc4f0dbSShawn McCarney  * @param inventoryItem Inventory item for the power supply.
2034adc4f0dbSShawn McCarney  * @param chassisId Chassis that contains the power supply.
2035adc4f0dbSShawn McCarney  * @return JSON PowerSupply object for the specified inventory item.
2036adc4f0dbSShawn McCarney  */
2037adc4f0dbSShawn McCarney static nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
2038adc4f0dbSShawn McCarney                                       const InventoryItem& inventoryItem,
2039adc4f0dbSShawn McCarney                                       const std::string& chassisId)
2040adc4f0dbSShawn McCarney {
2041adc4f0dbSShawn McCarney     // Check if matching PowerSupply object already exists in JSON array
2042adc4f0dbSShawn McCarney     for (nlohmann::json& powerSupply : powerSupplyArray)
2043adc4f0dbSShawn McCarney     {
2044adc4f0dbSShawn McCarney         if (powerSupply["MemberId"] == inventoryItem.name)
2045adc4f0dbSShawn McCarney         {
2046adc4f0dbSShawn McCarney             return powerSupply;
2047adc4f0dbSShawn McCarney         }
2048adc4f0dbSShawn McCarney     }
2049adc4f0dbSShawn McCarney 
2050adc4f0dbSShawn McCarney     // Add new PowerSupply object to JSON array
2051adc4f0dbSShawn McCarney     powerSupplyArray.push_back({});
2052adc4f0dbSShawn McCarney     nlohmann::json& powerSupply = powerSupplyArray.back();
2053adc4f0dbSShawn McCarney     powerSupply["@odata.id"] =
2054adc4f0dbSShawn McCarney         "/redfish/v1/Chassis/" + chassisId + "/Power#/PowerSupplies/";
2055adc4f0dbSShawn McCarney     powerSupply["MemberId"] = inventoryItem.name;
2056adc4f0dbSShawn McCarney     powerSupply["Name"] = boost::replace_all_copy(inventoryItem.name, "_", " ");
2057adc4f0dbSShawn McCarney     powerSupply["Manufacturer"] = inventoryItem.manufacturer;
2058adc4f0dbSShawn McCarney     powerSupply["Model"] = inventoryItem.model;
2059adc4f0dbSShawn McCarney     powerSupply["PartNumber"] = inventoryItem.partNumber;
2060adc4f0dbSShawn McCarney     powerSupply["SerialNumber"] = inventoryItem.serialNumber;
2061d500549bSAnthony Wilson     setLedState(powerSupply, &inventoryItem);
2062adc4f0dbSShawn McCarney     powerSupply["Status"]["State"] = getState(&inventoryItem);
2063adc4f0dbSShawn McCarney 
2064adc4f0dbSShawn McCarney     const char* health = inventoryItem.isFunctional ? "OK" : "Critical";
2065adc4f0dbSShawn McCarney     powerSupply["Status"]["Health"] = health;
2066adc4f0dbSShawn McCarney 
2067adc4f0dbSShawn McCarney     return powerSupply;
20688fb49dd6SShawn McCarney }
20698fb49dd6SShawn McCarney 
20708fb49dd6SShawn McCarney /**
2071de629b6eSShawn McCarney  * @brief Gets the values of the specified sensors.
2072de629b6eSShawn McCarney  *
2073de629b6eSShawn McCarney  * Stores the results as JSON in the SensorsAsyncResp.
2074de629b6eSShawn McCarney  *
2075de629b6eSShawn McCarney  * Gets the sensor values asynchronously.  Stores the results later when the
2076de629b6eSShawn McCarney  * information has been obtained.
2077de629b6eSShawn McCarney  *
2078adc4f0dbSShawn McCarney  * The sensorNames set contains all requested sensors for the current chassis.
2079de629b6eSShawn McCarney  *
2080de629b6eSShawn McCarney  * To minimize the number of DBus calls, the DBus method
2081de629b6eSShawn McCarney  * org.freedesktop.DBus.ObjectManager.GetManagedObjects() is used to get the
2082de629b6eSShawn McCarney  * values of all sensors provided by a connection (service).
2083de629b6eSShawn McCarney  *
2084de629b6eSShawn McCarney  * The connections set contains all the connections that provide sensor values.
2085de629b6eSShawn McCarney  *
2086de629b6eSShawn McCarney  * The objectMgrPaths map contains mappings from a connection name to the
2087de629b6eSShawn McCarney  * corresponding DBus object path that implements ObjectManager.
2088de629b6eSShawn McCarney  *
2089adc4f0dbSShawn McCarney  * The InventoryItem vector contains D-Bus inventory items associated with the
2090adc4f0dbSShawn McCarney  * sensors.  Inventory item data is needed for some Redfish sensor properties.
2091adc4f0dbSShawn McCarney  *
2092de629b6eSShawn McCarney  * @param SensorsAsyncResp Pointer to object holding response data.
2093adc4f0dbSShawn McCarney  * @param sensorNames All requested sensors within the current chassis.
2094de629b6eSShawn McCarney  * @param connections Connections that provide sensor values.
2095de629b6eSShawn McCarney  * @param objectMgrPaths Mappings from connection name to DBus object path that
2096de629b6eSShawn McCarney  * implements ObjectManager.
2097adc4f0dbSShawn McCarney  * @param inventoryItems Inventory items associated with the sensors.
2098de629b6eSShawn McCarney  */
2099de629b6eSShawn McCarney void getSensorData(
2100de629b6eSShawn McCarney     std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
210149c53ac9SJohnathan Mantey     const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames,
2102de629b6eSShawn McCarney     const boost::container::flat_set<std::string>& connections,
21038fb49dd6SShawn McCarney     std::shared_ptr<boost::container::flat_map<std::string, std::string>>
2104adc4f0dbSShawn McCarney         objectMgrPaths,
2105adc4f0dbSShawn McCarney     std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
2106de629b6eSShawn McCarney {
2107de629b6eSShawn McCarney     BMCWEB_LOG_DEBUG << "getSensorData enter";
2108de629b6eSShawn McCarney     // Get managed objects from all services exposing sensors
2109de629b6eSShawn McCarney     for (const std::string& connection : connections)
2110de629b6eSShawn McCarney     {
2111de629b6eSShawn McCarney         // Response handler to process managed objects
21128fb49dd6SShawn McCarney         auto getManagedObjectsCb = [SensorsAsyncResp, sensorNames,
2113adc4f0dbSShawn McCarney                                     inventoryItems](
2114de629b6eSShawn McCarney                                        const boost::system::error_code ec,
2115de629b6eSShawn McCarney                                        ManagedObjectsVectorType& resp) {
2116de629b6eSShawn McCarney             BMCWEB_LOG_DEBUG << "getManagedObjectsCb enter";
2117de629b6eSShawn McCarney             if (ec)
2118de629b6eSShawn McCarney             {
2119de629b6eSShawn McCarney                 BMCWEB_LOG_ERROR << "getManagedObjectsCb DBUS error: " << ec;
2120de629b6eSShawn McCarney                 messages::internalError(SensorsAsyncResp->res);
2121de629b6eSShawn McCarney                 return;
2122de629b6eSShawn McCarney             }
2123de629b6eSShawn McCarney             // Go through all objects and update response with sensor data
2124de629b6eSShawn McCarney             for (const auto& objDictEntry : resp)
2125de629b6eSShawn McCarney             {
2126de629b6eSShawn McCarney                 const std::string& objPath =
2127de629b6eSShawn McCarney                     static_cast<const std::string&>(objDictEntry.first);
2128de629b6eSShawn McCarney                 BMCWEB_LOG_DEBUG << "getManagedObjectsCb parsing object "
2129de629b6eSShawn McCarney                                  << objPath;
2130de629b6eSShawn McCarney 
2131de629b6eSShawn McCarney                 std::vector<std::string> split;
2132de629b6eSShawn McCarney                 // Reserve space for
2133de629b6eSShawn McCarney                 // /xyz/openbmc_project/sensors/<name>/<subname>
2134de629b6eSShawn McCarney                 split.reserve(6);
2135de629b6eSShawn McCarney                 boost::algorithm::split(split, objPath, boost::is_any_of("/"));
2136de629b6eSShawn McCarney                 if (split.size() < 6)
2137de629b6eSShawn McCarney                 {
2138de629b6eSShawn McCarney                     BMCWEB_LOG_ERROR << "Got path that isn't long enough "
2139de629b6eSShawn McCarney                                      << objPath;
2140de629b6eSShawn McCarney                     continue;
2141de629b6eSShawn McCarney                 }
2142de629b6eSShawn McCarney                 // These indexes aren't intuitive, as boost::split puts an empty
2143de629b6eSShawn McCarney                 // string at the beginning
2144de629b6eSShawn McCarney                 const std::string& sensorType = split[4];
2145de629b6eSShawn McCarney                 const std::string& sensorName = split[5];
2146de629b6eSShawn McCarney                 BMCWEB_LOG_DEBUG << "sensorName " << sensorName
2147de629b6eSShawn McCarney                                  << " sensorType " << sensorType;
214849c53ac9SJohnathan Mantey                 if (sensorNames->find(objPath) == sensorNames->end())
2149de629b6eSShawn McCarney                 {
2150de629b6eSShawn McCarney                     BMCWEB_LOG_ERROR << sensorName << " not in sensor list ";
2151de629b6eSShawn McCarney                     continue;
2152de629b6eSShawn McCarney                 }
2153de629b6eSShawn McCarney 
2154adc4f0dbSShawn McCarney                 // Find inventory item (if any) associated with sensor
2155adc4f0dbSShawn McCarney                 InventoryItem* inventoryItem =
2156adc4f0dbSShawn McCarney                     findInventoryItemForSensor(inventoryItems, objPath);
2157adc4f0dbSShawn McCarney 
215895a3ecadSAnthony Wilson                 const std::string& sensorSchema =
215995a3ecadSAnthony Wilson                     SensorsAsyncResp->chassisSubNode;
216095a3ecadSAnthony Wilson 
216195a3ecadSAnthony Wilson                 nlohmann::json* sensorJson = nullptr;
216295a3ecadSAnthony Wilson 
216395a3ecadSAnthony Wilson                 if (sensorSchema == "Sensors")
216495a3ecadSAnthony Wilson                 {
216595a3ecadSAnthony Wilson                     SensorsAsyncResp->res.jsonValue["@odata.id"] =
216695a3ecadSAnthony Wilson                         "/redfish/v1/Chassis/" + SensorsAsyncResp->chassisId +
216795a3ecadSAnthony Wilson                         "/" + SensorsAsyncResp->chassisSubNode + "/" +
216895a3ecadSAnthony Wilson                         sensorName;
216995a3ecadSAnthony Wilson                     sensorJson = &(SensorsAsyncResp->res.jsonValue);
217095a3ecadSAnthony Wilson                 }
217195a3ecadSAnthony Wilson                 else
217295a3ecadSAnthony Wilson                 {
2173271584abSEd Tanous                     std::string fieldName;
2174de629b6eSShawn McCarney                     if (sensorType == "temperature")
2175de629b6eSShawn McCarney                     {
2176de629b6eSShawn McCarney                         fieldName = "Temperatures";
2177de629b6eSShawn McCarney                     }
2178de629b6eSShawn McCarney                     else if (sensorType == "fan" || sensorType == "fan_tach" ||
2179de629b6eSShawn McCarney                              sensorType == "fan_pwm")
2180de629b6eSShawn McCarney                     {
2181de629b6eSShawn McCarney                         fieldName = "Fans";
2182de629b6eSShawn McCarney                     }
2183de629b6eSShawn McCarney                     else if (sensorType == "voltage")
2184de629b6eSShawn McCarney                     {
2185de629b6eSShawn McCarney                         fieldName = "Voltages";
2186de629b6eSShawn McCarney                     }
2187de629b6eSShawn McCarney                     else if (sensorType == "power")
2188de629b6eSShawn McCarney                     {
2189028f7ebcSEddie James                         if (!sensorName.compare("total_power"))
2190028f7ebcSEddie James                         {
2191028f7ebcSEddie James                             fieldName = "PowerControl";
2192028f7ebcSEddie James                         }
2193adc4f0dbSShawn McCarney                         else if ((inventoryItem != nullptr) &&
2194adc4f0dbSShawn McCarney                                  (inventoryItem->isPowerSupply))
2195028f7ebcSEddie James                         {
2196de629b6eSShawn McCarney                             fieldName = "PowerSupplies";
2197de629b6eSShawn McCarney                         }
2198adc4f0dbSShawn McCarney                         else
2199adc4f0dbSShawn McCarney                         {
2200adc4f0dbSShawn McCarney                             // Other power sensors are in SensorCollection
2201adc4f0dbSShawn McCarney                             continue;
2202adc4f0dbSShawn McCarney                         }
2203028f7ebcSEddie James                     }
2204de629b6eSShawn McCarney                     else
2205de629b6eSShawn McCarney                     {
2206de629b6eSShawn McCarney                         BMCWEB_LOG_ERROR << "Unsure how to handle sensorType "
2207de629b6eSShawn McCarney                                          << sensorType;
2208de629b6eSShawn McCarney                         continue;
2209de629b6eSShawn McCarney                     }
2210de629b6eSShawn McCarney 
2211de629b6eSShawn McCarney                     nlohmann::json& tempArray =
2212de629b6eSShawn McCarney                         SensorsAsyncResp->res.jsonValue[fieldName];
2213adc4f0dbSShawn McCarney                     if (fieldName == "PowerControl")
221449c53ac9SJohnathan Mantey                     {
2215adc4f0dbSShawn McCarney                         if (tempArray.empty())
22167ab06f49SGunnar Mills                         {
221795a3ecadSAnthony Wilson                             // Put multiple "sensors" into a single
221895a3ecadSAnthony Wilson                             // PowerControl. Follows MemberId naming and
221995a3ecadSAnthony Wilson                             // naming in power.hpp.
22207ab06f49SGunnar Mills                             tempArray.push_back(
2221adc4f0dbSShawn McCarney                                 {{"@odata.id",
2222adc4f0dbSShawn McCarney                                   "/redfish/v1/Chassis/" +
22237ab06f49SGunnar Mills                                       SensorsAsyncResp->chassisId + "/" +
2224adc4f0dbSShawn McCarney                                       SensorsAsyncResp->chassisSubNode + "#/" +
2225adc4f0dbSShawn McCarney                                       fieldName + "/0"}});
2226adc4f0dbSShawn McCarney                         }
2227adc4f0dbSShawn McCarney                         sensorJson = &(tempArray.back());
2228adc4f0dbSShawn McCarney                     }
2229adc4f0dbSShawn McCarney                     else if (fieldName == "PowerSupplies")
2230adc4f0dbSShawn McCarney                     {
2231adc4f0dbSShawn McCarney                         if (inventoryItem != nullptr)
2232adc4f0dbSShawn McCarney                         {
2233adc4f0dbSShawn McCarney                             sensorJson =
2234adc4f0dbSShawn McCarney                                 &(getPowerSupply(tempArray, *inventoryItem,
2235adc4f0dbSShawn McCarney                                                  SensorsAsyncResp->chassisId));
2236adc4f0dbSShawn McCarney                         }
223749c53ac9SJohnathan Mantey                     }
223849c53ac9SJohnathan Mantey                     else
223949c53ac9SJohnathan Mantey                     {
2240de629b6eSShawn McCarney                         tempArray.push_back(
224195a3ecadSAnthony Wilson                             {{"@odata.id",
224295a3ecadSAnthony Wilson                               "/redfish/v1/Chassis/" +
224349c53ac9SJohnathan Mantey                                   SensorsAsyncResp->chassisId + "/" +
224495a3ecadSAnthony Wilson                                   SensorsAsyncResp->chassisSubNode + "#/" +
224595a3ecadSAnthony Wilson                                   fieldName + "/"}});
2246adc4f0dbSShawn McCarney                         sensorJson = &(tempArray.back());
224749c53ac9SJohnathan Mantey                     }
224895a3ecadSAnthony Wilson                 }
2249de629b6eSShawn McCarney 
2250adc4f0dbSShawn McCarney                 if (sensorJson != nullptr)
2251adc4f0dbSShawn McCarney                 {
2252de629b6eSShawn McCarney                     objectInterfacesToJson(sensorName, sensorType,
225395a3ecadSAnthony Wilson                                            SensorsAsyncResp->chassisSubNode,
2254adc4f0dbSShawn McCarney                                            objDictEntry.second, *sensorJson,
2255adc4f0dbSShawn McCarney                                            inventoryItem);
2256adc4f0dbSShawn McCarney                 }
2257de629b6eSShawn McCarney             }
225849c53ac9SJohnathan Mantey             if (SensorsAsyncResp.use_count() == 1)
225949c53ac9SJohnathan Mantey             {
226049c53ac9SJohnathan Mantey                 sortJSONResponse(SensorsAsyncResp);
226149c53ac9SJohnathan Mantey                 if (SensorsAsyncResp->chassisSubNode == "Thermal")
22628bd25ccdSJames Feist                 {
22638bd25ccdSJames Feist                     populateFanRedundancy(SensorsAsyncResp);
22648bd25ccdSJames Feist                 }
226549c53ac9SJohnathan Mantey             }
2266de629b6eSShawn McCarney             BMCWEB_LOG_DEBUG << "getManagedObjectsCb exit";
2267de629b6eSShawn McCarney         };
2268de629b6eSShawn McCarney 
2269de629b6eSShawn McCarney         // Find DBus object path that implements ObjectManager for the current
2270de629b6eSShawn McCarney         // connection.  If no mapping found, default to "/".
22718fb49dd6SShawn McCarney         auto iter = objectMgrPaths->find(connection);
2272de629b6eSShawn McCarney         const std::string& objectMgrPath =
22738fb49dd6SShawn McCarney             (iter != objectMgrPaths->end()) ? iter->second : "/";
2274de629b6eSShawn McCarney         BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is "
2275de629b6eSShawn McCarney                          << objectMgrPath;
2276de629b6eSShawn McCarney 
2277de629b6eSShawn McCarney         crow::connections::systemBus->async_method_call(
2278de629b6eSShawn McCarney             getManagedObjectsCb, connection, objectMgrPath,
2279de629b6eSShawn McCarney             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
2280de629b6eSShawn McCarney     };
2281de629b6eSShawn McCarney     BMCWEB_LOG_DEBUG << "getSensorData exit";
2282de629b6eSShawn McCarney }
2283de629b6eSShawn McCarney 
228495a3ecadSAnthony Wilson void processSensorList(
228595a3ecadSAnthony Wilson     std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
228695a3ecadSAnthony Wilson     std::shared_ptr<boost::container::flat_set<std::string>> sensorNames)
22871abe55efSEd Tanous {
228895a3ecadSAnthony Wilson     auto getConnectionCb =
228995a3ecadSAnthony Wilson         [SensorsAsyncResp, sensorNames](
229095a3ecadSAnthony Wilson             const boost::container::flat_set<std::string>& connections) {
229155c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "getConnectionCb enter";
2292de629b6eSShawn McCarney             auto getObjectManagerPathsCb =
229349c53ac9SJohnathan Mantey                 [SensorsAsyncResp, sensorNames, connections](
229495a3ecadSAnthony Wilson                     std::shared_ptr<
229595a3ecadSAnthony Wilson                         boost::container::flat_map<std::string, std::string>>
22968fb49dd6SShawn McCarney                         objectMgrPaths) {
2297de629b6eSShawn McCarney                     BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb enter";
2298adc4f0dbSShawn McCarney                     auto getInventoryItemsCb =
2299adc4f0dbSShawn McCarney                         [SensorsAsyncResp, sensorNames, connections,
2300adc4f0dbSShawn McCarney                          objectMgrPaths](
2301adc4f0dbSShawn McCarney                             std::shared_ptr<std::vector<InventoryItem>>
2302adc4f0dbSShawn McCarney                                 inventoryItems) {
2303adc4f0dbSShawn McCarney                             BMCWEB_LOG_DEBUG << "getInventoryItemsCb enter";
230449c53ac9SJohnathan Mantey                             // Get sensor data and store results in JSON
2305de629b6eSShawn McCarney                             getSensorData(SensorsAsyncResp, sensorNames,
2306adc4f0dbSShawn McCarney                                           connections, objectMgrPaths,
2307adc4f0dbSShawn McCarney                                           inventoryItems);
2308adc4f0dbSShawn McCarney                             BMCWEB_LOG_DEBUG << "getInventoryItemsCb exit";
2309adc4f0dbSShawn McCarney                         };
2310adc4f0dbSShawn McCarney 
2311adc4f0dbSShawn McCarney                     // Get inventory items associated with sensors
2312adc4f0dbSShawn McCarney                     getInventoryItems(SensorsAsyncResp, sensorNames,
2313adc4f0dbSShawn McCarney                                       objectMgrPaths,
2314adc4f0dbSShawn McCarney                                       std::move(getInventoryItemsCb));
2315adc4f0dbSShawn McCarney 
2316de629b6eSShawn McCarney                     BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb exit";
231708777fb0SLewanczyk, Dawid                 };
2318de629b6eSShawn McCarney 
231949c53ac9SJohnathan Mantey             // Get mapping from connection names to the DBus object
232049c53ac9SJohnathan Mantey             // paths that implement the ObjectManager interface
2321de629b6eSShawn McCarney             getObjectManagerPaths(SensorsAsyncResp,
2322de629b6eSShawn McCarney                                   std::move(getObjectManagerPathsCb));
232355c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "getConnectionCb exit";
232408777fb0SLewanczyk, Dawid         };
2325de629b6eSShawn McCarney 
2326de629b6eSShawn McCarney     // Get set of connections that provide sensor values
232795a3ecadSAnthony Wilson     getConnections(SensorsAsyncResp, sensorNames, std::move(getConnectionCb));
232895a3ecadSAnthony Wilson }
232995a3ecadSAnthony Wilson 
233095a3ecadSAnthony Wilson /**
233195a3ecadSAnthony Wilson  * @brief Entry point for retrieving sensors data related to requested
233295a3ecadSAnthony Wilson  *        chassis.
233395a3ecadSAnthony Wilson  * @param SensorsAsyncResp   Pointer to object holding response data
233495a3ecadSAnthony Wilson  */
233595a3ecadSAnthony Wilson void getChassisData(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp)
233695a3ecadSAnthony Wilson {
233795a3ecadSAnthony Wilson     BMCWEB_LOG_DEBUG << "getChassisData enter";
233895a3ecadSAnthony Wilson     auto getChassisCb =
233995a3ecadSAnthony Wilson         [SensorsAsyncResp](
234095a3ecadSAnthony Wilson             std::shared_ptr<boost::container::flat_set<std::string>>
234195a3ecadSAnthony Wilson                 sensorNames) {
234295a3ecadSAnthony Wilson             BMCWEB_LOG_DEBUG << "getChassisCb enter";
234395a3ecadSAnthony Wilson             processSensorList(SensorsAsyncResp, sensorNames);
234455c7b7a2SEd Tanous             BMCWEB_LOG_DEBUG << "getChassisCb exit";
234508777fb0SLewanczyk, Dawid         };
23464f9a2130SJennifer Lee     SensorsAsyncResp->res.jsonValue["Redundancy"] = nlohmann::json::array();
234708777fb0SLewanczyk, Dawid 
234826f03899SShawn McCarney     // Get set of sensors in chassis
2349588c3f0dSKowalski, Kamil     getChassis(SensorsAsyncResp, std::move(getChassisCb));
235055c7b7a2SEd Tanous     BMCWEB_LOG_DEBUG << "getChassisData exit";
2351271584abSEd Tanous }
235208777fb0SLewanczyk, Dawid 
2353413961deSRichard Marian Thomaiyar /**
235449c53ac9SJohnathan Mantey  * @brief Find the requested sensorName in the list of all sensors supplied by
235549c53ac9SJohnathan Mantey  * the chassis node
235649c53ac9SJohnathan Mantey  *
235749c53ac9SJohnathan Mantey  * @param sensorName   The sensor name supplied in the PATCH request
235849c53ac9SJohnathan Mantey  * @param sensorsList  The list of sensors managed by the chassis node
235949c53ac9SJohnathan Mantey  * @param sensorsModified  The list of sensors that were found as a result of
236049c53ac9SJohnathan Mantey  *                         repeated calls to this function
236149c53ac9SJohnathan Mantey  */
236249c53ac9SJohnathan Mantey bool findSensorNameUsingSensorPath(
23630a86febdSRichard Marian Thomaiyar     std::string_view sensorName,
236449c53ac9SJohnathan Mantey     boost::container::flat_set<std::string>& sensorsList,
236549c53ac9SJohnathan Mantey     boost::container::flat_set<std::string>& sensorsModified)
236649c53ac9SJohnathan Mantey {
23670a86febdSRichard Marian Thomaiyar     for (std::string_view chassisSensor : sensorsList)
236849c53ac9SJohnathan Mantey     {
23690a86febdSRichard Marian Thomaiyar         std::size_t pos = chassisSensor.rfind("/");
23700a86febdSRichard Marian Thomaiyar         if (pos >= (chassisSensor.size() - 1))
237149c53ac9SJohnathan Mantey         {
237249c53ac9SJohnathan Mantey             continue;
237349c53ac9SJohnathan Mantey         }
23740a86febdSRichard Marian Thomaiyar         std::string_view thisSensorName = chassisSensor.substr(pos + 1);
237549c53ac9SJohnathan Mantey         if (thisSensorName == sensorName)
237649c53ac9SJohnathan Mantey         {
237749c53ac9SJohnathan Mantey             sensorsModified.emplace(chassisSensor);
237849c53ac9SJohnathan Mantey             return true;
237949c53ac9SJohnathan Mantey         }
238049c53ac9SJohnathan Mantey     }
238149c53ac9SJohnathan Mantey     return false;
238249c53ac9SJohnathan Mantey }
238349c53ac9SJohnathan Mantey 
238449c53ac9SJohnathan Mantey /**
2385413961deSRichard Marian Thomaiyar  * @brief Entry point for overriding sensor values of given sensor
2386413961deSRichard Marian Thomaiyar  *
2387413961deSRichard Marian Thomaiyar  * @param res   response object
2388*4bb3dc34SCarol Wang  * @param allCollections   Collections extract from sensors' request patch info
2389413961deSRichard Marian Thomaiyar  * @param typeList   TypeList of sensors for the resource queried
2390413961deSRichard Marian Thomaiyar  * @param chassisSubNode   Chassis Node for which the query has to happen
2391413961deSRichard Marian Thomaiyar  */
2392*4bb3dc34SCarol Wang void setSensorOverride(
2393*4bb3dc34SCarol Wang     std::shared_ptr<SensorsAsyncResp> sensorAsyncResp,
2394*4bb3dc34SCarol Wang     std::unordered_map<std::string, std::vector<nlohmann::json>>&
2395*4bb3dc34SCarol Wang         allCollections,
2396*4bb3dc34SCarol Wang     const std::string& chassisName, const std::vector<const char*> typeList)
2397413961deSRichard Marian Thomaiyar {
2398*4bb3dc34SCarol Wang     BMCWEB_LOG_INFO << "setSensorOverride for subNode"
2399*4bb3dc34SCarol Wang                     << sensorAsyncResp->chassisSubNode << "\n";
2400413961deSRichard Marian Thomaiyar 
2401f65af9e8SRichard Marian Thomaiyar     const char* propertyValueName;
2402f65af9e8SRichard Marian Thomaiyar     std::unordered_map<std::string, std::pair<double, std::string>> overrideMap;
2403413961deSRichard Marian Thomaiyar     std::string memberId;
2404413961deSRichard Marian Thomaiyar     double value;
2405f65af9e8SRichard Marian Thomaiyar     for (auto& collectionItems : allCollections)
2406f65af9e8SRichard Marian Thomaiyar     {
2407f65af9e8SRichard Marian Thomaiyar         if (collectionItems.first == "Temperatures")
2408f65af9e8SRichard Marian Thomaiyar         {
2409f65af9e8SRichard Marian Thomaiyar             propertyValueName = "ReadingCelsius";
2410f65af9e8SRichard Marian Thomaiyar         }
2411f65af9e8SRichard Marian Thomaiyar         else if (collectionItems.first == "Fans")
2412f65af9e8SRichard Marian Thomaiyar         {
2413f65af9e8SRichard Marian Thomaiyar             propertyValueName = "Reading";
2414f65af9e8SRichard Marian Thomaiyar         }
2415f65af9e8SRichard Marian Thomaiyar         else
2416f65af9e8SRichard Marian Thomaiyar         {
2417f65af9e8SRichard Marian Thomaiyar             propertyValueName = "ReadingVolts";
2418f65af9e8SRichard Marian Thomaiyar         }
2419f65af9e8SRichard Marian Thomaiyar         for (auto& item : collectionItems.second)
2420f65af9e8SRichard Marian Thomaiyar         {
2421*4bb3dc34SCarol Wang             if (!json_util::readJson(item, sensorAsyncResp->res, "MemberId",
2422*4bb3dc34SCarol Wang                                      memberId, propertyValueName, value))
2423413961deSRichard Marian Thomaiyar             {
2424413961deSRichard Marian Thomaiyar                 return;
2425413961deSRichard Marian Thomaiyar             }
2426f65af9e8SRichard Marian Thomaiyar             overrideMap.emplace(memberId,
2427f65af9e8SRichard Marian Thomaiyar                                 std::make_pair(value, collectionItems.first));
2428f65af9e8SRichard Marian Thomaiyar         }
2429f65af9e8SRichard Marian Thomaiyar     }
2430*4bb3dc34SCarol Wang 
243149c53ac9SJohnathan Mantey     auto getChassisSensorListCb = [sensorAsyncResp,
243249c53ac9SJohnathan Mantey                                    overrideMap](const std::shared_ptr<
243349c53ac9SJohnathan Mantey                                                 boost::container::flat_set<
243449c53ac9SJohnathan Mantey                                                     std::string>>
243549c53ac9SJohnathan Mantey                                                     sensorsList) {
243649c53ac9SJohnathan Mantey         // Match sensor names in the PATCH request to those managed by the
243749c53ac9SJohnathan Mantey         // chassis node
243849c53ac9SJohnathan Mantey         const std::shared_ptr<boost::container::flat_set<std::string>>
243949c53ac9SJohnathan Mantey             sensorNames =
244049c53ac9SJohnathan Mantey                 std::make_shared<boost::container::flat_set<std::string>>();
2441f65af9e8SRichard Marian Thomaiyar         for (const auto& item : overrideMap)
2442413961deSRichard Marian Thomaiyar         {
2443f65af9e8SRichard Marian Thomaiyar             const auto& sensor = item.first;
244449c53ac9SJohnathan Mantey             if (!findSensorNameUsingSensorPath(sensor, *sensorsList,
244549c53ac9SJohnathan Mantey                                                *sensorNames))
2446f65af9e8SRichard Marian Thomaiyar             {
2447f65af9e8SRichard Marian Thomaiyar                 BMCWEB_LOG_INFO << "Unable to find memberId " << item.first;
2448413961deSRichard Marian Thomaiyar                 messages::resourceNotFound(sensorAsyncResp->res,
2449f65af9e8SRichard Marian Thomaiyar                                            item.second.second, item.first);
2450413961deSRichard Marian Thomaiyar                 return;
2451413961deSRichard Marian Thomaiyar             }
2452f65af9e8SRichard Marian Thomaiyar         }
2453413961deSRichard Marian Thomaiyar         // Get the connection to which the memberId belongs
2454413961deSRichard Marian Thomaiyar         auto getObjectsWithConnectionCb =
2455f65af9e8SRichard Marian Thomaiyar             [sensorAsyncResp, overrideMap](
2456413961deSRichard Marian Thomaiyar                 const boost::container::flat_set<std::string>& connections,
2457413961deSRichard Marian Thomaiyar                 const std::set<std::pair<std::string, std::string>>&
2458413961deSRichard Marian Thomaiyar                     objectsWithConnection) {
2459f65af9e8SRichard Marian Thomaiyar                 if (objectsWithConnection.size() != overrideMap.size())
2460413961deSRichard Marian Thomaiyar                 {
2461413961deSRichard Marian Thomaiyar                     BMCWEB_LOG_INFO
2462f65af9e8SRichard Marian Thomaiyar                         << "Unable to find all objects with proper connection "
2463f65af9e8SRichard Marian Thomaiyar                         << objectsWithConnection.size() << " requested "
2464f65af9e8SRichard Marian Thomaiyar                         << overrideMap.size() << "\n";
2465413961deSRichard Marian Thomaiyar                     messages::resourceNotFound(
2466413961deSRichard Marian Thomaiyar                         sensorAsyncResp->res,
2467413961deSRichard Marian Thomaiyar                         sensorAsyncResp->chassisSubNode == "Thermal"
2468413961deSRichard Marian Thomaiyar                             ? "Temperatures"
2469413961deSRichard Marian Thomaiyar                             : "Voltages",
2470f65af9e8SRichard Marian Thomaiyar                         "Count");
2471f65af9e8SRichard Marian Thomaiyar                     return;
2472f65af9e8SRichard Marian Thomaiyar                 }
2473f65af9e8SRichard Marian Thomaiyar                 for (const auto& item : objectsWithConnection)
2474f65af9e8SRichard Marian Thomaiyar                 {
2475f65af9e8SRichard Marian Thomaiyar 
2476f65af9e8SRichard Marian Thomaiyar                     auto lastPos = item.first.rfind('/');
2477f65af9e8SRichard Marian Thomaiyar                     if (lastPos == std::string::npos)
2478f65af9e8SRichard Marian Thomaiyar                     {
2479f65af9e8SRichard Marian Thomaiyar                         messages::internalError(sensorAsyncResp->res);
2480f65af9e8SRichard Marian Thomaiyar                         return;
2481f65af9e8SRichard Marian Thomaiyar                     }
2482f65af9e8SRichard Marian Thomaiyar                     std::string sensorName = item.first.substr(lastPos + 1);
2483f65af9e8SRichard Marian Thomaiyar 
2484f65af9e8SRichard Marian Thomaiyar                     const auto& iterator = overrideMap.find(sensorName);
2485f65af9e8SRichard Marian Thomaiyar                     if (iterator == overrideMap.end())
2486f65af9e8SRichard Marian Thomaiyar                     {
2487f65af9e8SRichard Marian Thomaiyar                         BMCWEB_LOG_INFO << "Unable to find sensor object"
2488f65af9e8SRichard Marian Thomaiyar                                         << item.first << "\n";
2489f65af9e8SRichard Marian Thomaiyar                         messages::internalError(sensorAsyncResp->res);
2490413961deSRichard Marian Thomaiyar                         return;
2491413961deSRichard Marian Thomaiyar                     }
2492413961deSRichard Marian Thomaiyar                     crow::connections::systemBus->async_method_call(
2493f65af9e8SRichard Marian Thomaiyar                         [sensorAsyncResp](const boost::system::error_code ec) {
2494413961deSRichard Marian Thomaiyar                             if (ec)
2495413961deSRichard Marian Thomaiyar                             {
2496413961deSRichard Marian Thomaiyar                                 BMCWEB_LOG_DEBUG
2497f65af9e8SRichard Marian Thomaiyar                                     << "setOverrideValueStatus DBUS error: "
2498413961deSRichard Marian Thomaiyar                                     << ec;
2499413961deSRichard Marian Thomaiyar                                 messages::internalError(sensorAsyncResp->res);
2500413961deSRichard Marian Thomaiyar                                 return;
2501413961deSRichard Marian Thomaiyar                             }
2502413961deSRichard Marian Thomaiyar                         },
2503f65af9e8SRichard Marian Thomaiyar                         item.second, item.first,
2504413961deSRichard Marian Thomaiyar                         "org.freedesktop.DBus.Properties", "Set",
2505413961deSRichard Marian Thomaiyar                         "xyz.openbmc_project.Sensor.Value", "Value",
2506f65af9e8SRichard Marian Thomaiyar                         sdbusplus::message::variant<double>(
2507f65af9e8SRichard Marian Thomaiyar                             iterator->second.first));
2508f65af9e8SRichard Marian Thomaiyar                 }
2509413961deSRichard Marian Thomaiyar             };
2510413961deSRichard Marian Thomaiyar         // Get object with connection for the given sensor name
2511413961deSRichard Marian Thomaiyar         getObjectsWithConnection(sensorAsyncResp, sensorNames,
2512413961deSRichard Marian Thomaiyar                                  std::move(getObjectsWithConnectionCb));
2513413961deSRichard Marian Thomaiyar     };
2514413961deSRichard Marian Thomaiyar     // get full sensor list for the given chassisId and cross verify the sensor.
2515413961deSRichard Marian Thomaiyar     getChassis(sensorAsyncResp, std::move(getChassisSensorListCb));
2516413961deSRichard Marian Thomaiyar }
2517413961deSRichard Marian Thomaiyar 
251895a3ecadSAnthony Wilson class SensorCollection : public Node
251995a3ecadSAnthony Wilson {
252095a3ecadSAnthony Wilson   public:
252195a3ecadSAnthony Wilson     SensorCollection(CrowApp& app) :
252295a3ecadSAnthony Wilson         Node(app, "/redfish/v1/Chassis/<str>/Sensors", std::string())
252395a3ecadSAnthony Wilson     {
252495a3ecadSAnthony Wilson         entityPrivileges = {
252595a3ecadSAnthony Wilson             {boost::beast::http::verb::get, {{"Login"}}},
252695a3ecadSAnthony Wilson             {boost::beast::http::verb::head, {{"Login"}}},
252795a3ecadSAnthony Wilson             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
252895a3ecadSAnthony Wilson             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
252995a3ecadSAnthony Wilson             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
253095a3ecadSAnthony Wilson             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
253195a3ecadSAnthony Wilson     }
253295a3ecadSAnthony Wilson 
253395a3ecadSAnthony Wilson   private:
253495a3ecadSAnthony Wilson     std::vector<const char*> typeList = {
253595a3ecadSAnthony Wilson         "/xyz/openbmc_project/sensors/power",
253695a3ecadSAnthony Wilson         "/xyz/openbmc_project/sensors/current"};
253795a3ecadSAnthony Wilson     void doGet(crow::Response& res, const crow::Request& req,
253895a3ecadSAnthony Wilson                const std::vector<std::string>& params) override
253995a3ecadSAnthony Wilson     {
254095a3ecadSAnthony Wilson         BMCWEB_LOG_DEBUG << "SensorCollection doGet enter";
254195a3ecadSAnthony Wilson         if (params.size() != 1)
254295a3ecadSAnthony Wilson         {
254395a3ecadSAnthony Wilson             BMCWEB_LOG_DEBUG << "SensorCollection doGet param size < 1";
254495a3ecadSAnthony Wilson             messages::internalError(res);
254595a3ecadSAnthony Wilson             res.end();
254695a3ecadSAnthony Wilson             return;
254795a3ecadSAnthony Wilson         }
254895a3ecadSAnthony Wilson 
254995a3ecadSAnthony Wilson         const std::string& chassisId = params[0];
255095a3ecadSAnthony Wilson         std::shared_ptr<SensorsAsyncResp> asyncResp =
255195a3ecadSAnthony Wilson             std::make_shared<SensorsAsyncResp>(res, chassisId, typeList,
255295a3ecadSAnthony Wilson                                                "Sensors");
255395a3ecadSAnthony Wilson 
255495a3ecadSAnthony Wilson         auto getChassisCb =
255595a3ecadSAnthony Wilson             [asyncResp](std::shared_ptr<boost::container::flat_set<std::string>>
255695a3ecadSAnthony Wilson                             sensorNames) {
255795a3ecadSAnthony Wilson                 BMCWEB_LOG_DEBUG << "getChassisCb enter";
255895a3ecadSAnthony Wilson 
255995a3ecadSAnthony Wilson                 nlohmann::json& entriesArray =
256095a3ecadSAnthony Wilson                     asyncResp->res.jsonValue["Members"];
256195a3ecadSAnthony Wilson                 for (auto& sensor : *sensorNames)
256295a3ecadSAnthony Wilson                 {
256395a3ecadSAnthony Wilson                     BMCWEB_LOG_DEBUG << "Adding sensor: " << sensor;
256495a3ecadSAnthony Wilson 
256595a3ecadSAnthony Wilson                     std::size_t lastPos = sensor.rfind("/");
256695a3ecadSAnthony Wilson                     if (lastPos == std::string::npos ||
256795a3ecadSAnthony Wilson                         lastPos + 1 >= sensor.size())
256895a3ecadSAnthony Wilson                     {
256995a3ecadSAnthony Wilson                         BMCWEB_LOG_ERROR << "Invalid sensor path: " << sensor;
257095a3ecadSAnthony Wilson                         messages::internalError(asyncResp->res);
257195a3ecadSAnthony Wilson                         return;
257295a3ecadSAnthony Wilson                     }
257395a3ecadSAnthony Wilson                     std::string sensorName = sensor.substr(lastPos + 1);
257495a3ecadSAnthony Wilson                     entriesArray.push_back(
257595a3ecadSAnthony Wilson                         {{"@odata.id",
257695a3ecadSAnthony Wilson                           "/redfish/v1/Chassis/" + asyncResp->chassisId + "/" +
257795a3ecadSAnthony Wilson                               asyncResp->chassisSubNode + "/" + sensorName}});
257895a3ecadSAnthony Wilson                 }
257995a3ecadSAnthony Wilson 
258095a3ecadSAnthony Wilson                 asyncResp->res.jsonValue["Members@odata.count"] =
258195a3ecadSAnthony Wilson                     entriesArray.size();
258295a3ecadSAnthony Wilson                 BMCWEB_LOG_DEBUG << "getChassisCb exit";
258395a3ecadSAnthony Wilson             };
258495a3ecadSAnthony Wilson 
258595a3ecadSAnthony Wilson         // Get set of sensors in chassis
258695a3ecadSAnthony Wilson         getChassis(asyncResp, std::move(getChassisCb));
258795a3ecadSAnthony Wilson         BMCWEB_LOG_DEBUG << "SensorCollection doGet exit";
258895a3ecadSAnthony Wilson     }
258995a3ecadSAnthony Wilson };
259095a3ecadSAnthony Wilson 
259195a3ecadSAnthony Wilson class Sensor : public Node
259295a3ecadSAnthony Wilson {
259395a3ecadSAnthony Wilson   public:
259495a3ecadSAnthony Wilson     Sensor(CrowApp& app) :
259595a3ecadSAnthony Wilson         Node(app, "/redfish/v1/Chassis/<str>/Sensors/<str>/", std::string(),
259695a3ecadSAnthony Wilson              std::string())
259795a3ecadSAnthony Wilson     {
259895a3ecadSAnthony Wilson         entityPrivileges = {
259995a3ecadSAnthony Wilson             {boost::beast::http::verb::get, {{"Login"}}},
260095a3ecadSAnthony Wilson             {boost::beast::http::verb::head, {{"Login"}}},
260195a3ecadSAnthony Wilson             {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
260295a3ecadSAnthony Wilson             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
260395a3ecadSAnthony Wilson             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
260495a3ecadSAnthony Wilson             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
260595a3ecadSAnthony Wilson     }
260695a3ecadSAnthony Wilson 
260795a3ecadSAnthony Wilson   private:
260895a3ecadSAnthony Wilson     void doGet(crow::Response& res, const crow::Request& req,
260995a3ecadSAnthony Wilson                const std::vector<std::string>& params) override
261095a3ecadSAnthony Wilson     {
261195a3ecadSAnthony Wilson         BMCWEB_LOG_DEBUG << "Sensor doGet enter";
261295a3ecadSAnthony Wilson         if (params.size() != 2)
261395a3ecadSAnthony Wilson         {
261495a3ecadSAnthony Wilson             BMCWEB_LOG_DEBUG << "Sensor doGet param size < 2";
261595a3ecadSAnthony Wilson             messages::internalError(res);
261695a3ecadSAnthony Wilson             res.end();
261795a3ecadSAnthony Wilson             return;
261895a3ecadSAnthony Wilson         }
261995a3ecadSAnthony Wilson         const std::string& chassisId = params[0];
262095a3ecadSAnthony Wilson         std::shared_ptr<SensorsAsyncResp> asyncResp =
262195a3ecadSAnthony Wilson             std::make_shared<SensorsAsyncResp>(
262295a3ecadSAnthony Wilson                 res, chassisId, std::vector<const char*>(), "Sensors");
262395a3ecadSAnthony Wilson 
262495a3ecadSAnthony Wilson         const std::string& sensorName = params[1];
262595a3ecadSAnthony Wilson         const std::array<const char*, 1> interfaces = {
262695a3ecadSAnthony Wilson             "xyz.openbmc_project.Sensor.Value"};
262795a3ecadSAnthony Wilson 
262895a3ecadSAnthony Wilson         // Get a list of all of the sensors that implement Sensor.Value
262995a3ecadSAnthony Wilson         // and get the path and service name associated with the sensor
263095a3ecadSAnthony Wilson         crow::connections::systemBus->async_method_call(
263195a3ecadSAnthony Wilson             [asyncResp, sensorName](const boost::system::error_code ec,
263295a3ecadSAnthony Wilson                                     const GetSubTreeType& subtree) {
263395a3ecadSAnthony Wilson                 BMCWEB_LOG_DEBUG << "respHandler1 enter";
263495a3ecadSAnthony Wilson                 if (ec)
263595a3ecadSAnthony Wilson                 {
263695a3ecadSAnthony Wilson                     messages::internalError(asyncResp->res);
263795a3ecadSAnthony Wilson                     BMCWEB_LOG_ERROR << "Sensor getSensorPaths resp_handler: "
263895a3ecadSAnthony Wilson                                      << "Dbus error " << ec;
263995a3ecadSAnthony Wilson                     return;
264095a3ecadSAnthony Wilson                 }
264195a3ecadSAnthony Wilson 
264295a3ecadSAnthony Wilson                 GetSubTreeType::const_iterator it = std::find_if(
264395a3ecadSAnthony Wilson                     subtree.begin(), subtree.end(),
264495a3ecadSAnthony Wilson                     [sensorName](
264595a3ecadSAnthony Wilson                         const std::pair<
264695a3ecadSAnthony Wilson                             std::string,
264795a3ecadSAnthony Wilson                             std::vector<std::pair<std::string,
264895a3ecadSAnthony Wilson                                                   std::vector<std::string>>>>&
264995a3ecadSAnthony Wilson                             object) {
265095a3ecadSAnthony Wilson                         std::string_view sensor = object.first;
265195a3ecadSAnthony Wilson                         std::size_t lastPos = sensor.rfind("/");
265295a3ecadSAnthony Wilson                         if (lastPos == std::string::npos ||
265395a3ecadSAnthony Wilson                             lastPos + 1 >= sensor.size())
265495a3ecadSAnthony Wilson                         {
265595a3ecadSAnthony Wilson                             BMCWEB_LOG_ERROR << "Invalid sensor path: "
265695a3ecadSAnthony Wilson                                              << sensor;
265795a3ecadSAnthony Wilson                             return false;
265895a3ecadSAnthony Wilson                         }
265995a3ecadSAnthony Wilson                         std::string_view name = sensor.substr(lastPos + 1);
266095a3ecadSAnthony Wilson 
266195a3ecadSAnthony Wilson                         return name == sensorName;
266295a3ecadSAnthony Wilson                     });
266395a3ecadSAnthony Wilson 
266495a3ecadSAnthony Wilson                 if (it == subtree.end())
266595a3ecadSAnthony Wilson                 {
266695a3ecadSAnthony Wilson                     BMCWEB_LOG_ERROR << "Could not find path for sensor: "
266795a3ecadSAnthony Wilson                                      << sensorName;
266895a3ecadSAnthony Wilson                     messages::resourceNotFound(asyncResp->res, "Sensor",
266995a3ecadSAnthony Wilson                                                sensorName);
267095a3ecadSAnthony Wilson                     return;
267195a3ecadSAnthony Wilson                 }
267295a3ecadSAnthony Wilson                 std::string_view sensorPath = (*it).first;
267395a3ecadSAnthony Wilson                 BMCWEB_LOG_DEBUG << "Found sensor path for sensor '"
267495a3ecadSAnthony Wilson                                  << sensorName << "': " << sensorPath;
267595a3ecadSAnthony Wilson 
267695a3ecadSAnthony Wilson                 const std::shared_ptr<boost::container::flat_set<std::string>>
267795a3ecadSAnthony Wilson                     sensorList = std::make_shared<
267895a3ecadSAnthony Wilson                         boost::container::flat_set<std::string>>();
267995a3ecadSAnthony Wilson 
268095a3ecadSAnthony Wilson                 sensorList->emplace(sensorPath);
268195a3ecadSAnthony Wilson                 processSensorList(asyncResp, sensorList);
268295a3ecadSAnthony Wilson                 BMCWEB_LOG_DEBUG << "respHandler1 exit";
268395a3ecadSAnthony Wilson             },
268495a3ecadSAnthony Wilson             "xyz.openbmc_project.ObjectMapper",
268595a3ecadSAnthony Wilson             "/xyz/openbmc_project/object_mapper",
268695a3ecadSAnthony Wilson             "xyz.openbmc_project.ObjectMapper", "GetSubTree",
268795a3ecadSAnthony Wilson             "/xyz/openbmc_project/sensors", 2, interfaces);
268895a3ecadSAnthony Wilson     }
268995a3ecadSAnthony Wilson };
269095a3ecadSAnthony Wilson 
269108777fb0SLewanczyk, Dawid } // namespace redfish
2692