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> 241abe55efSEd Tanous #include <dbus_singleton.hpp> 25413961deSRichard Marian Thomaiyar #include <utils/json_utils.hpp> 261214b7e7SGunnar Mills 271214b7e7SGunnar Mills #include <cmath> 28b5a76932SEd Tanous #include <utility> 29abf2add6SEd Tanous #include <variant> 3008777fb0SLewanczyk, Dawid 311abe55efSEd Tanous namespace redfish 321abe55efSEd Tanous { 3308777fb0SLewanczyk, Dawid 3408777fb0SLewanczyk, Dawid using GetSubTreeType = std::vector< 3508777fb0SLewanczyk, Dawid std::pair<std::string, 3608777fb0SLewanczyk, Dawid std::vector<std::pair<std::string, std::vector<std::string>>>>>; 3708777fb0SLewanczyk, Dawid 38adc4f0dbSShawn McCarney using SensorVariant = 39adc4f0dbSShawn McCarney std::variant<int64_t, double, uint32_t, bool, std::string>; 40aa2e59c1SEd Tanous 4108777fb0SLewanczyk, Dawid using ManagedObjectsVectorType = std::vector<std::pair< 42aa2e59c1SEd Tanous sdbusplus::message::object_path, 4308777fb0SLewanczyk, Dawid boost::container::flat_map< 44aa2e59c1SEd Tanous std::string, boost::container::flat_map<std::string, SensorVariant>>>>; 4508777fb0SLewanczyk, Dawid 46a0ec28b6SAdrian Ambrożewicz namespace sensors 47a0ec28b6SAdrian Ambrożewicz { 48a0ec28b6SAdrian Ambrożewicz namespace node 49a0ec28b6SAdrian Ambrożewicz { 50a0ec28b6SAdrian Ambrożewicz static constexpr std::string_view power = "Power"; 51a0ec28b6SAdrian Ambrożewicz static constexpr std::string_view sensors = "Sensors"; 52a0ec28b6SAdrian Ambrożewicz static constexpr std::string_view thermal = "Thermal"; 53a0ec28b6SAdrian Ambrożewicz } // namespace node 54a0ec28b6SAdrian Ambrożewicz 55a0ec28b6SAdrian Ambrożewicz namespace dbus 56a0ec28b6SAdrian Ambrożewicz { 57a0ec28b6SAdrian Ambrożewicz static const boost::container::flat_map<std::string_view, 58a0ec28b6SAdrian Ambrożewicz std::vector<const char*>> 59a0ec28b6SAdrian Ambrożewicz types = {{node::power, 60a0ec28b6SAdrian Ambrożewicz {"/xyz/openbmc_project/sensors/voltage", 61a0ec28b6SAdrian Ambrożewicz "/xyz/openbmc_project/sensors/power"}}, 62a0ec28b6SAdrian Ambrożewicz {node::sensors, 63a0ec28b6SAdrian Ambrożewicz {"/xyz/openbmc_project/sensors/power", 64a0ec28b6SAdrian Ambrożewicz "/xyz/openbmc_project/sensors/current", 65a0ec28b6SAdrian Ambrożewicz "/xyz/openbmc_project/sensors/utilization"}}, 66a0ec28b6SAdrian Ambrożewicz {node::thermal, 67a0ec28b6SAdrian Ambrożewicz {"/xyz/openbmc_project/sensors/fan_tach", 68a0ec28b6SAdrian Ambrożewicz "/xyz/openbmc_project/sensors/temperature", 69a0ec28b6SAdrian Ambrożewicz "/xyz/openbmc_project/sensors/fan_pwm"}}}; 70a0ec28b6SAdrian Ambrożewicz } 71a0ec28b6SAdrian Ambrożewicz } // namespace sensors 72a0ec28b6SAdrian Ambrożewicz 7308777fb0SLewanczyk, Dawid /** 74588c3f0dSKowalski, Kamil * SensorsAsyncResp 7508777fb0SLewanczyk, Dawid * Gathers data needed for response processing after async calls are done 7608777fb0SLewanczyk, Dawid */ 771abe55efSEd Tanous class SensorsAsyncResp 781abe55efSEd Tanous { 7908777fb0SLewanczyk, Dawid public: 80a0ec28b6SAdrian Ambrożewicz using DataCompleteCb = std::function<void( 81a0ec28b6SAdrian Ambrożewicz const boost::beast::http::status status, 82a0ec28b6SAdrian Ambrożewicz const boost::container::flat_map<std::string, std::string>& uriToDbus)>; 83a0ec28b6SAdrian Ambrożewicz 84a0ec28b6SAdrian Ambrożewicz struct SensorData 85a0ec28b6SAdrian Ambrożewicz { 86a0ec28b6SAdrian Ambrożewicz const std::string name; 87a0ec28b6SAdrian Ambrożewicz std::string uri; 88a0ec28b6SAdrian Ambrożewicz const std::string valueKey; 89a0ec28b6SAdrian Ambrożewicz const std::string dbusPath; 90a0ec28b6SAdrian Ambrożewicz }; 91a0ec28b6SAdrian Ambrożewicz 92271584abSEd Tanous SensorsAsyncResp(crow::Response& response, const std::string& chassisIdIn, 93b5a76932SEd Tanous const std::vector<const char*>& typesIn, 94a0ec28b6SAdrian Ambrożewicz const std::string_view& subNode) : 9543b761d0SEd Tanous res(response), 96271584abSEd Tanous chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode) 971214b7e7SGunnar Mills {} 9808777fb0SLewanczyk, Dawid 99a0ec28b6SAdrian Ambrożewicz // Store extra data about sensor mapping and return it in callback 100a0ec28b6SAdrian Ambrożewicz SensorsAsyncResp(crow::Response& response, const std::string& chassisIdIn, 101b5a76932SEd Tanous const std::vector<const char*>& typesIn, 102a0ec28b6SAdrian Ambrożewicz const std::string_view& subNode, 103a0ec28b6SAdrian Ambrożewicz DataCompleteCb&& creationComplete) : 104a0ec28b6SAdrian Ambrożewicz res(response), 105a0ec28b6SAdrian Ambrożewicz chassisId(chassisIdIn), types(typesIn), 106a0ec28b6SAdrian Ambrożewicz chassisSubNode(subNode), metadata{std::vector<SensorData>()}, 107a0ec28b6SAdrian Ambrożewicz dataComplete{std::move(creationComplete)} 108a0ec28b6SAdrian Ambrożewicz {} 109a0ec28b6SAdrian Ambrożewicz 1101abe55efSEd Tanous ~SensorsAsyncResp() 1111abe55efSEd Tanous { 1121abe55efSEd Tanous if (res.result() == boost::beast::http::status::internal_server_error) 1131abe55efSEd Tanous { 1141abe55efSEd Tanous // Reset the json object to clear out any data that made it in 1151abe55efSEd Tanous // before the error happened todo(ed) handle error condition with 1161abe55efSEd Tanous // proper code 11755c7b7a2SEd Tanous res.jsonValue = nlohmann::json::object(); 11808777fb0SLewanczyk, Dawid } 119a0ec28b6SAdrian Ambrożewicz 120a0ec28b6SAdrian Ambrożewicz if (dataComplete && metadata) 121a0ec28b6SAdrian Ambrożewicz { 122a0ec28b6SAdrian Ambrożewicz boost::container::flat_map<std::string, std::string> map; 123a0ec28b6SAdrian Ambrożewicz if (res.result() == boost::beast::http::status::ok) 124a0ec28b6SAdrian Ambrożewicz { 125a0ec28b6SAdrian Ambrożewicz for (auto& sensor : *metadata) 126a0ec28b6SAdrian Ambrożewicz { 127a0ec28b6SAdrian Ambrożewicz map.insert(std::make_pair(sensor.uri + sensor.valueKey, 128a0ec28b6SAdrian Ambrożewicz sensor.dbusPath)); 129a0ec28b6SAdrian Ambrożewicz } 130a0ec28b6SAdrian Ambrożewicz } 131a0ec28b6SAdrian Ambrożewicz dataComplete(res.result(), map); 132a0ec28b6SAdrian Ambrożewicz } 133a0ec28b6SAdrian Ambrożewicz 13408777fb0SLewanczyk, Dawid res.end(); 13508777fb0SLewanczyk, Dawid } 136588c3f0dSKowalski, Kamil 137a0ec28b6SAdrian Ambrożewicz void addMetadata(const nlohmann::json& sensorObject, 138a0ec28b6SAdrian Ambrożewicz const std::string& valueKey, const std::string& dbusPath) 139a0ec28b6SAdrian Ambrożewicz { 140a0ec28b6SAdrian Ambrożewicz if (metadata) 141a0ec28b6SAdrian Ambrożewicz { 142a0ec28b6SAdrian Ambrożewicz metadata->emplace_back(SensorData{sensorObject["Name"], 143a0ec28b6SAdrian Ambrożewicz sensorObject["@odata.id"], 144a0ec28b6SAdrian Ambrożewicz valueKey, dbusPath}); 145a0ec28b6SAdrian Ambrożewicz } 146a0ec28b6SAdrian Ambrożewicz } 147a0ec28b6SAdrian Ambrożewicz 148a0ec28b6SAdrian Ambrożewicz void updateUri(const std::string& name, const std::string& uri) 149a0ec28b6SAdrian Ambrożewicz { 150a0ec28b6SAdrian Ambrożewicz if (metadata) 151a0ec28b6SAdrian Ambrożewicz { 152a0ec28b6SAdrian Ambrożewicz for (auto& sensor : *metadata) 153a0ec28b6SAdrian Ambrożewicz { 154a0ec28b6SAdrian Ambrożewicz if (sensor.name == name) 155a0ec28b6SAdrian Ambrożewicz { 156a0ec28b6SAdrian Ambrożewicz sensor.uri = uri; 157a0ec28b6SAdrian Ambrożewicz } 158a0ec28b6SAdrian Ambrożewicz } 159a0ec28b6SAdrian Ambrożewicz } 160a0ec28b6SAdrian Ambrożewicz } 161a0ec28b6SAdrian Ambrożewicz 16255c7b7a2SEd Tanous crow::Response& res; 163a0ec28b6SAdrian Ambrożewicz const std::string chassisId; 16408777fb0SLewanczyk, Dawid const std::vector<const char*> types; 165a0ec28b6SAdrian Ambrożewicz const std::string chassisSubNode; 166a0ec28b6SAdrian Ambrożewicz 167a0ec28b6SAdrian Ambrożewicz private: 168a0ec28b6SAdrian Ambrożewicz std::optional<std::vector<SensorData>> metadata; 169a0ec28b6SAdrian Ambrożewicz DataCompleteCb dataComplete; 17008777fb0SLewanczyk, Dawid }; 17108777fb0SLewanczyk, Dawid 17208777fb0SLewanczyk, Dawid /** 173d500549bSAnthony Wilson * Possible states for physical inventory leds 174d500549bSAnthony Wilson */ 175d500549bSAnthony Wilson enum class LedState 176d500549bSAnthony Wilson { 177d500549bSAnthony Wilson OFF, 178d500549bSAnthony Wilson ON, 179d500549bSAnthony Wilson BLINK, 180d500549bSAnthony Wilson UNKNOWN 181d500549bSAnthony Wilson }; 182d500549bSAnthony Wilson 183d500549bSAnthony Wilson /** 184adc4f0dbSShawn McCarney * D-Bus inventory item associated with one or more sensors. 185adc4f0dbSShawn McCarney */ 186adc4f0dbSShawn McCarney class InventoryItem 187adc4f0dbSShawn McCarney { 188adc4f0dbSShawn McCarney public: 189adc4f0dbSShawn McCarney InventoryItem(const std::string& objPath) : 190adc4f0dbSShawn McCarney objectPath(objPath), name(), isPresent(true), isFunctional(true), 19142cbe538SGunnar Mills isPowerSupply(false), powerSupplyEfficiencyPercent(-1), manufacturer(), 19242cbe538SGunnar Mills model(), partNumber(), serialNumber(), sensors(), ledObjectPath(""), 193d500549bSAnthony Wilson ledState(LedState::UNKNOWN) 194adc4f0dbSShawn McCarney { 195adc4f0dbSShawn McCarney // Set inventory item name to last node of object path 19628aa8de5SGeorge Liu sdbusplus::message::object_path path(objectPath); 19728aa8de5SGeorge Liu name = path.filename(); 19828aa8de5SGeorge Liu if (name.empty()) 199adc4f0dbSShawn McCarney { 20028aa8de5SGeorge Liu BMCWEB_LOG_ERROR << "Failed to find '/' in " << objectPath; 201adc4f0dbSShawn McCarney } 202adc4f0dbSShawn McCarney } 203adc4f0dbSShawn McCarney 204adc4f0dbSShawn McCarney std::string objectPath; 205adc4f0dbSShawn McCarney std::string name; 206adc4f0dbSShawn McCarney bool isPresent; 207adc4f0dbSShawn McCarney bool isFunctional; 208adc4f0dbSShawn McCarney bool isPowerSupply; 20942cbe538SGunnar Mills int powerSupplyEfficiencyPercent; 210adc4f0dbSShawn McCarney std::string manufacturer; 211adc4f0dbSShawn McCarney std::string model; 212adc4f0dbSShawn McCarney std::string partNumber; 213adc4f0dbSShawn McCarney std::string serialNumber; 214adc4f0dbSShawn McCarney std::set<std::string> sensors; 215d500549bSAnthony Wilson std::string ledObjectPath; 216d500549bSAnthony Wilson LedState ledState; 217adc4f0dbSShawn McCarney }; 218adc4f0dbSShawn McCarney 219adc4f0dbSShawn McCarney /** 220413961deSRichard Marian Thomaiyar * @brief Get objects with connection necessary for sensors 221588c3f0dSKowalski, Kamil * @param SensorsAsyncResp Pointer to object holding response data 22208777fb0SLewanczyk, Dawid * @param sensorNames Sensors retrieved from chassis 22308777fb0SLewanczyk, Dawid * @param callback Callback for processing gathered connections 22408777fb0SLewanczyk, Dawid */ 22508777fb0SLewanczyk, Dawid template <typename Callback> 226413961deSRichard Marian Thomaiyar void getObjectsWithConnection( 22781ce609eSEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 228b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames, 2291abe55efSEd Tanous Callback&& callback) 2301abe55efSEd Tanous { 231413961deSRichard Marian Thomaiyar BMCWEB_LOG_DEBUG << "getObjectsWithConnection enter"; 23203b5bae3SJames Feist const std::string path = "/xyz/openbmc_project/sensors"; 23308777fb0SLewanczyk, Dawid const std::array<std::string, 1> interfaces = { 23408777fb0SLewanczyk, Dawid "xyz.openbmc_project.Sensor.Value"}; 23508777fb0SLewanczyk, Dawid 23608777fb0SLewanczyk, Dawid // Response handler for parsing objects subtree 23781ce609eSEd Tanous auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp, 2381abe55efSEd Tanous sensorNames](const boost::system::error_code ec, 2391abe55efSEd Tanous const GetSubTreeType& subtree) { 240413961deSRichard Marian Thomaiyar BMCWEB_LOG_DEBUG << "getObjectsWithConnection resp_handler enter"; 2411abe55efSEd Tanous if (ec) 2421abe55efSEd Tanous { 24381ce609eSEd Tanous messages::internalError(sensorsAsyncResp->res); 244413961deSRichard Marian Thomaiyar BMCWEB_LOG_ERROR 245413961deSRichard Marian Thomaiyar << "getObjectsWithConnection resp_handler: Dbus error " << ec; 24608777fb0SLewanczyk, Dawid return; 24708777fb0SLewanczyk, Dawid } 24808777fb0SLewanczyk, Dawid 24955c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Found " << subtree.size() << " subtrees"; 25008777fb0SLewanczyk, Dawid 25108777fb0SLewanczyk, Dawid // Make unique list of connections only for requested sensor types and 25208777fb0SLewanczyk, Dawid // found in the chassis 25308777fb0SLewanczyk, Dawid boost::container::flat_set<std::string> connections; 254413961deSRichard Marian Thomaiyar std::set<std::pair<std::string, std::string>> objectsWithConnection; 2551abe55efSEd Tanous // Intrinsic to avoid malloc. Most systems will have < 8 sensor 2561abe55efSEd Tanous // producers 25708777fb0SLewanczyk, Dawid connections.reserve(8); 25808777fb0SLewanczyk, Dawid 25949c53ac9SJohnathan Mantey BMCWEB_LOG_DEBUG << "sensorNames list count: " << sensorNames->size(); 26049c53ac9SJohnathan Mantey for (const std::string& tsensor : *sensorNames) 2611abe55efSEd Tanous { 26255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Sensor to find: " << tsensor; 26308777fb0SLewanczyk, Dawid } 26408777fb0SLewanczyk, Dawid 26508777fb0SLewanczyk, Dawid for (const std::pair< 26608777fb0SLewanczyk, Dawid std::string, 26708777fb0SLewanczyk, Dawid std::vector<std::pair<std::string, std::vector<std::string>>>>& 2681abe55efSEd Tanous object : subtree) 2691abe55efSEd Tanous { 27049c53ac9SJohnathan Mantey if (sensorNames->find(object.first) != sensorNames->end()) 2711abe55efSEd Tanous { 27249c53ac9SJohnathan Mantey for (const std::pair<std::string, std::vector<std::string>>& 2731abe55efSEd Tanous objData : object.second) 2741abe55efSEd Tanous { 27549c53ac9SJohnathan Mantey BMCWEB_LOG_DEBUG << "Adding connection: " << objData.first; 27608777fb0SLewanczyk, Dawid connections.insert(objData.first); 277de629b6eSShawn McCarney objectsWithConnection.insert( 278de629b6eSShawn McCarney std::make_pair(object.first, objData.first)); 27908777fb0SLewanczyk, Dawid } 28008777fb0SLewanczyk, Dawid } 28108777fb0SLewanczyk, Dawid } 28255c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Found " << connections.size() << " connections"; 283413961deSRichard Marian Thomaiyar callback(std::move(connections), std::move(objectsWithConnection)); 284413961deSRichard Marian Thomaiyar BMCWEB_LOG_DEBUG << "getObjectsWithConnection resp_handler exit"; 28508777fb0SLewanczyk, Dawid }; 28608777fb0SLewanczyk, Dawid // Make call to ObjectMapper to find all sensors objects 28755c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 28855c7b7a2SEd Tanous std::move(respHandler), "xyz.openbmc_project.ObjectMapper", 2891abe55efSEd Tanous "/xyz/openbmc_project/object_mapper", 2901abe55efSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 2, interfaces); 291413961deSRichard Marian Thomaiyar BMCWEB_LOG_DEBUG << "getObjectsWithConnection exit"; 292413961deSRichard Marian Thomaiyar } 293413961deSRichard Marian Thomaiyar 294413961deSRichard Marian Thomaiyar /** 295413961deSRichard Marian Thomaiyar * @brief Create connections necessary for sensors 296413961deSRichard Marian Thomaiyar * @param SensorsAsyncResp Pointer to object holding response data 297413961deSRichard Marian Thomaiyar * @param sensorNames Sensors retrieved from chassis 298413961deSRichard Marian Thomaiyar * @param callback Callback for processing gathered connections 299413961deSRichard Marian Thomaiyar */ 300413961deSRichard Marian Thomaiyar template <typename Callback> 30149c53ac9SJohnathan Mantey void getConnections( 30281ce609eSEd Tanous std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, 30349c53ac9SJohnathan Mantey const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames, 304413961deSRichard Marian Thomaiyar Callback&& callback) 305413961deSRichard Marian Thomaiyar { 306413961deSRichard Marian Thomaiyar auto objectsWithConnectionCb = 307413961deSRichard Marian Thomaiyar [callback](const boost::container::flat_set<std::string>& connections, 308413961deSRichard Marian Thomaiyar const std::set<std::pair<std::string, std::string>>& 3093174e4dfSEd Tanous /*objectsWithConnection*/) { callback(connections); }; 31081ce609eSEd Tanous getObjectsWithConnection(sensorsAsyncResp, sensorNames, 311413961deSRichard Marian Thomaiyar std::move(objectsWithConnectionCb)); 31208777fb0SLewanczyk, Dawid } 31308777fb0SLewanczyk, Dawid 31408777fb0SLewanczyk, Dawid /** 31549c53ac9SJohnathan Mantey * @brief Shrinks the list of sensors for processing 31649c53ac9SJohnathan Mantey * @param SensorsAysncResp The class holding the Redfish response 31749c53ac9SJohnathan Mantey * @param allSensors A list of all the sensors associated to the 31849c53ac9SJohnathan Mantey * chassis element (i.e. baseboard, front panel, etc...) 31949c53ac9SJohnathan Mantey * @param activeSensors A list that is a reduction of the incoming 32049c53ac9SJohnathan Mantey * allSensors list. Eliminate Thermal sensors when a Power request is 32149c53ac9SJohnathan Mantey * made, and eliminate Power sensors when a Thermal request is made. 32249c53ac9SJohnathan Mantey */ 32323a21a1cSEd Tanous inline void reduceSensorList( 32481ce609eSEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 32549c53ac9SJohnathan Mantey const std::vector<std::string>* allSensors, 326b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_set<std::string>>& 327b5a76932SEd Tanous activeSensors) 32849c53ac9SJohnathan Mantey { 32981ce609eSEd Tanous if (sensorsAsyncResp == nullptr) 33049c53ac9SJohnathan Mantey { 33149c53ac9SJohnathan Mantey return; 33249c53ac9SJohnathan Mantey } 33349c53ac9SJohnathan Mantey if ((allSensors == nullptr) || (activeSensors == nullptr)) 33449c53ac9SJohnathan Mantey { 33549c53ac9SJohnathan Mantey messages::resourceNotFound( 33681ce609eSEd Tanous sensorsAsyncResp->res, sensorsAsyncResp->chassisSubNode, 33781ce609eSEd Tanous sensorsAsyncResp->chassisSubNode == sensors::node::thermal 338a0ec28b6SAdrian Ambrożewicz ? "Temperatures" 33949c53ac9SJohnathan Mantey : "Voltages"); 34049c53ac9SJohnathan Mantey 34149c53ac9SJohnathan Mantey return; 34249c53ac9SJohnathan Mantey } 34349c53ac9SJohnathan Mantey if (allSensors->empty()) 34449c53ac9SJohnathan Mantey { 34549c53ac9SJohnathan Mantey // Nothing to do, the activeSensors object is also empty 34649c53ac9SJohnathan Mantey return; 34749c53ac9SJohnathan Mantey } 34849c53ac9SJohnathan Mantey 34981ce609eSEd Tanous for (const char* type : sensorsAsyncResp->types) 35049c53ac9SJohnathan Mantey { 35149c53ac9SJohnathan Mantey for (const std::string& sensor : *allSensors) 35249c53ac9SJohnathan Mantey { 35349c53ac9SJohnathan Mantey if (boost::starts_with(sensor, type)) 35449c53ac9SJohnathan Mantey { 35549c53ac9SJohnathan Mantey activeSensors->emplace(sensor); 35649c53ac9SJohnathan Mantey } 35749c53ac9SJohnathan Mantey } 35849c53ac9SJohnathan Mantey } 35949c53ac9SJohnathan Mantey } 36049c53ac9SJohnathan Mantey 36149c53ac9SJohnathan Mantey /** 3624bb3dc34SCarol Wang * @brief Retrieves valid chassis path 3634bb3dc34SCarol Wang * @param asyncResp Pointer to object holding response data 3644bb3dc34SCarol Wang * @param callback Callback for next step to get valid chassis path 3654bb3dc34SCarol Wang */ 3664bb3dc34SCarol Wang template <typename Callback> 367b5a76932SEd Tanous void getValidChassisPath(const std::shared_ptr<SensorsAsyncResp>& asyncResp, 3684bb3dc34SCarol Wang Callback&& callback) 3694bb3dc34SCarol Wang { 3704bb3dc34SCarol Wang BMCWEB_LOG_DEBUG << "checkChassisId enter"; 3714bb3dc34SCarol Wang const std::array<const char*, 2> interfaces = { 3724bb3dc34SCarol Wang "xyz.openbmc_project.Inventory.Item.Board", 3734bb3dc34SCarol Wang "xyz.openbmc_project.Inventory.Item.Chassis"}; 3744bb3dc34SCarol Wang 3754bb3dc34SCarol Wang auto respHandler = 3764bb3dc34SCarol Wang [callback{std::move(callback)}, 3774bb3dc34SCarol Wang asyncResp](const boost::system::error_code ec, 3784bb3dc34SCarol Wang const std::vector<std::string>& chassisPaths) mutable { 3794bb3dc34SCarol Wang BMCWEB_LOG_DEBUG << "getValidChassisPath respHandler enter"; 3804bb3dc34SCarol Wang if (ec) 3814bb3dc34SCarol Wang { 3824bb3dc34SCarol Wang BMCWEB_LOG_ERROR 3834bb3dc34SCarol Wang << "getValidChassisPath respHandler DBUS error: " << ec; 3844bb3dc34SCarol Wang messages::internalError(asyncResp->res); 3854bb3dc34SCarol Wang return; 3864bb3dc34SCarol Wang } 3874bb3dc34SCarol Wang 3884bb3dc34SCarol Wang std::optional<std::string> chassisPath; 3894bb3dc34SCarol Wang std::string chassisName; 3904bb3dc34SCarol Wang for (const std::string& chassis : chassisPaths) 3914bb3dc34SCarol Wang { 39228aa8de5SGeorge Liu sdbusplus::message::object_path path(chassis); 39328aa8de5SGeorge Liu chassisName = path.filename(); 39428aa8de5SGeorge Liu if (chassisName.empty()) 3954bb3dc34SCarol Wang { 3964bb3dc34SCarol Wang BMCWEB_LOG_ERROR << "Failed to find '/' in " << chassis; 3974bb3dc34SCarol Wang continue; 3984bb3dc34SCarol Wang } 3994bb3dc34SCarol Wang if (chassisName == asyncResp->chassisId) 4004bb3dc34SCarol Wang { 4014bb3dc34SCarol Wang chassisPath = chassis; 4024bb3dc34SCarol Wang break; 4034bb3dc34SCarol Wang } 4044bb3dc34SCarol Wang } 4054bb3dc34SCarol Wang callback(chassisPath); 4064bb3dc34SCarol Wang }; 4074bb3dc34SCarol Wang 4084bb3dc34SCarol Wang // Get the Chassis Collection 4094bb3dc34SCarol Wang crow::connections::systemBus->async_method_call( 4104bb3dc34SCarol Wang respHandler, "xyz.openbmc_project.ObjectMapper", 4114bb3dc34SCarol Wang "/xyz/openbmc_project/object_mapper", 4124bb3dc34SCarol Wang "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 4134bb3dc34SCarol Wang "/xyz/openbmc_project/inventory", 0, interfaces); 4144bb3dc34SCarol Wang BMCWEB_LOG_DEBUG << "checkChassisId exit"; 4154bb3dc34SCarol Wang } 4164bb3dc34SCarol Wang 4174bb3dc34SCarol Wang /** 41808777fb0SLewanczyk, Dawid * @brief Retrieves requested chassis sensors and redundancy data from DBus . 419588c3f0dSKowalski, Kamil * @param SensorsAsyncResp Pointer to object holding response data 42008777fb0SLewanczyk, Dawid * @param callback Callback for next step in gathered sensor processing 42108777fb0SLewanczyk, Dawid */ 42208777fb0SLewanczyk, Dawid template <typename Callback> 423b5a76932SEd Tanous void getChassis(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 4241abe55efSEd Tanous Callback&& callback) 4251abe55efSEd Tanous { 42655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "getChassis enter"; 427adc4f0dbSShawn McCarney const std::array<const char*, 2> interfaces = { 42849c53ac9SJohnathan Mantey "xyz.openbmc_project.Inventory.Item.Board", 429adc4f0dbSShawn McCarney "xyz.openbmc_project.Inventory.Item.Chassis"}; 43049c53ac9SJohnathan Mantey auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp]( 43149c53ac9SJohnathan Mantey const boost::system::error_code ec, 43249c53ac9SJohnathan Mantey const std::vector<std::string>& chassisPaths) { 43355c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "getChassis respHandler enter"; 4341abe55efSEd Tanous if (ec) 4351abe55efSEd Tanous { 43655c7b7a2SEd Tanous BMCWEB_LOG_ERROR << "getChassis respHandler DBUS error: " << ec; 43749c53ac9SJohnathan Mantey messages::internalError(sensorsAsyncResp->res); 43808777fb0SLewanczyk, Dawid return; 43908777fb0SLewanczyk, Dawid } 44008777fb0SLewanczyk, Dawid 44149c53ac9SJohnathan Mantey const std::string* chassisPath = nullptr; 44249c53ac9SJohnathan Mantey std::string chassisName; 44349c53ac9SJohnathan Mantey for (const std::string& chassis : chassisPaths) 4441abe55efSEd Tanous { 44528aa8de5SGeorge Liu sdbusplus::message::object_path path(chassis); 44628aa8de5SGeorge Liu chassisName = path.filename(); 44728aa8de5SGeorge Liu if (chassisName.empty()) 4481abe55efSEd Tanous { 44949c53ac9SJohnathan Mantey BMCWEB_LOG_ERROR << "Failed to find '/' in " << chassis; 450daf36e2eSEd Tanous continue; 451daf36e2eSEd Tanous } 45249c53ac9SJohnathan Mantey if (chassisName == sensorsAsyncResp->chassisId) 4531abe55efSEd Tanous { 45449c53ac9SJohnathan Mantey chassisPath = &chassis; 45549c53ac9SJohnathan Mantey break; 456daf36e2eSEd Tanous } 45749c53ac9SJohnathan Mantey } 45849c53ac9SJohnathan Mantey if (chassisPath == nullptr) 4591abe55efSEd Tanous { 46049c53ac9SJohnathan Mantey messages::resourceNotFound(sensorsAsyncResp->res, "Chassis", 46149c53ac9SJohnathan Mantey sensorsAsyncResp->chassisId); 46249c53ac9SJohnathan Mantey return; 4631abe55efSEd Tanous } 46408777fb0SLewanczyk, Dawid 46549c53ac9SJohnathan Mantey const std::string& chassisSubNode = sensorsAsyncResp->chassisSubNode; 466a0ec28b6SAdrian Ambrożewicz if (chassisSubNode == sensors::node::power) 46749c53ac9SJohnathan Mantey { 46849c53ac9SJohnathan Mantey sensorsAsyncResp->res.jsonValue["@odata.type"] = 46949c53ac9SJohnathan Mantey "#Power.v1_5_2.Power"; 47049c53ac9SJohnathan Mantey } 471a0ec28b6SAdrian Ambrożewicz else if (chassisSubNode == sensors::node::thermal) 47249c53ac9SJohnathan Mantey { 47349c53ac9SJohnathan Mantey sensorsAsyncResp->res.jsonValue["@odata.type"] = 47449c53ac9SJohnathan Mantey "#Thermal.v1_4_0.Thermal"; 4754f9a2130SJennifer Lee sensorsAsyncResp->res.jsonValue["Fans"] = nlohmann::json::array(); 4764f9a2130SJennifer Lee sensorsAsyncResp->res.jsonValue["Temperatures"] = 4774f9a2130SJennifer Lee nlohmann::json::array(); 47849c53ac9SJohnathan Mantey } 479a0ec28b6SAdrian Ambrożewicz else if (chassisSubNode == sensors::node::sensors) 48095a3ecadSAnthony Wilson { 48195a3ecadSAnthony Wilson sensorsAsyncResp->res.jsonValue["@odata.type"] = 48295a3ecadSAnthony Wilson "#SensorCollection.SensorCollection"; 48395a3ecadSAnthony Wilson sensorsAsyncResp->res.jsonValue["Description"] = 48495a3ecadSAnthony Wilson "Collection of Sensors for this Chassis"; 48595a3ecadSAnthony Wilson sensorsAsyncResp->res.jsonValue["Members"] = 48695a3ecadSAnthony Wilson nlohmann::json::array(); 48795a3ecadSAnthony Wilson sensorsAsyncResp->res.jsonValue["Members@odata.count"] = 0; 48895a3ecadSAnthony Wilson } 48995a3ecadSAnthony Wilson 490a0ec28b6SAdrian Ambrożewicz if (chassisSubNode != sensors::node::sensors) 49195a3ecadSAnthony Wilson { 49295a3ecadSAnthony Wilson sensorsAsyncResp->res.jsonValue["Id"] = chassisSubNode; 49395a3ecadSAnthony Wilson } 49495a3ecadSAnthony Wilson 49549c53ac9SJohnathan Mantey sensorsAsyncResp->res.jsonValue["@odata.id"] = 49649c53ac9SJohnathan Mantey "/redfish/v1/Chassis/" + sensorsAsyncResp->chassisId + "/" + 49749c53ac9SJohnathan Mantey chassisSubNode; 49849c53ac9SJohnathan Mantey sensorsAsyncResp->res.jsonValue["Name"] = chassisSubNode; 49949c53ac9SJohnathan Mantey 5008fb49dd6SShawn McCarney // Get the list of all sensors for this Chassis element 5018fb49dd6SShawn McCarney std::string sensorPath = *chassisPath + "/all_sensors"; 50255c7b7a2SEd Tanous crow::connections::systemBus->async_method_call( 50349c53ac9SJohnathan Mantey [sensorsAsyncResp, callback{std::move(callback)}]( 504271584abSEd Tanous const boost::system::error_code& e, 50549c53ac9SJohnathan Mantey const std::variant<std::vector<std::string>>& 50649c53ac9SJohnathan Mantey variantEndpoints) { 507271584abSEd Tanous if (e) 50849c53ac9SJohnathan Mantey { 509271584abSEd Tanous if (e.value() != EBADR) 51049c53ac9SJohnathan Mantey { 51149c53ac9SJohnathan Mantey messages::internalError(sensorsAsyncResp->res); 51249c53ac9SJohnathan Mantey return; 51349c53ac9SJohnathan Mantey } 51449c53ac9SJohnathan Mantey } 51549c53ac9SJohnathan Mantey const std::vector<std::string>* nodeSensorList = 51649c53ac9SJohnathan Mantey std::get_if<std::vector<std::string>>(&(variantEndpoints)); 51749c53ac9SJohnathan Mantey if (nodeSensorList == nullptr) 51849c53ac9SJohnathan Mantey { 51949c53ac9SJohnathan Mantey messages::resourceNotFound( 52049c53ac9SJohnathan Mantey sensorsAsyncResp->res, sensorsAsyncResp->chassisSubNode, 521a0ec28b6SAdrian Ambrożewicz sensorsAsyncResp->chassisSubNode == 522a0ec28b6SAdrian Ambrożewicz sensors::node::thermal 52349c53ac9SJohnathan Mantey ? "Temperatures" 524a0ec28b6SAdrian Ambrożewicz : sensorsAsyncResp->chassisSubNode == 525a0ec28b6SAdrian Ambrożewicz sensors::node::power 52695a3ecadSAnthony Wilson ? "Voltages" 52795a3ecadSAnthony Wilson : "Sensors"); 52849c53ac9SJohnathan Mantey return; 52949c53ac9SJohnathan Mantey } 53049c53ac9SJohnathan Mantey const std::shared_ptr<boost::container::flat_set<std::string>> 53149c53ac9SJohnathan Mantey culledSensorList = std::make_shared< 53249c53ac9SJohnathan Mantey boost::container::flat_set<std::string>>(); 53349c53ac9SJohnathan Mantey reduceSensorList(sensorsAsyncResp, nodeSensorList, 53449c53ac9SJohnathan Mantey culledSensorList); 53549c53ac9SJohnathan Mantey callback(culledSensorList); 53649c53ac9SJohnathan Mantey }, 53749c53ac9SJohnathan Mantey "xyz.openbmc_project.ObjectMapper", sensorPath, 53849c53ac9SJohnathan Mantey "org.freedesktop.DBus.Properties", "Get", 53949c53ac9SJohnathan Mantey "xyz.openbmc_project.Association", "endpoints"); 54049c53ac9SJohnathan Mantey }; 54149c53ac9SJohnathan Mantey 54249c53ac9SJohnathan Mantey // Get the Chassis Collection 54349c53ac9SJohnathan Mantey crow::connections::systemBus->async_method_call( 54449c53ac9SJohnathan Mantey respHandler, "xyz.openbmc_project.ObjectMapper", 54549c53ac9SJohnathan Mantey "/xyz/openbmc_project/object_mapper", 54649c53ac9SJohnathan Mantey "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 547271584abSEd Tanous "/xyz/openbmc_project/inventory", 0, interfaces); 54855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "getChassis exit"; 54908777fb0SLewanczyk, Dawid } 55008777fb0SLewanczyk, Dawid 55108777fb0SLewanczyk, Dawid /** 552de629b6eSShawn McCarney * @brief Finds all DBus object paths that implement ObjectManager. 553de629b6eSShawn McCarney * 554de629b6eSShawn McCarney * Creates a mapping from the associated connection name to the object path. 555de629b6eSShawn McCarney * 556de629b6eSShawn McCarney * Finds the object paths asynchronously. Invokes callback when information has 557de629b6eSShawn McCarney * been obtained. 558de629b6eSShawn McCarney * 559de629b6eSShawn McCarney * The callback must have the following signature: 560de629b6eSShawn McCarney * @code 5618fb49dd6SShawn McCarney * callback(std::shared_ptr<boost::container::flat_map<std::string, 5628fb49dd6SShawn McCarney * std::string>> objectMgrPaths) 563de629b6eSShawn McCarney * @endcode 564de629b6eSShawn McCarney * 56549c53ac9SJohnathan Mantey * @param sensorsAsyncResp Pointer to object holding response data. 566de629b6eSShawn McCarney * @param callback Callback to invoke when object paths obtained. 567de629b6eSShawn McCarney */ 568de629b6eSShawn McCarney template <typename Callback> 569b5a76932SEd Tanous void getObjectManagerPaths( 57081ce609eSEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 571de629b6eSShawn McCarney Callback&& callback) 572de629b6eSShawn McCarney { 573de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getObjectManagerPaths enter"; 574de629b6eSShawn McCarney const std::array<std::string, 1> interfaces = { 575de629b6eSShawn McCarney "org.freedesktop.DBus.ObjectManager"}; 576de629b6eSShawn McCarney 577de629b6eSShawn McCarney // Response handler for GetSubTree DBus method 578de629b6eSShawn McCarney auto respHandler = [callback{std::move(callback)}, 57981ce609eSEd Tanous sensorsAsyncResp](const boost::system::error_code ec, 580de629b6eSShawn McCarney const GetSubTreeType& subtree) { 581de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler enter"; 582de629b6eSShawn McCarney if (ec) 583de629b6eSShawn McCarney { 58481ce609eSEd Tanous messages::internalError(sensorsAsyncResp->res); 585de629b6eSShawn McCarney BMCWEB_LOG_ERROR << "getObjectManagerPaths respHandler: DBus error " 586de629b6eSShawn McCarney << ec; 587de629b6eSShawn McCarney return; 588de629b6eSShawn McCarney } 589de629b6eSShawn McCarney 590de629b6eSShawn McCarney // Loop over returned object paths 5918fb49dd6SShawn McCarney std::shared_ptr<boost::container::flat_map<std::string, std::string>> 5928fb49dd6SShawn McCarney objectMgrPaths = std::make_shared< 5938fb49dd6SShawn McCarney boost::container::flat_map<std::string, std::string>>(); 594de629b6eSShawn McCarney for (const std::pair< 595de629b6eSShawn McCarney std::string, 596de629b6eSShawn McCarney std::vector<std::pair<std::string, std::vector<std::string>>>>& 597de629b6eSShawn McCarney object : subtree) 598de629b6eSShawn McCarney { 599de629b6eSShawn McCarney // Loop over connections for current object path 600de629b6eSShawn McCarney const std::string& objectPath = object.first; 601de629b6eSShawn McCarney for (const std::pair<std::string, std::vector<std::string>>& 602de629b6eSShawn McCarney objData : object.second) 603de629b6eSShawn McCarney { 604de629b6eSShawn McCarney // Add mapping from connection to object path 605de629b6eSShawn McCarney const std::string& connection = objData.first; 6068fb49dd6SShawn McCarney (*objectMgrPaths)[connection] = objectPath; 607de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "Added mapping " << connection << " -> " 608de629b6eSShawn McCarney << objectPath; 609de629b6eSShawn McCarney } 610de629b6eSShawn McCarney } 6118fb49dd6SShawn McCarney callback(objectMgrPaths); 612de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler exit"; 613de629b6eSShawn McCarney }; 614de629b6eSShawn McCarney 615de629b6eSShawn McCarney // Query mapper for all DBus object paths that implement ObjectManager 616de629b6eSShawn McCarney crow::connections::systemBus->async_method_call( 617de629b6eSShawn McCarney std::move(respHandler), "xyz.openbmc_project.ObjectMapper", 618de629b6eSShawn McCarney "/xyz/openbmc_project/object_mapper", 619271584abSEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, interfaces); 620de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getObjectManagerPaths exit"; 621de629b6eSShawn McCarney } 622de629b6eSShawn McCarney 623de629b6eSShawn McCarney /** 624adc4f0dbSShawn McCarney * @brief Returns the Redfish State value for the specified inventory item. 625adc4f0dbSShawn McCarney * @param inventoryItem D-Bus inventory item associated with a sensor. 626adc4f0dbSShawn McCarney * @return State value for inventory item. 62734dd179eSJames Feist */ 62823a21a1cSEd Tanous inline std::string getState(const InventoryItem* inventoryItem) 629adc4f0dbSShawn McCarney { 630adc4f0dbSShawn McCarney if ((inventoryItem != nullptr) && !(inventoryItem->isPresent)) 631adc4f0dbSShawn McCarney { 632adc4f0dbSShawn McCarney return "Absent"; 633adc4f0dbSShawn McCarney } 63434dd179eSJames Feist 635adc4f0dbSShawn McCarney return "Enabled"; 636adc4f0dbSShawn McCarney } 637adc4f0dbSShawn McCarney 638adc4f0dbSShawn McCarney /** 639adc4f0dbSShawn McCarney * @brief Returns the Redfish Health value for the specified sensor. 640adc4f0dbSShawn McCarney * @param sensorJson Sensor JSON object. 641adc4f0dbSShawn McCarney * @param interfacesDict Map of all sensor interfaces. 642adc4f0dbSShawn McCarney * @param inventoryItem D-Bus inventory item associated with the sensor. Will 643adc4f0dbSShawn McCarney * be nullptr if no associated inventory item was found. 644adc4f0dbSShawn McCarney * @return Health value for sensor. 645adc4f0dbSShawn McCarney */ 64623a21a1cSEd Tanous inline std::string getHealth( 647adc4f0dbSShawn McCarney nlohmann::json& sensorJson, 64834dd179eSJames Feist const boost::container::flat_map< 64934dd179eSJames Feist std::string, boost::container::flat_map<std::string, SensorVariant>>& 650adc4f0dbSShawn McCarney interfacesDict, 651adc4f0dbSShawn McCarney const InventoryItem* inventoryItem) 65234dd179eSJames Feist { 653adc4f0dbSShawn McCarney // Get current health value (if any) in the sensor JSON object. Some JSON 654adc4f0dbSShawn McCarney // objects contain multiple sensors (such as PowerSupplies). We want to set 655adc4f0dbSShawn McCarney // the overall health to be the most severe of any of the sensors. 656adc4f0dbSShawn McCarney std::string currentHealth; 657adc4f0dbSShawn McCarney auto statusIt = sensorJson.find("Status"); 658adc4f0dbSShawn McCarney if (statusIt != sensorJson.end()) 659adc4f0dbSShawn McCarney { 660adc4f0dbSShawn McCarney auto healthIt = statusIt->find("Health"); 661adc4f0dbSShawn McCarney if (healthIt != statusIt->end()) 662adc4f0dbSShawn McCarney { 663adc4f0dbSShawn McCarney std::string* health = healthIt->get_ptr<std::string*>(); 664adc4f0dbSShawn McCarney if (health != nullptr) 665adc4f0dbSShawn McCarney { 666adc4f0dbSShawn McCarney currentHealth = *health; 667adc4f0dbSShawn McCarney } 668adc4f0dbSShawn McCarney } 669adc4f0dbSShawn McCarney } 670adc4f0dbSShawn McCarney 671adc4f0dbSShawn McCarney // If current health in JSON object is already Critical, return that. This 672adc4f0dbSShawn McCarney // should override the sensor health, which might be less severe. 673adc4f0dbSShawn McCarney if (currentHealth == "Critical") 674adc4f0dbSShawn McCarney { 675adc4f0dbSShawn McCarney return "Critical"; 676adc4f0dbSShawn McCarney } 677adc4f0dbSShawn McCarney 678adc4f0dbSShawn McCarney // Check if sensor has critical threshold alarm 67934dd179eSJames Feist auto criticalThresholdIt = 68034dd179eSJames Feist interfacesDict.find("xyz.openbmc_project.Sensor.Threshold.Critical"); 68134dd179eSJames Feist if (criticalThresholdIt != interfacesDict.end()) 68234dd179eSJames Feist { 68334dd179eSJames Feist auto thresholdHighIt = 68434dd179eSJames Feist criticalThresholdIt->second.find("CriticalAlarmHigh"); 68534dd179eSJames Feist auto thresholdLowIt = 68634dd179eSJames Feist criticalThresholdIt->second.find("CriticalAlarmLow"); 68734dd179eSJames Feist if (thresholdHighIt != criticalThresholdIt->second.end()) 68834dd179eSJames Feist { 68934dd179eSJames Feist const bool* asserted = std::get_if<bool>(&thresholdHighIt->second); 69034dd179eSJames Feist if (asserted == nullptr) 69134dd179eSJames Feist { 69234dd179eSJames Feist BMCWEB_LOG_ERROR << "Illegal sensor threshold"; 69334dd179eSJames Feist } 69434dd179eSJames Feist else if (*asserted) 69534dd179eSJames Feist { 69634dd179eSJames Feist return "Critical"; 69734dd179eSJames Feist } 69834dd179eSJames Feist } 69934dd179eSJames Feist if (thresholdLowIt != criticalThresholdIt->second.end()) 70034dd179eSJames Feist { 70134dd179eSJames Feist const bool* asserted = std::get_if<bool>(&thresholdLowIt->second); 70234dd179eSJames Feist if (asserted == nullptr) 70334dd179eSJames Feist { 70434dd179eSJames Feist BMCWEB_LOG_ERROR << "Illegal sensor threshold"; 70534dd179eSJames Feist } 70634dd179eSJames Feist else if (*asserted) 70734dd179eSJames Feist { 70834dd179eSJames Feist return "Critical"; 70934dd179eSJames Feist } 71034dd179eSJames Feist } 71134dd179eSJames Feist } 71234dd179eSJames Feist 713adc4f0dbSShawn McCarney // Check if associated inventory item is not functional 714adc4f0dbSShawn McCarney if ((inventoryItem != nullptr) && !(inventoryItem->isFunctional)) 715adc4f0dbSShawn McCarney { 716adc4f0dbSShawn McCarney return "Critical"; 717adc4f0dbSShawn McCarney } 718adc4f0dbSShawn McCarney 719adc4f0dbSShawn McCarney // If current health in JSON object is already Warning, return that. This 720adc4f0dbSShawn McCarney // should override the sensor status, which might be less severe. 721adc4f0dbSShawn McCarney if (currentHealth == "Warning") 722adc4f0dbSShawn McCarney { 723adc4f0dbSShawn McCarney return "Warning"; 724adc4f0dbSShawn McCarney } 725adc4f0dbSShawn McCarney 726adc4f0dbSShawn McCarney // Check if sensor has warning threshold alarm 72734dd179eSJames Feist auto warningThresholdIt = 72834dd179eSJames Feist interfacesDict.find("xyz.openbmc_project.Sensor.Threshold.Warning"); 72934dd179eSJames Feist if (warningThresholdIt != interfacesDict.end()) 73034dd179eSJames Feist { 73134dd179eSJames Feist auto thresholdHighIt = 73234dd179eSJames Feist warningThresholdIt->second.find("WarningAlarmHigh"); 73334dd179eSJames Feist auto thresholdLowIt = 73434dd179eSJames Feist warningThresholdIt->second.find("WarningAlarmLow"); 73534dd179eSJames Feist if (thresholdHighIt != warningThresholdIt->second.end()) 73634dd179eSJames Feist { 73734dd179eSJames Feist const bool* asserted = std::get_if<bool>(&thresholdHighIt->second); 73834dd179eSJames Feist if (asserted == nullptr) 73934dd179eSJames Feist { 74034dd179eSJames Feist BMCWEB_LOG_ERROR << "Illegal sensor threshold"; 74134dd179eSJames Feist } 74234dd179eSJames Feist else if (*asserted) 74334dd179eSJames Feist { 74434dd179eSJames Feist return "Warning"; 74534dd179eSJames Feist } 74634dd179eSJames Feist } 74734dd179eSJames Feist if (thresholdLowIt != warningThresholdIt->second.end()) 74834dd179eSJames Feist { 74934dd179eSJames Feist const bool* asserted = std::get_if<bool>(&thresholdLowIt->second); 75034dd179eSJames Feist if (asserted == nullptr) 75134dd179eSJames Feist { 75234dd179eSJames Feist BMCWEB_LOG_ERROR << "Illegal sensor threshold"; 75334dd179eSJames Feist } 75434dd179eSJames Feist else if (*asserted) 75534dd179eSJames Feist { 75634dd179eSJames Feist return "Warning"; 75734dd179eSJames Feist } 75834dd179eSJames Feist } 75934dd179eSJames Feist } 760adc4f0dbSShawn McCarney 76134dd179eSJames Feist return "OK"; 76234dd179eSJames Feist } 76334dd179eSJames Feist 76423a21a1cSEd Tanous inline void setLedState(nlohmann::json& sensorJson, 765d500549bSAnthony Wilson const InventoryItem* inventoryItem) 766d500549bSAnthony Wilson { 767d500549bSAnthony Wilson if (inventoryItem != nullptr && !inventoryItem->ledObjectPath.empty()) 768d500549bSAnthony Wilson { 769d500549bSAnthony Wilson switch (inventoryItem->ledState) 770d500549bSAnthony Wilson { 771d500549bSAnthony Wilson case LedState::OFF: 772d500549bSAnthony Wilson sensorJson["IndicatorLED"] = "Off"; 773d500549bSAnthony Wilson break; 774d500549bSAnthony Wilson case LedState::ON: 775d500549bSAnthony Wilson sensorJson["IndicatorLED"] = "Lit"; 776d500549bSAnthony Wilson break; 777d500549bSAnthony Wilson case LedState::BLINK: 778d500549bSAnthony Wilson sensorJson["IndicatorLED"] = "Blinking"; 779d500549bSAnthony Wilson break; 78023a21a1cSEd Tanous case LedState::UNKNOWN: 781d500549bSAnthony Wilson break; 782d500549bSAnthony Wilson } 783d500549bSAnthony Wilson } 784d500549bSAnthony Wilson } 785d500549bSAnthony Wilson 78634dd179eSJames Feist /** 78708777fb0SLewanczyk, Dawid * @brief Builds a json sensor representation of a sensor. 78808777fb0SLewanczyk, Dawid * @param sensorName The name of the sensor to be built 789274fad5aSGunnar Mills * @param sensorType The type (temperature, fan_tach, etc) of the sensor to 79008777fb0SLewanczyk, Dawid * build 791a0ec28b6SAdrian Ambrożewicz * @param sensorsAsyncResp Sensor metadata 79208777fb0SLewanczyk, Dawid * @param interfacesDict A dictionary of the interfaces and properties of said 79308777fb0SLewanczyk, Dawid * interfaces to be built from 79408777fb0SLewanczyk, Dawid * @param sensor_json The json object to fill 795adc4f0dbSShawn McCarney * @param inventoryItem D-Bus inventory item associated with the sensor. Will 796adc4f0dbSShawn McCarney * be nullptr if no associated inventory item was found. 79708777fb0SLewanczyk, Dawid */ 79823a21a1cSEd Tanous inline void objectInterfacesToJson( 79908777fb0SLewanczyk, Dawid const std::string& sensorName, const std::string& sensorType, 800b5a76932SEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 80108777fb0SLewanczyk, Dawid const boost::container::flat_map< 802aa2e59c1SEd Tanous std::string, boost::container::flat_map<std::string, SensorVariant>>& 80308777fb0SLewanczyk, Dawid interfacesDict, 80481ce609eSEd Tanous nlohmann::json& sensorJson, InventoryItem* inventoryItem) 8051abe55efSEd Tanous { 80608777fb0SLewanczyk, Dawid // We need a value interface before we can do anything with it 80755c7b7a2SEd Tanous auto valueIt = interfacesDict.find("xyz.openbmc_project.Sensor.Value"); 8081abe55efSEd Tanous if (valueIt == interfacesDict.end()) 8091abe55efSEd Tanous { 81055c7b7a2SEd Tanous BMCWEB_LOG_ERROR << "Sensor doesn't have a value interface"; 81108777fb0SLewanczyk, Dawid return; 81208777fb0SLewanczyk, Dawid } 81308777fb0SLewanczyk, Dawid 81408777fb0SLewanczyk, Dawid // Assume values exist as is (10^0 == 1) if no scale exists 81508777fb0SLewanczyk, Dawid int64_t scaleMultiplier = 0; 81608777fb0SLewanczyk, Dawid 81755c7b7a2SEd Tanous auto scaleIt = valueIt->second.find("Scale"); 81808777fb0SLewanczyk, Dawid // If a scale exists, pull value as int64, and use the scaling. 8191abe55efSEd Tanous if (scaleIt != valueIt->second.end()) 8201abe55efSEd Tanous { 821abf2add6SEd Tanous const int64_t* int64Value = std::get_if<int64_t>(&scaleIt->second); 8221abe55efSEd Tanous if (int64Value != nullptr) 8231abe55efSEd Tanous { 82408777fb0SLewanczyk, Dawid scaleMultiplier = *int64Value; 82508777fb0SLewanczyk, Dawid } 82608777fb0SLewanczyk, Dawid } 82708777fb0SLewanczyk, Dawid 828a0ec28b6SAdrian Ambrożewicz if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) 829adc4f0dbSShawn McCarney { 83095a3ecadSAnthony Wilson // For sensors in SensorCollection we set Id instead of MemberId, 83195a3ecadSAnthony Wilson // including power sensors. 83281ce609eSEd Tanous sensorJson["Id"] = sensorName; 83381ce609eSEd Tanous sensorJson["Name"] = boost::replace_all_copy(sensorName, "_", " "); 83495a3ecadSAnthony Wilson } 83595a3ecadSAnthony Wilson else if (sensorType != "power") 83695a3ecadSAnthony Wilson { 83795a3ecadSAnthony Wilson // Set MemberId and Name for non-power sensors. For PowerSupplies and 83895a3ecadSAnthony Wilson // PowerControl, those properties have more general values because 83995a3ecadSAnthony Wilson // multiple sensors can be stored in the same JSON object. 84081ce609eSEd Tanous sensorJson["MemberId"] = sensorName; 84181ce609eSEd Tanous sensorJson["Name"] = boost::replace_all_copy(sensorName, "_", " "); 842adc4f0dbSShawn McCarney } 843e742b6ccSEd Tanous 84481ce609eSEd Tanous sensorJson["Status"]["State"] = getState(inventoryItem); 84581ce609eSEd Tanous sensorJson["Status"]["Health"] = 84681ce609eSEd Tanous getHealth(sensorJson, interfacesDict, inventoryItem); 84708777fb0SLewanczyk, Dawid 84808777fb0SLewanczyk, Dawid // Parameter to set to override the type we get from dbus, and force it to 84908777fb0SLewanczyk, Dawid // int, regardless of what is available. This is used for schemas like fan, 85008777fb0SLewanczyk, Dawid // that require integers, not floats. 85108777fb0SLewanczyk, Dawid bool forceToInt = false; 85208777fb0SLewanczyk, Dawid 8533929aca1SAnthony Wilson nlohmann::json::json_pointer unit("/Reading"); 854a0ec28b6SAdrian Ambrożewicz if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) 85595a3ecadSAnthony Wilson { 85681ce609eSEd Tanous sensorJson["@odata.type"] = "#Sensor.v1_0_0.Sensor"; 85795a3ecadSAnthony Wilson if (sensorType == "power") 85895a3ecadSAnthony Wilson { 85981ce609eSEd Tanous sensorJson["ReadingUnits"] = "Watts"; 86095a3ecadSAnthony Wilson } 86195a3ecadSAnthony Wilson else if (sensorType == "current") 86295a3ecadSAnthony Wilson { 86381ce609eSEd Tanous sensorJson["ReadingUnits"] = "Amperes"; 86495a3ecadSAnthony Wilson } 865f8ede15eSAdrian Ambrożewicz else if (sensorType == "utilization") 866f8ede15eSAdrian Ambrożewicz { 86781ce609eSEd Tanous sensorJson["ReadingUnits"] = "Percent"; 868f8ede15eSAdrian Ambrożewicz } 86995a3ecadSAnthony Wilson } 87095a3ecadSAnthony Wilson else if (sensorType == "temperature") 8711abe55efSEd Tanous { 8723929aca1SAnthony Wilson unit = "/ReadingCelsius"_json_pointer; 87381ce609eSEd Tanous sensorJson["@odata.type"] = "#Thermal.v1_3_0.Temperature"; 87408777fb0SLewanczyk, Dawid // TODO(ed) Documentation says that path should be type fan_tach, 87508777fb0SLewanczyk, Dawid // implementation seems to implement fan 8761abe55efSEd Tanous } 8771abe55efSEd Tanous else if (sensorType == "fan" || sensorType == "fan_tach") 8781abe55efSEd Tanous { 8793929aca1SAnthony Wilson unit = "/Reading"_json_pointer; 88081ce609eSEd Tanous sensorJson["ReadingUnits"] = "RPM"; 88181ce609eSEd Tanous sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan"; 88281ce609eSEd Tanous setLedState(sensorJson, inventoryItem); 88308777fb0SLewanczyk, Dawid forceToInt = true; 8841abe55efSEd Tanous } 8856f6d0d32SEd Tanous else if (sensorType == "fan_pwm") 8866f6d0d32SEd Tanous { 8873929aca1SAnthony Wilson unit = "/Reading"_json_pointer; 88881ce609eSEd Tanous sensorJson["ReadingUnits"] = "Percent"; 88981ce609eSEd Tanous sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan"; 89081ce609eSEd Tanous setLedState(sensorJson, inventoryItem); 8916f6d0d32SEd Tanous forceToInt = true; 8926f6d0d32SEd Tanous } 8931abe55efSEd Tanous else if (sensorType == "voltage") 8941abe55efSEd Tanous { 8953929aca1SAnthony Wilson unit = "/ReadingVolts"_json_pointer; 89681ce609eSEd Tanous sensorJson["@odata.type"] = "#Power.v1_0_0.Voltage"; 8971abe55efSEd Tanous } 8982474adfaSEd Tanous else if (sensorType == "power") 8992474adfaSEd Tanous { 90049c53ac9SJohnathan Mantey std::string sensorNameLower = 90149c53ac9SJohnathan Mantey boost::algorithm::to_lower_copy(sensorName); 90249c53ac9SJohnathan Mantey 903028f7ebcSEddie James if (!sensorName.compare("total_power")) 904028f7ebcSEddie James { 90581ce609eSEd Tanous sensorJson["@odata.type"] = "#Power.v1_0_0.PowerControl"; 9067ab06f49SGunnar Mills // Put multiple "sensors" into a single PowerControl, so have 9077ab06f49SGunnar Mills // generic names for MemberId and Name. Follows Redfish mockup. 90881ce609eSEd Tanous sensorJson["MemberId"] = "0"; 90981ce609eSEd Tanous sensorJson["Name"] = "Chassis Power Control"; 9103929aca1SAnthony Wilson unit = "/PowerConsumedWatts"_json_pointer; 911028f7ebcSEddie James } 912028f7ebcSEddie James else if (sensorNameLower.find("input") != std::string::npos) 91349c53ac9SJohnathan Mantey { 9143929aca1SAnthony Wilson unit = "/PowerInputWatts"_json_pointer; 91549c53ac9SJohnathan Mantey } 91649c53ac9SJohnathan Mantey else 91749c53ac9SJohnathan Mantey { 9183929aca1SAnthony Wilson unit = "/PowerOutputWatts"_json_pointer; 91949c53ac9SJohnathan Mantey } 9202474adfaSEd Tanous } 9211abe55efSEd Tanous else 9221abe55efSEd Tanous { 92355c7b7a2SEd Tanous BMCWEB_LOG_ERROR << "Redfish cannot map object type for " << sensorName; 92408777fb0SLewanczyk, Dawid return; 92508777fb0SLewanczyk, Dawid } 92608777fb0SLewanczyk, Dawid // Map of dbus interface name, dbus property name and redfish property_name 9273929aca1SAnthony Wilson std::vector< 9283929aca1SAnthony Wilson std::tuple<const char*, const char*, nlohmann::json::json_pointer>> 9293929aca1SAnthony Wilson properties; 93008777fb0SLewanczyk, Dawid properties.reserve(7); 93108777fb0SLewanczyk, Dawid 93208777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Value", "Value", unit); 933de629b6eSShawn McCarney 934a0ec28b6SAdrian Ambrożewicz if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) 9353929aca1SAnthony Wilson { 9363929aca1SAnthony Wilson properties.emplace_back( 9373929aca1SAnthony Wilson "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningHigh", 9383929aca1SAnthony Wilson "/Thresholds/UpperCaution/Reading"_json_pointer); 9393929aca1SAnthony Wilson properties.emplace_back( 9403929aca1SAnthony Wilson "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningLow", 9413929aca1SAnthony Wilson "/Thresholds/LowerCaution/Reading"_json_pointer); 9423929aca1SAnthony Wilson properties.emplace_back( 9433929aca1SAnthony Wilson "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalHigh", 9443929aca1SAnthony Wilson "/Thresholds/UpperCritical/Reading"_json_pointer); 9453929aca1SAnthony Wilson properties.emplace_back( 9463929aca1SAnthony Wilson "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalLow", 9473929aca1SAnthony Wilson "/Thresholds/LowerCritical/Reading"_json_pointer); 9483929aca1SAnthony Wilson } 9493929aca1SAnthony Wilson else if (sensorType != "power") 950de629b6eSShawn McCarney { 95108777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning", 9523929aca1SAnthony Wilson "WarningHigh", 9533929aca1SAnthony Wilson "/UpperThresholdNonCritical"_json_pointer); 95408777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning", 9553929aca1SAnthony Wilson "WarningLow", 9563929aca1SAnthony Wilson "/LowerThresholdNonCritical"_json_pointer); 95708777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical", 9583929aca1SAnthony Wilson "CriticalHigh", 9593929aca1SAnthony Wilson "/UpperThresholdCritical"_json_pointer); 96008777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical", 9613929aca1SAnthony Wilson "CriticalLow", 9623929aca1SAnthony Wilson "/LowerThresholdCritical"_json_pointer); 963de629b6eSShawn McCarney } 96408777fb0SLewanczyk, Dawid 9652474adfaSEd Tanous // TODO Need to get UpperThresholdFatal and LowerThresholdFatal 9662474adfaSEd Tanous 967a0ec28b6SAdrian Ambrożewicz if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) 96895a3ecadSAnthony Wilson { 96995a3ecadSAnthony Wilson properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue", 9703929aca1SAnthony Wilson "/ReadingRangeMin"_json_pointer); 97195a3ecadSAnthony Wilson properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue", 9723929aca1SAnthony Wilson "/ReadingRangeMax"_json_pointer); 97395a3ecadSAnthony Wilson } 97495a3ecadSAnthony Wilson else if (sensorType == "temperature") 9751abe55efSEd Tanous { 97608777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue", 9773929aca1SAnthony Wilson "/MinReadingRangeTemp"_json_pointer); 97808777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue", 9793929aca1SAnthony Wilson "/MaxReadingRangeTemp"_json_pointer); 9801abe55efSEd Tanous } 981adc4f0dbSShawn McCarney else if (sensorType != "power") 9821abe55efSEd Tanous { 98308777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue", 9843929aca1SAnthony Wilson "/MinReadingRange"_json_pointer); 98508777fb0SLewanczyk, Dawid properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue", 9863929aca1SAnthony Wilson "/MaxReadingRange"_json_pointer); 98708777fb0SLewanczyk, Dawid } 98808777fb0SLewanczyk, Dawid 9893929aca1SAnthony Wilson for (const std::tuple<const char*, const char*, 9903929aca1SAnthony Wilson nlohmann::json::json_pointer>& p : properties) 9911abe55efSEd Tanous { 99208777fb0SLewanczyk, Dawid auto interfaceProperties = interfacesDict.find(std::get<0>(p)); 9931abe55efSEd Tanous if (interfaceProperties != interfacesDict.end()) 9941abe55efSEd Tanous { 995271584abSEd Tanous auto thisValueIt = interfaceProperties->second.find(std::get<1>(p)); 996271584abSEd Tanous if (thisValueIt != interfaceProperties->second.end()) 9971abe55efSEd Tanous { 998271584abSEd Tanous const SensorVariant& valueVariant = thisValueIt->second; 9993929aca1SAnthony Wilson 10003929aca1SAnthony Wilson // The property we want to set may be nested json, so use 10013929aca1SAnthony Wilson // a json_pointer for easy indexing into the json structure. 10023929aca1SAnthony Wilson const nlohmann::json::json_pointer& key = std::get<2>(p); 10033929aca1SAnthony Wilson 100408777fb0SLewanczyk, Dawid // Attempt to pull the int64 directly 1005abf2add6SEd Tanous const int64_t* int64Value = std::get_if<int64_t>(&valueVariant); 100608777fb0SLewanczyk, Dawid 1007abf2add6SEd Tanous const double* doubleValue = std::get_if<double>(&valueVariant); 1008028f7ebcSEddie James const uint32_t* uValue = std::get_if<uint32_t>(&valueVariant); 10096f6d0d32SEd Tanous double temp = 0.0; 10106f6d0d32SEd Tanous if (int64Value != nullptr) 10111abe55efSEd Tanous { 1012271584abSEd Tanous temp = static_cast<double>(*int64Value); 10136f6d0d32SEd Tanous } 10146f6d0d32SEd Tanous else if (doubleValue != nullptr) 10151abe55efSEd Tanous { 10166f6d0d32SEd Tanous temp = *doubleValue; 10171abe55efSEd Tanous } 1018028f7ebcSEddie James else if (uValue != nullptr) 1019028f7ebcSEddie James { 1020028f7ebcSEddie James temp = *uValue; 1021028f7ebcSEddie James } 10221abe55efSEd Tanous else 10231abe55efSEd Tanous { 10246f6d0d32SEd Tanous BMCWEB_LOG_ERROR 10256f6d0d32SEd Tanous << "Got value interface that wasn't int or double"; 10266f6d0d32SEd Tanous continue; 102708777fb0SLewanczyk, Dawid } 10286f6d0d32SEd Tanous temp = temp * std::pow(10, scaleMultiplier); 10296f6d0d32SEd Tanous if (forceToInt) 10306f6d0d32SEd Tanous { 103181ce609eSEd Tanous sensorJson[key] = static_cast<int64_t>(temp); 10326f6d0d32SEd Tanous } 10336f6d0d32SEd Tanous else 10346f6d0d32SEd Tanous { 103581ce609eSEd Tanous sensorJson[key] = temp; 103608777fb0SLewanczyk, Dawid } 103708777fb0SLewanczyk, Dawid } 103808777fb0SLewanczyk, Dawid } 103908777fb0SLewanczyk, Dawid } 1040a0ec28b6SAdrian Ambrożewicz 104181ce609eSEd Tanous sensorsAsyncResp->addMetadata(sensorJson, unit.to_string(), 1042a0ec28b6SAdrian Ambrożewicz "/xyz/openbmc_project/sensors/" + sensorType + 1043a0ec28b6SAdrian Ambrożewicz "/" + sensorName); 1044a0ec28b6SAdrian Ambrożewicz 104555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "Added sensor " << sensorName; 104608777fb0SLewanczyk, Dawid } 104708777fb0SLewanczyk, Dawid 1048b5a76932SEd Tanous inline void populateFanRedundancy( 1049b5a76932SEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp) 10508bd25ccdSJames Feist { 10518bd25ccdSJames Feist crow::connections::systemBus->async_method_call( 10528bd25ccdSJames Feist [sensorsAsyncResp](const boost::system::error_code ec, 10538bd25ccdSJames Feist const GetSubTreeType& resp) { 10548bd25ccdSJames Feist if (ec) 10558bd25ccdSJames Feist { 10568bd25ccdSJames Feist return; // don't have to have this interface 10578bd25ccdSJames Feist } 1058e278c18fSEd Tanous for (const std::pair<std::string, 1059e278c18fSEd Tanous std::vector<std::pair< 1060e278c18fSEd Tanous std::string, std::vector<std::string>>>>& 1061e278c18fSEd Tanous pathPair : resp) 10628bd25ccdSJames Feist { 1063e278c18fSEd Tanous const std::string& path = pathPair.first; 1064e278c18fSEd Tanous const std::vector< 1065e278c18fSEd Tanous std::pair<std::string, std::vector<std::string>>>& objDict = 1066e278c18fSEd Tanous pathPair.second; 10678bd25ccdSJames Feist if (objDict.empty()) 10688bd25ccdSJames Feist { 10698bd25ccdSJames Feist continue; // this should be impossible 10708bd25ccdSJames Feist } 10718bd25ccdSJames Feist 10728bd25ccdSJames Feist const std::string& owner = objDict.begin()->first; 10738bd25ccdSJames Feist crow::connections::systemBus->async_method_call( 10748bd25ccdSJames Feist [path, owner, 1075271584abSEd Tanous sensorsAsyncResp](const boost::system::error_code e, 10768bd25ccdSJames Feist std::variant<std::vector<std::string>> 10778bd25ccdSJames Feist variantEndpoints) { 1078271584abSEd Tanous if (e) 10798bd25ccdSJames Feist { 10808bd25ccdSJames Feist return; // if they don't have an association we 10818bd25ccdSJames Feist // can't tell what chassis is 10828bd25ccdSJames Feist } 10838bd25ccdSJames Feist // verify part of the right chassis 10848bd25ccdSJames Feist auto endpoints = std::get_if<std::vector<std::string>>( 10858bd25ccdSJames Feist &variantEndpoints); 10868bd25ccdSJames Feist 10878bd25ccdSJames Feist if (endpoints == nullptr) 10888bd25ccdSJames Feist { 10898bd25ccdSJames Feist BMCWEB_LOG_ERROR << "Invalid association interface"; 10908bd25ccdSJames Feist messages::internalError(sensorsAsyncResp->res); 10918bd25ccdSJames Feist return; 10928bd25ccdSJames Feist } 10938bd25ccdSJames Feist 10948bd25ccdSJames Feist auto found = std::find_if( 10958bd25ccdSJames Feist endpoints->begin(), endpoints->end(), 10968bd25ccdSJames Feist [sensorsAsyncResp](const std::string& entry) { 10978bd25ccdSJames Feist return entry.find( 10988bd25ccdSJames Feist sensorsAsyncResp->chassisId) != 10998bd25ccdSJames Feist std::string::npos; 11008bd25ccdSJames Feist }); 11018bd25ccdSJames Feist 11028bd25ccdSJames Feist if (found == endpoints->end()) 11038bd25ccdSJames Feist { 11048bd25ccdSJames Feist return; 11058bd25ccdSJames Feist } 11068bd25ccdSJames Feist crow::connections::systemBus->async_method_call( 11078bd25ccdSJames Feist [path, sensorsAsyncResp]( 1108271584abSEd Tanous const boost::system::error_code& err, 11098bd25ccdSJames Feist const boost::container::flat_map< 11108bd25ccdSJames Feist std::string, 11118bd25ccdSJames Feist std::variant<uint8_t, 11128bd25ccdSJames Feist std::vector<std::string>, 11138bd25ccdSJames Feist std::string>>& ret) { 1114271584abSEd Tanous if (err) 11158bd25ccdSJames Feist { 11168bd25ccdSJames Feist return; // don't have to have this 11178bd25ccdSJames Feist // interface 11188bd25ccdSJames Feist } 11198bd25ccdSJames Feist auto findFailures = ret.find("AllowedFailures"); 11208bd25ccdSJames Feist auto findCollection = ret.find("Collection"); 11218bd25ccdSJames Feist auto findStatus = ret.find("Status"); 11228bd25ccdSJames Feist 11238bd25ccdSJames Feist if (findFailures == ret.end() || 11248bd25ccdSJames Feist findCollection == ret.end() || 11258bd25ccdSJames Feist findStatus == ret.end()) 11268bd25ccdSJames Feist { 11278bd25ccdSJames Feist BMCWEB_LOG_ERROR 11288bd25ccdSJames Feist << "Invalid redundancy interface"; 11298bd25ccdSJames Feist messages::internalError( 11308bd25ccdSJames Feist sensorsAsyncResp->res); 11318bd25ccdSJames Feist return; 11328bd25ccdSJames Feist } 11338bd25ccdSJames Feist 11348bd25ccdSJames Feist auto allowedFailures = std::get_if<uint8_t>( 11358bd25ccdSJames Feist &(findFailures->second)); 11368bd25ccdSJames Feist auto collection = 11378bd25ccdSJames Feist std::get_if<std::vector<std::string>>( 11388bd25ccdSJames Feist &(findCollection->second)); 11398bd25ccdSJames Feist auto status = std::get_if<std::string>( 11408bd25ccdSJames Feist &(findStatus->second)); 11418bd25ccdSJames Feist 11428bd25ccdSJames Feist if (allowedFailures == nullptr || 11438bd25ccdSJames Feist collection == nullptr || status == nullptr) 11448bd25ccdSJames Feist { 11458bd25ccdSJames Feist 11468bd25ccdSJames Feist BMCWEB_LOG_ERROR 11478bd25ccdSJames Feist << "Invalid redundancy interface " 11488bd25ccdSJames Feist "types"; 11498bd25ccdSJames Feist messages::internalError( 11508bd25ccdSJames Feist sensorsAsyncResp->res); 11518bd25ccdSJames Feist return; 11528bd25ccdSJames Feist } 115328aa8de5SGeorge Liu sdbusplus::message::object_path objectPath( 115428aa8de5SGeorge Liu path); 115528aa8de5SGeorge Liu std::string name = objectPath.filename(); 115628aa8de5SGeorge Liu if (name.empty()) 11578bd25ccdSJames Feist { 11588bd25ccdSJames Feist // this should be impossible 11598bd25ccdSJames Feist messages::internalError( 11608bd25ccdSJames Feist sensorsAsyncResp->res); 11618bd25ccdSJames Feist return; 11628bd25ccdSJames Feist } 11638bd25ccdSJames Feist std::replace(name.begin(), name.end(), '_', 11648bd25ccdSJames Feist ' '); 11658bd25ccdSJames Feist 11668bd25ccdSJames Feist std::string health; 11678bd25ccdSJames Feist 11688bd25ccdSJames Feist if (boost::ends_with(*status, "Full")) 11698bd25ccdSJames Feist { 11708bd25ccdSJames Feist health = "OK"; 11718bd25ccdSJames Feist } 11728bd25ccdSJames Feist else if (boost::ends_with(*status, "Degraded")) 11738bd25ccdSJames Feist { 11748bd25ccdSJames Feist health = "Warning"; 11758bd25ccdSJames Feist } 11768bd25ccdSJames Feist else 11778bd25ccdSJames Feist { 11788bd25ccdSJames Feist health = "Critical"; 11798bd25ccdSJames Feist } 11808bd25ccdSJames Feist std::vector<nlohmann::json> redfishCollection; 11818bd25ccdSJames Feist const auto& fanRedfish = 11828bd25ccdSJames Feist sensorsAsyncResp->res.jsonValue["Fans"]; 11838bd25ccdSJames Feist for (const std::string& item : *collection) 11848bd25ccdSJames Feist { 118528aa8de5SGeorge Liu sdbusplus::message::object_path path(item); 118628aa8de5SGeorge Liu std::string itemName = path.filename(); 118728aa8de5SGeorge Liu if (itemName.empty()) 118828aa8de5SGeorge Liu { 118928aa8de5SGeorge Liu continue; 119028aa8de5SGeorge Liu } 11918bd25ccdSJames Feist /* 11928bd25ccdSJames Feist todo(ed): merge patch that fixes the names 11938bd25ccdSJames Feist std::replace(itemName.begin(), 11948bd25ccdSJames Feist itemName.end(), '_', ' ');*/ 11958bd25ccdSJames Feist auto schemaItem = std::find_if( 11968bd25ccdSJames Feist fanRedfish.begin(), fanRedfish.end(), 11978bd25ccdSJames Feist [itemName](const nlohmann::json& fan) { 11988bd25ccdSJames Feist return fan["MemberId"] == itemName; 11998bd25ccdSJames Feist }); 12008bd25ccdSJames Feist if (schemaItem != fanRedfish.end()) 12018bd25ccdSJames Feist { 12028bd25ccdSJames Feist redfishCollection.push_back( 12038bd25ccdSJames Feist {{"@odata.id", 12048bd25ccdSJames Feist (*schemaItem)["@odata.id"]}}); 12058bd25ccdSJames Feist } 12068bd25ccdSJames Feist else 12078bd25ccdSJames Feist { 12088bd25ccdSJames Feist BMCWEB_LOG_ERROR 12098bd25ccdSJames Feist << "failed to find fan in schema"; 12108bd25ccdSJames Feist messages::internalError( 12118bd25ccdSJames Feist sensorsAsyncResp->res); 12128bd25ccdSJames Feist return; 12138bd25ccdSJames Feist } 12148bd25ccdSJames Feist } 12158bd25ccdSJames Feist 12163e9e72ebSKuiying Wang size_t minNumNeeded = 12173e9e72ebSKuiying Wang collection->size() > 0 12183e9e72ebSKuiying Wang ? collection->size() - *allowedFailures 12193e9e72ebSKuiying Wang : 0; 1220271584abSEd Tanous nlohmann::json& jResp = 1221271584abSEd Tanous sensorsAsyncResp->res 12228bd25ccdSJames Feist .jsonValue["Redundancy"]; 1223271584abSEd Tanous jResp.push_back( 12248bd25ccdSJames Feist {{"@odata.id", 1225717794d5SAppaRao Puli "/redfish/v1/Chassis/" + 12268bd25ccdSJames Feist sensorsAsyncResp->chassisId + "/" + 12278bd25ccdSJames Feist sensorsAsyncResp->chassisSubNode + 12288bd25ccdSJames Feist "#/Redundancy/" + 1229271584abSEd Tanous std::to_string(jResp.size())}, 12308bd25ccdSJames Feist {"@odata.type", 12318bd25ccdSJames Feist "#Redundancy.v1_3_2.Redundancy"}, 12323e9e72ebSKuiying Wang {"MinNumNeeded", minNumNeeded}, 12338bd25ccdSJames Feist {"MemberId", name}, 12348bd25ccdSJames Feist {"Mode", "N+m"}, 12358bd25ccdSJames Feist {"Name", name}, 12368bd25ccdSJames Feist {"RedundancySet", redfishCollection}, 12378bd25ccdSJames Feist {"Status", 12388bd25ccdSJames Feist {{"Health", health}, 12398bd25ccdSJames Feist {"State", "Enabled"}}}}); 12408bd25ccdSJames Feist }, 12418bd25ccdSJames Feist owner, path, "org.freedesktop.DBus.Properties", 12428bd25ccdSJames Feist "GetAll", 12438bd25ccdSJames Feist "xyz.openbmc_project.Control.FanRedundancy"); 12448bd25ccdSJames Feist }, 124502e92e32SJames Feist "xyz.openbmc_project.ObjectMapper", path + "/chassis", 12468bd25ccdSJames Feist "org.freedesktop.DBus.Properties", "Get", 12478bd25ccdSJames Feist "xyz.openbmc_project.Association", "endpoints"); 12488bd25ccdSJames Feist } 12498bd25ccdSJames Feist }, 12508bd25ccdSJames Feist "xyz.openbmc_project.ObjectMapper", 12518bd25ccdSJames Feist "/xyz/openbmc_project/object_mapper", 12528bd25ccdSJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", 12538bd25ccdSJames Feist "/xyz/openbmc_project/control", 2, 12548bd25ccdSJames Feist std::array<const char*, 1>{ 12558bd25ccdSJames Feist "xyz.openbmc_project.Control.FanRedundancy"}); 12568bd25ccdSJames Feist } 12578bd25ccdSJames Feist 1258b5a76932SEd Tanous inline void 125981ce609eSEd Tanous sortJSONResponse(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp) 126049c53ac9SJohnathan Mantey { 126181ce609eSEd Tanous nlohmann::json& response = sensorsAsyncResp->res.jsonValue; 126249c53ac9SJohnathan Mantey std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"}; 126381ce609eSEd Tanous if (sensorsAsyncResp->chassisSubNode == sensors::node::power) 126449c53ac9SJohnathan Mantey { 126549c53ac9SJohnathan Mantey sensorHeaders = {"Voltages", "PowerSupplies"}; 126649c53ac9SJohnathan Mantey } 126749c53ac9SJohnathan Mantey for (const std::string& sensorGroup : sensorHeaders) 126849c53ac9SJohnathan Mantey { 126949c53ac9SJohnathan Mantey nlohmann::json::iterator entry = response.find(sensorGroup); 127049c53ac9SJohnathan Mantey if (entry != response.end()) 127149c53ac9SJohnathan Mantey { 127249c53ac9SJohnathan Mantey std::sort(entry->begin(), entry->end(), 127349c53ac9SJohnathan Mantey [](nlohmann::json& c1, nlohmann::json& c2) { 127449c53ac9SJohnathan Mantey return c1["Name"] < c2["Name"]; 127549c53ac9SJohnathan Mantey }); 127649c53ac9SJohnathan Mantey 127749c53ac9SJohnathan Mantey // add the index counts to the end of each entry 127849c53ac9SJohnathan Mantey size_t count = 0; 127949c53ac9SJohnathan Mantey for (nlohmann::json& sensorJson : *entry) 128049c53ac9SJohnathan Mantey { 128149c53ac9SJohnathan Mantey nlohmann::json::iterator odata = sensorJson.find("@odata.id"); 128249c53ac9SJohnathan Mantey if (odata == sensorJson.end()) 128349c53ac9SJohnathan Mantey { 128449c53ac9SJohnathan Mantey continue; 128549c53ac9SJohnathan Mantey } 128649c53ac9SJohnathan Mantey std::string* value = odata->get_ptr<std::string*>(); 128749c53ac9SJohnathan Mantey if (value != nullptr) 128849c53ac9SJohnathan Mantey { 128949c53ac9SJohnathan Mantey *value += std::to_string(count); 129049c53ac9SJohnathan Mantey count++; 129181ce609eSEd Tanous sensorsAsyncResp->updateUri(sensorJson["Name"], *value); 129249c53ac9SJohnathan Mantey } 129349c53ac9SJohnathan Mantey } 129449c53ac9SJohnathan Mantey } 129549c53ac9SJohnathan Mantey } 129649c53ac9SJohnathan Mantey } 129749c53ac9SJohnathan Mantey 129808777fb0SLewanczyk, Dawid /** 1299adc4f0dbSShawn McCarney * @brief Finds the inventory item with the specified object path. 1300adc4f0dbSShawn McCarney * @param inventoryItems D-Bus inventory items associated with sensors. 1301adc4f0dbSShawn McCarney * @param invItemObjPath D-Bus object path of inventory item. 1302adc4f0dbSShawn McCarney * @return Inventory item within vector, or nullptr if no match found. 13038fb49dd6SShawn McCarney */ 130423a21a1cSEd Tanous inline InventoryItem* findInventoryItem( 1305b5a76932SEd Tanous const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, 1306adc4f0dbSShawn McCarney const std::string& invItemObjPath) 13078fb49dd6SShawn McCarney { 1308adc4f0dbSShawn McCarney for (InventoryItem& inventoryItem : *inventoryItems) 13098fb49dd6SShawn McCarney { 1310adc4f0dbSShawn McCarney if (inventoryItem.objectPath == invItemObjPath) 13118fb49dd6SShawn McCarney { 1312adc4f0dbSShawn McCarney return &inventoryItem; 13138fb49dd6SShawn McCarney } 13148fb49dd6SShawn McCarney } 13158fb49dd6SShawn McCarney return nullptr; 13168fb49dd6SShawn McCarney } 13178fb49dd6SShawn McCarney 13188fb49dd6SShawn McCarney /** 1319adc4f0dbSShawn McCarney * @brief Finds the inventory item associated with the specified sensor. 1320adc4f0dbSShawn McCarney * @param inventoryItems D-Bus inventory items associated with sensors. 1321adc4f0dbSShawn McCarney * @param sensorObjPath D-Bus object path of sensor. 1322adc4f0dbSShawn McCarney * @return Inventory item within vector, or nullptr if no match found. 13238fb49dd6SShawn McCarney */ 132423a21a1cSEd Tanous inline InventoryItem* findInventoryItemForSensor( 1325b5a76932SEd Tanous const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, 1326adc4f0dbSShawn McCarney const std::string& sensorObjPath) 1327adc4f0dbSShawn McCarney { 1328adc4f0dbSShawn McCarney for (InventoryItem& inventoryItem : *inventoryItems) 1329adc4f0dbSShawn McCarney { 1330adc4f0dbSShawn McCarney if (inventoryItem.sensors.count(sensorObjPath) > 0) 1331adc4f0dbSShawn McCarney { 1332adc4f0dbSShawn McCarney return &inventoryItem; 1333adc4f0dbSShawn McCarney } 1334adc4f0dbSShawn McCarney } 1335adc4f0dbSShawn McCarney return nullptr; 1336adc4f0dbSShawn McCarney } 1337adc4f0dbSShawn McCarney 1338adc4f0dbSShawn McCarney /** 1339d500549bSAnthony Wilson * @brief Finds the inventory item associated with the specified led path. 1340d500549bSAnthony Wilson * @param inventoryItems D-Bus inventory items associated with sensors. 1341d500549bSAnthony Wilson * @param ledObjPath D-Bus object path of led. 1342d500549bSAnthony Wilson * @return Inventory item within vector, or nullptr if no match found. 1343d500549bSAnthony Wilson */ 1344d500549bSAnthony Wilson inline InventoryItem* 1345d500549bSAnthony Wilson findInventoryItemForLed(std::vector<InventoryItem>& inventoryItems, 1346d500549bSAnthony Wilson const std::string& ledObjPath) 1347d500549bSAnthony Wilson { 1348d500549bSAnthony Wilson for (InventoryItem& inventoryItem : inventoryItems) 1349d500549bSAnthony Wilson { 1350d500549bSAnthony Wilson if (inventoryItem.ledObjectPath == ledObjPath) 1351d500549bSAnthony Wilson { 1352d500549bSAnthony Wilson return &inventoryItem; 1353d500549bSAnthony Wilson } 1354d500549bSAnthony Wilson } 1355d500549bSAnthony Wilson return nullptr; 1356d500549bSAnthony Wilson } 1357d500549bSAnthony Wilson 1358d500549bSAnthony Wilson /** 1359adc4f0dbSShawn McCarney * @brief Adds inventory item and associated sensor to specified vector. 1360adc4f0dbSShawn McCarney * 1361adc4f0dbSShawn McCarney * Adds a new InventoryItem to the vector if necessary. Searches for an 1362adc4f0dbSShawn McCarney * existing InventoryItem with the specified object path. If not found, one is 1363adc4f0dbSShawn McCarney * added to the vector. 1364adc4f0dbSShawn McCarney * 1365adc4f0dbSShawn McCarney * Next, the specified sensor is added to the set of sensors associated with the 1366adc4f0dbSShawn McCarney * InventoryItem. 1367adc4f0dbSShawn McCarney * 1368adc4f0dbSShawn McCarney * @param inventoryItems D-Bus inventory items associated with sensors. 1369adc4f0dbSShawn McCarney * @param invItemObjPath D-Bus object path of inventory item. 1370adc4f0dbSShawn McCarney * @param sensorObjPath D-Bus object path of sensor 1371adc4f0dbSShawn McCarney */ 1372b5a76932SEd Tanous inline void addInventoryItem( 1373b5a76932SEd Tanous const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, 1374b5a76932SEd Tanous const std::string& invItemObjPath, const std::string& sensorObjPath) 1375adc4f0dbSShawn McCarney { 1376adc4f0dbSShawn McCarney // Look for inventory item in vector 1377adc4f0dbSShawn McCarney InventoryItem* inventoryItem = 1378adc4f0dbSShawn McCarney findInventoryItem(inventoryItems, invItemObjPath); 1379adc4f0dbSShawn McCarney 1380adc4f0dbSShawn McCarney // If inventory item doesn't exist in vector, add it 1381adc4f0dbSShawn McCarney if (inventoryItem == nullptr) 1382adc4f0dbSShawn McCarney { 1383adc4f0dbSShawn McCarney inventoryItems->emplace_back(invItemObjPath); 1384adc4f0dbSShawn McCarney inventoryItem = &(inventoryItems->back()); 1385adc4f0dbSShawn McCarney } 1386adc4f0dbSShawn McCarney 1387adc4f0dbSShawn McCarney // Add sensor to set of sensors associated with inventory item 1388adc4f0dbSShawn McCarney inventoryItem->sensors.emplace(sensorObjPath); 1389adc4f0dbSShawn McCarney } 1390adc4f0dbSShawn McCarney 1391adc4f0dbSShawn McCarney /** 1392adc4f0dbSShawn McCarney * @brief Stores D-Bus data in the specified inventory item. 1393adc4f0dbSShawn McCarney * 1394adc4f0dbSShawn McCarney * Finds D-Bus data in the specified map of interfaces. Stores the data in the 1395adc4f0dbSShawn McCarney * specified InventoryItem. 1396adc4f0dbSShawn McCarney * 1397adc4f0dbSShawn McCarney * This data is later used to provide sensor property values in the JSON 1398adc4f0dbSShawn McCarney * response. 1399adc4f0dbSShawn McCarney * 1400adc4f0dbSShawn McCarney * @param inventoryItem Inventory item where data will be stored. 1401adc4f0dbSShawn McCarney * @param interfacesDict Map containing D-Bus interfaces and their properties 1402adc4f0dbSShawn McCarney * for the specified inventory item. 1403adc4f0dbSShawn McCarney */ 140423a21a1cSEd Tanous inline void storeInventoryItemData( 1405adc4f0dbSShawn McCarney InventoryItem& inventoryItem, 14068fb49dd6SShawn McCarney const boost::container::flat_map< 14078fb49dd6SShawn McCarney std::string, boost::container::flat_map<std::string, SensorVariant>>& 14088fb49dd6SShawn McCarney interfacesDict) 14098fb49dd6SShawn McCarney { 1410adc4f0dbSShawn McCarney // Get properties from Inventory.Item interface 1411adc4f0dbSShawn McCarney auto interfaceIt = 1412adc4f0dbSShawn McCarney interfacesDict.find("xyz.openbmc_project.Inventory.Item"); 1413adc4f0dbSShawn McCarney if (interfaceIt != interfacesDict.end()) 14148fb49dd6SShawn McCarney { 1415adc4f0dbSShawn McCarney auto propertyIt = interfaceIt->second.find("Present"); 1416adc4f0dbSShawn McCarney if (propertyIt != interfaceIt->second.end()) 14178fb49dd6SShawn McCarney { 1418adc4f0dbSShawn McCarney const bool* value = std::get_if<bool>(&propertyIt->second); 1419adc4f0dbSShawn McCarney if (value != nullptr) 14208fb49dd6SShawn McCarney { 1421adc4f0dbSShawn McCarney inventoryItem.isPresent = *value; 14228fb49dd6SShawn McCarney } 14238fb49dd6SShawn McCarney } 14248fb49dd6SShawn McCarney } 14258fb49dd6SShawn McCarney 1426adc4f0dbSShawn McCarney // Check if Inventory.Item.PowerSupply interface is present 1427adc4f0dbSShawn McCarney interfaceIt = 1428adc4f0dbSShawn McCarney interfacesDict.find("xyz.openbmc_project.Inventory.Item.PowerSupply"); 1429adc4f0dbSShawn McCarney if (interfaceIt != interfacesDict.end()) 14308fb49dd6SShawn McCarney { 1431adc4f0dbSShawn McCarney inventoryItem.isPowerSupply = true; 14328fb49dd6SShawn McCarney } 1433adc4f0dbSShawn McCarney 1434adc4f0dbSShawn McCarney // Get properties from Inventory.Decorator.Asset interface 1435adc4f0dbSShawn McCarney interfaceIt = 1436adc4f0dbSShawn McCarney interfacesDict.find("xyz.openbmc_project.Inventory.Decorator.Asset"); 1437adc4f0dbSShawn McCarney if (interfaceIt != interfacesDict.end()) 1438adc4f0dbSShawn McCarney { 1439adc4f0dbSShawn McCarney auto propertyIt = interfaceIt->second.find("Manufacturer"); 1440adc4f0dbSShawn McCarney if (propertyIt != interfaceIt->second.end()) 1441adc4f0dbSShawn McCarney { 1442adc4f0dbSShawn McCarney const std::string* value = 1443adc4f0dbSShawn McCarney std::get_if<std::string>(&propertyIt->second); 1444adc4f0dbSShawn McCarney if (value != nullptr) 1445adc4f0dbSShawn McCarney { 1446adc4f0dbSShawn McCarney inventoryItem.manufacturer = *value; 1447adc4f0dbSShawn McCarney } 1448adc4f0dbSShawn McCarney } 1449adc4f0dbSShawn McCarney 1450adc4f0dbSShawn McCarney propertyIt = interfaceIt->second.find("Model"); 1451adc4f0dbSShawn McCarney if (propertyIt != interfaceIt->second.end()) 1452adc4f0dbSShawn McCarney { 1453adc4f0dbSShawn McCarney const std::string* value = 1454adc4f0dbSShawn McCarney std::get_if<std::string>(&propertyIt->second); 1455adc4f0dbSShawn McCarney if (value != nullptr) 1456adc4f0dbSShawn McCarney { 1457adc4f0dbSShawn McCarney inventoryItem.model = *value; 1458adc4f0dbSShawn McCarney } 1459adc4f0dbSShawn McCarney } 1460adc4f0dbSShawn McCarney 1461adc4f0dbSShawn McCarney propertyIt = interfaceIt->second.find("PartNumber"); 1462adc4f0dbSShawn McCarney if (propertyIt != interfaceIt->second.end()) 1463adc4f0dbSShawn McCarney { 1464adc4f0dbSShawn McCarney const std::string* value = 1465adc4f0dbSShawn McCarney std::get_if<std::string>(&propertyIt->second); 1466adc4f0dbSShawn McCarney if (value != nullptr) 1467adc4f0dbSShawn McCarney { 1468adc4f0dbSShawn McCarney inventoryItem.partNumber = *value; 1469adc4f0dbSShawn McCarney } 1470adc4f0dbSShawn McCarney } 1471adc4f0dbSShawn McCarney 1472adc4f0dbSShawn McCarney propertyIt = interfaceIt->second.find("SerialNumber"); 1473adc4f0dbSShawn McCarney if (propertyIt != interfaceIt->second.end()) 1474adc4f0dbSShawn McCarney { 1475adc4f0dbSShawn McCarney const std::string* value = 1476adc4f0dbSShawn McCarney std::get_if<std::string>(&propertyIt->second); 1477adc4f0dbSShawn McCarney if (value != nullptr) 1478adc4f0dbSShawn McCarney { 1479adc4f0dbSShawn McCarney inventoryItem.serialNumber = *value; 1480adc4f0dbSShawn McCarney } 1481adc4f0dbSShawn McCarney } 1482adc4f0dbSShawn McCarney } 1483adc4f0dbSShawn McCarney 1484adc4f0dbSShawn McCarney // Get properties from State.Decorator.OperationalStatus interface 1485adc4f0dbSShawn McCarney interfaceIt = interfacesDict.find( 1486adc4f0dbSShawn McCarney "xyz.openbmc_project.State.Decorator.OperationalStatus"); 1487adc4f0dbSShawn McCarney if (interfaceIt != interfacesDict.end()) 1488adc4f0dbSShawn McCarney { 1489adc4f0dbSShawn McCarney auto propertyIt = interfaceIt->second.find("Functional"); 1490adc4f0dbSShawn McCarney if (propertyIt != interfaceIt->second.end()) 1491adc4f0dbSShawn McCarney { 1492adc4f0dbSShawn McCarney const bool* value = std::get_if<bool>(&propertyIt->second); 1493adc4f0dbSShawn McCarney if (value != nullptr) 1494adc4f0dbSShawn McCarney { 1495adc4f0dbSShawn McCarney inventoryItem.isFunctional = *value; 14968fb49dd6SShawn McCarney } 14978fb49dd6SShawn McCarney } 14988fb49dd6SShawn McCarney } 14998fb49dd6SShawn McCarney } 15008fb49dd6SShawn McCarney 15018fb49dd6SShawn McCarney /** 1502adc4f0dbSShawn McCarney * @brief Gets D-Bus data for inventory items associated with sensors. 15038fb49dd6SShawn McCarney * 1504adc4f0dbSShawn McCarney * Uses the specified connections (services) to obtain D-Bus data for inventory 1505adc4f0dbSShawn McCarney * items associated with sensors. Stores the resulting data in the 1506adc4f0dbSShawn McCarney * inventoryItems vector. 15078fb49dd6SShawn McCarney * 1508adc4f0dbSShawn McCarney * This data is later used to provide sensor property values in the JSON 1509adc4f0dbSShawn McCarney * response. 1510adc4f0dbSShawn McCarney * 1511adc4f0dbSShawn McCarney * Finds the inventory item data asynchronously. Invokes callback when data has 1512adc4f0dbSShawn McCarney * been obtained. 1513adc4f0dbSShawn McCarney * 1514adc4f0dbSShawn McCarney * The callback must have the following signature: 1515adc4f0dbSShawn McCarney * @code 1516d500549bSAnthony Wilson * callback(void) 1517adc4f0dbSShawn McCarney * @endcode 1518adc4f0dbSShawn McCarney * 1519adc4f0dbSShawn McCarney * This function is called recursively, obtaining data asynchronously from one 1520adc4f0dbSShawn McCarney * connection in each call. This ensures the callback is not invoked until the 1521adc4f0dbSShawn McCarney * last asynchronous function has completed. 15228fb49dd6SShawn McCarney * 15238fb49dd6SShawn McCarney * @param sensorsAsyncResp Pointer to object holding response data. 1524adc4f0dbSShawn McCarney * @param inventoryItems D-Bus inventory items associated with sensors. 1525adc4f0dbSShawn McCarney * @param invConnections Connections that provide data for the inventory items. 15268fb49dd6SShawn McCarney * @param objectMgrPaths Mappings from connection name to DBus object path that 15278fb49dd6SShawn McCarney * implements ObjectManager. 1528adc4f0dbSShawn McCarney * @param callback Callback to invoke when inventory data has been obtained. 1529adc4f0dbSShawn McCarney * @param invConnectionsIndex Current index in invConnections. Only specified 1530adc4f0dbSShawn McCarney * in recursive calls to this function. 15318fb49dd6SShawn McCarney */ 1532adc4f0dbSShawn McCarney template <typename Callback> 1533adc4f0dbSShawn McCarney static void getInventoryItemsData( 15348fb49dd6SShawn McCarney std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, 1535adc4f0dbSShawn McCarney std::shared_ptr<std::vector<InventoryItem>> inventoryItems, 15368fb49dd6SShawn McCarney std::shared_ptr<boost::container::flat_set<std::string>> invConnections, 15378fb49dd6SShawn McCarney std::shared_ptr<boost::container::flat_map<std::string, std::string>> 1538adc4f0dbSShawn McCarney objectMgrPaths, 1539271584abSEd Tanous Callback&& callback, size_t invConnectionsIndex = 0) 15408fb49dd6SShawn McCarney { 1541adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsData enter"; 15428fb49dd6SShawn McCarney 1543adc4f0dbSShawn McCarney // If no more connections left, call callback 1544adc4f0dbSShawn McCarney if (invConnectionsIndex >= invConnections->size()) 15458fb49dd6SShawn McCarney { 1546d500549bSAnthony Wilson callback(); 1547adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsData exit"; 1548adc4f0dbSShawn McCarney return; 1549adc4f0dbSShawn McCarney } 1550adc4f0dbSShawn McCarney 1551adc4f0dbSShawn McCarney // Get inventory item data from current connection 1552adc4f0dbSShawn McCarney auto it = invConnections->nth(invConnectionsIndex); 1553adc4f0dbSShawn McCarney if (it != invConnections->end()) 1554adc4f0dbSShawn McCarney { 1555adc4f0dbSShawn McCarney const std::string& invConnection = *it; 1556adc4f0dbSShawn McCarney 15578fb49dd6SShawn McCarney // Response handler for GetManagedObjects 1558adc4f0dbSShawn McCarney auto respHandler = [sensorsAsyncResp, inventoryItems, invConnections, 1559adc4f0dbSShawn McCarney objectMgrPaths, callback{std::move(callback)}, 1560adc4f0dbSShawn McCarney invConnectionsIndex]( 1561adc4f0dbSShawn McCarney const boost::system::error_code ec, 15628fb49dd6SShawn McCarney ManagedObjectsVectorType& resp) { 1563adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler enter"; 15648fb49dd6SShawn McCarney if (ec) 15658fb49dd6SShawn McCarney { 15668fb49dd6SShawn McCarney BMCWEB_LOG_ERROR 1567adc4f0dbSShawn McCarney << "getInventoryItemsData respHandler DBus error " << ec; 15688fb49dd6SShawn McCarney messages::internalError(sensorsAsyncResp->res); 15698fb49dd6SShawn McCarney return; 15708fb49dd6SShawn McCarney } 15718fb49dd6SShawn McCarney 15728fb49dd6SShawn McCarney // Loop through returned object paths 15738fb49dd6SShawn McCarney for (const auto& objDictEntry : resp) 15748fb49dd6SShawn McCarney { 15758fb49dd6SShawn McCarney const std::string& objPath = 15768fb49dd6SShawn McCarney static_cast<const std::string&>(objDictEntry.first); 15778fb49dd6SShawn McCarney 1578adc4f0dbSShawn McCarney // If this object path is one of the specified inventory items 1579adc4f0dbSShawn McCarney InventoryItem* inventoryItem = 1580adc4f0dbSShawn McCarney findInventoryItem(inventoryItems, objPath); 1581adc4f0dbSShawn McCarney if (inventoryItem != nullptr) 15828fb49dd6SShawn McCarney { 1583adc4f0dbSShawn McCarney // Store inventory data in InventoryItem 1584adc4f0dbSShawn McCarney storeInventoryItemData(*inventoryItem, objDictEntry.second); 15858fb49dd6SShawn McCarney } 15868fb49dd6SShawn McCarney } 15878fb49dd6SShawn McCarney 1588adc4f0dbSShawn McCarney // Recurse to get inventory item data from next connection 1589adc4f0dbSShawn McCarney getInventoryItemsData(sensorsAsyncResp, inventoryItems, 1590adc4f0dbSShawn McCarney invConnections, objectMgrPaths, 1591adc4f0dbSShawn McCarney std::move(callback), invConnectionsIndex + 1); 1592adc4f0dbSShawn McCarney 1593adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler exit"; 15948fb49dd6SShawn McCarney }; 15958fb49dd6SShawn McCarney 15968fb49dd6SShawn McCarney // Find DBus object path that implements ObjectManager for the current 15978fb49dd6SShawn McCarney // connection. If no mapping found, default to "/". 15988fb49dd6SShawn McCarney auto iter = objectMgrPaths->find(invConnection); 15998fb49dd6SShawn McCarney const std::string& objectMgrPath = 16008fb49dd6SShawn McCarney (iter != objectMgrPaths->end()) ? iter->second : "/"; 16018fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "ObjectManager path for " << invConnection << " is " 16028fb49dd6SShawn McCarney << objectMgrPath; 16038fb49dd6SShawn McCarney 16048fb49dd6SShawn McCarney // Get all object paths and their interfaces for current connection 16058fb49dd6SShawn McCarney crow::connections::systemBus->async_method_call( 16068fb49dd6SShawn McCarney std::move(respHandler), invConnection, objectMgrPath, 16078fb49dd6SShawn McCarney "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 16088fb49dd6SShawn McCarney } 16098fb49dd6SShawn McCarney 1610adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsData exit"; 16118fb49dd6SShawn McCarney } 16128fb49dd6SShawn McCarney 16138fb49dd6SShawn McCarney /** 1614adc4f0dbSShawn McCarney * @brief Gets connections that provide D-Bus data for inventory items. 16158fb49dd6SShawn McCarney * 1616adc4f0dbSShawn McCarney * Gets the D-Bus connections (services) that provide data for the inventory 1617adc4f0dbSShawn McCarney * items that are associated with sensors. 16188fb49dd6SShawn McCarney * 16198fb49dd6SShawn McCarney * Finds the connections asynchronously. Invokes callback when information has 16208fb49dd6SShawn McCarney * been obtained. 16218fb49dd6SShawn McCarney * 16228fb49dd6SShawn McCarney * The callback must have the following signature: 16238fb49dd6SShawn McCarney * @code 16248fb49dd6SShawn McCarney * callback(std::shared_ptr<boost::container::flat_set<std::string>> 16258fb49dd6SShawn McCarney * invConnections) 16268fb49dd6SShawn McCarney * @endcode 16278fb49dd6SShawn McCarney * 16288fb49dd6SShawn McCarney * @param sensorsAsyncResp Pointer to object holding response data. 1629adc4f0dbSShawn McCarney * @param inventoryItems D-Bus inventory items associated with sensors. 16308fb49dd6SShawn McCarney * @param callback Callback to invoke when connections have been obtained. 16318fb49dd6SShawn McCarney */ 16328fb49dd6SShawn McCarney template <typename Callback> 16338fb49dd6SShawn McCarney static void getInventoryItemsConnections( 1634b5a76932SEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 1635b5a76932SEd Tanous const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, 16368fb49dd6SShawn McCarney Callback&& callback) 16378fb49dd6SShawn McCarney { 16388fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsConnections enter"; 16398fb49dd6SShawn McCarney 16408fb49dd6SShawn McCarney const std::string path = "/xyz/openbmc_project/inventory"; 1641adc4f0dbSShawn McCarney const std::array<std::string, 4> interfaces = { 16428fb49dd6SShawn McCarney "xyz.openbmc_project.Inventory.Item", 1643adc4f0dbSShawn McCarney "xyz.openbmc_project.Inventory.Item.PowerSupply", 1644adc4f0dbSShawn McCarney "xyz.openbmc_project.Inventory.Decorator.Asset", 16458fb49dd6SShawn McCarney "xyz.openbmc_project.State.Decorator.OperationalStatus"}; 16468fb49dd6SShawn McCarney 16478fb49dd6SShawn McCarney // Response handler for parsing output from GetSubTree 16488fb49dd6SShawn McCarney auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp, 1649adc4f0dbSShawn McCarney inventoryItems](const boost::system::error_code ec, 16508fb49dd6SShawn McCarney const GetSubTreeType& subtree) { 16518fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsConnections respHandler enter"; 16528fb49dd6SShawn McCarney if (ec) 16538fb49dd6SShawn McCarney { 16548fb49dd6SShawn McCarney messages::internalError(sensorsAsyncResp->res); 16558fb49dd6SShawn McCarney BMCWEB_LOG_ERROR 16568fb49dd6SShawn McCarney << "getInventoryItemsConnections respHandler DBus error " << ec; 16578fb49dd6SShawn McCarney return; 16588fb49dd6SShawn McCarney } 16598fb49dd6SShawn McCarney 16608fb49dd6SShawn McCarney // Make unique list of connections for desired inventory items 16618fb49dd6SShawn McCarney std::shared_ptr<boost::container::flat_set<std::string>> 16628fb49dd6SShawn McCarney invConnections = 16638fb49dd6SShawn McCarney std::make_shared<boost::container::flat_set<std::string>>(); 16648fb49dd6SShawn McCarney invConnections->reserve(8); 16658fb49dd6SShawn McCarney 16668fb49dd6SShawn McCarney // Loop through objects from GetSubTree 16678fb49dd6SShawn McCarney for (const std::pair< 16688fb49dd6SShawn McCarney std::string, 16698fb49dd6SShawn McCarney std::vector<std::pair<std::string, std::vector<std::string>>>>& 16708fb49dd6SShawn McCarney object : subtree) 16718fb49dd6SShawn McCarney { 1672adc4f0dbSShawn McCarney // Check if object path is one of the specified inventory items 16738fb49dd6SShawn McCarney const std::string& objPath = object.first; 1674adc4f0dbSShawn McCarney if (findInventoryItem(inventoryItems, objPath) != nullptr) 16758fb49dd6SShawn McCarney { 16768fb49dd6SShawn McCarney // Store all connections to inventory item 16778fb49dd6SShawn McCarney for (const std::pair<std::string, std::vector<std::string>>& 16788fb49dd6SShawn McCarney objData : object.second) 16798fb49dd6SShawn McCarney { 16808fb49dd6SShawn McCarney const std::string& invConnection = objData.first; 16818fb49dd6SShawn McCarney invConnections->insert(invConnection); 16828fb49dd6SShawn McCarney } 16838fb49dd6SShawn McCarney } 16848fb49dd6SShawn McCarney } 1685d500549bSAnthony Wilson 16868fb49dd6SShawn McCarney callback(invConnections); 16878fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsConnections respHandler exit"; 16888fb49dd6SShawn McCarney }; 16898fb49dd6SShawn McCarney 16908fb49dd6SShawn McCarney // Make call to ObjectMapper to find all inventory items 16918fb49dd6SShawn McCarney crow::connections::systemBus->async_method_call( 16928fb49dd6SShawn McCarney std::move(respHandler), "xyz.openbmc_project.ObjectMapper", 16938fb49dd6SShawn McCarney "/xyz/openbmc_project/object_mapper", 16948fb49dd6SShawn McCarney "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 0, interfaces); 16958fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsConnections exit"; 16968fb49dd6SShawn McCarney } 16978fb49dd6SShawn McCarney 16988fb49dd6SShawn McCarney /** 1699adc4f0dbSShawn McCarney * @brief Gets associations from sensors to inventory items. 17008fb49dd6SShawn McCarney * 17018fb49dd6SShawn McCarney * Looks for ObjectMapper associations from the specified sensors to related 1702d500549bSAnthony Wilson * inventory items. Then finds the associations from those inventory items to 1703d500549bSAnthony Wilson * their LEDs, if any. 17048fb49dd6SShawn McCarney * 17058fb49dd6SShawn McCarney * Finds the inventory items asynchronously. Invokes callback when information 17068fb49dd6SShawn McCarney * has been obtained. 17078fb49dd6SShawn McCarney * 17088fb49dd6SShawn McCarney * The callback must have the following signature: 17098fb49dd6SShawn McCarney * @code 1710adc4f0dbSShawn McCarney * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) 17118fb49dd6SShawn McCarney * @endcode 17128fb49dd6SShawn McCarney * 17138fb49dd6SShawn McCarney * @param sensorsAsyncResp Pointer to object holding response data. 17148fb49dd6SShawn McCarney * @param sensorNames All sensors within the current chassis. 17158fb49dd6SShawn McCarney * @param objectMgrPaths Mappings from connection name to DBus object path that 17168fb49dd6SShawn McCarney * implements ObjectManager. 17178fb49dd6SShawn McCarney * @param callback Callback to invoke when inventory items have been obtained. 17188fb49dd6SShawn McCarney */ 17198fb49dd6SShawn McCarney template <typename Callback> 1720adc4f0dbSShawn McCarney static void getInventoryItemAssociations( 1721b5a76932SEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 1722b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames, 1723b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_map<std::string, std::string>>& 17248fb49dd6SShawn McCarney objectMgrPaths, 17258fb49dd6SShawn McCarney Callback&& callback) 17268fb49dd6SShawn McCarney { 1727adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemAssociations enter"; 17288fb49dd6SShawn McCarney 17298fb49dd6SShawn McCarney // Response handler for GetManagedObjects 17308fb49dd6SShawn McCarney auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp, 17318fb49dd6SShawn McCarney sensorNames](const boost::system::error_code ec, 17328fb49dd6SShawn McCarney dbus::utility::ManagedObjectType& resp) { 1733adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler enter"; 17348fb49dd6SShawn McCarney if (ec) 17358fb49dd6SShawn McCarney { 1736adc4f0dbSShawn McCarney BMCWEB_LOG_ERROR 1737adc4f0dbSShawn McCarney << "getInventoryItemAssociations respHandler DBus error " << ec; 17388fb49dd6SShawn McCarney messages::internalError(sensorsAsyncResp->res); 17398fb49dd6SShawn McCarney return; 17408fb49dd6SShawn McCarney } 17418fb49dd6SShawn McCarney 1742adc4f0dbSShawn McCarney // Create vector to hold list of inventory items 1743adc4f0dbSShawn McCarney std::shared_ptr<std::vector<InventoryItem>> inventoryItems = 1744adc4f0dbSShawn McCarney std::make_shared<std::vector<InventoryItem>>(); 1745adc4f0dbSShawn McCarney 17468fb49dd6SShawn McCarney // Loop through returned object paths 17478fb49dd6SShawn McCarney std::string sensorAssocPath; 17488fb49dd6SShawn McCarney sensorAssocPath.reserve(128); // avoid memory allocations 17498fb49dd6SShawn McCarney for (const auto& objDictEntry : resp) 17508fb49dd6SShawn McCarney { 17518fb49dd6SShawn McCarney const std::string& objPath = 17528fb49dd6SShawn McCarney static_cast<const std::string&>(objDictEntry.first); 17538fb49dd6SShawn McCarney const boost::container::flat_map< 17548fb49dd6SShawn McCarney std::string, boost::container::flat_map< 17558fb49dd6SShawn McCarney std::string, dbus::utility::DbusVariantType>>& 17568fb49dd6SShawn McCarney interfacesDict = objDictEntry.second; 17578fb49dd6SShawn McCarney 17588fb49dd6SShawn McCarney // If path is inventory association for one of the specified sensors 17598fb49dd6SShawn McCarney for (const std::string& sensorName : *sensorNames) 17608fb49dd6SShawn McCarney { 17618fb49dd6SShawn McCarney sensorAssocPath = sensorName; 17628fb49dd6SShawn McCarney sensorAssocPath += "/inventory"; 17638fb49dd6SShawn McCarney if (objPath == sensorAssocPath) 17648fb49dd6SShawn McCarney { 17658fb49dd6SShawn McCarney // Get Association interface for object path 17668fb49dd6SShawn McCarney auto assocIt = 17678fb49dd6SShawn McCarney interfacesDict.find("xyz.openbmc_project.Association"); 17688fb49dd6SShawn McCarney if (assocIt != interfacesDict.end()) 17698fb49dd6SShawn McCarney { 17708fb49dd6SShawn McCarney // Get inventory item from end point 17718fb49dd6SShawn McCarney auto endpointsIt = assocIt->second.find("endpoints"); 17728fb49dd6SShawn McCarney if (endpointsIt != assocIt->second.end()) 17738fb49dd6SShawn McCarney { 17748fb49dd6SShawn McCarney const std::vector<std::string>* endpoints = 17758fb49dd6SShawn McCarney std::get_if<std::vector<std::string>>( 17768fb49dd6SShawn McCarney &endpointsIt->second); 17778fb49dd6SShawn McCarney if ((endpoints != nullptr) && !endpoints->empty()) 17788fb49dd6SShawn McCarney { 1779adc4f0dbSShawn McCarney // Add inventory item to vector 1780adc4f0dbSShawn McCarney const std::string& invItemPath = 1781adc4f0dbSShawn McCarney endpoints->front(); 1782adc4f0dbSShawn McCarney addInventoryItem(inventoryItems, invItemPath, 1783adc4f0dbSShawn McCarney sensorName); 17848fb49dd6SShawn McCarney } 17858fb49dd6SShawn McCarney } 17868fb49dd6SShawn McCarney } 17878fb49dd6SShawn McCarney break; 17888fb49dd6SShawn McCarney } 17898fb49dd6SShawn McCarney } 17908fb49dd6SShawn McCarney } 17918fb49dd6SShawn McCarney 1792d500549bSAnthony Wilson // Now loop through the returned object paths again, this time to 1793d500549bSAnthony Wilson // find the leds associated with the inventory items we just found 1794d500549bSAnthony Wilson std::string inventoryAssocPath; 1795d500549bSAnthony Wilson inventoryAssocPath.reserve(128); // avoid memory allocations 1796d500549bSAnthony Wilson for (const auto& objDictEntry : resp) 1797d500549bSAnthony Wilson { 1798d500549bSAnthony Wilson const std::string& objPath = 1799d500549bSAnthony Wilson static_cast<const std::string&>(objDictEntry.first); 1800d500549bSAnthony Wilson const boost::container::flat_map< 1801d500549bSAnthony Wilson std::string, boost::container::flat_map< 1802d500549bSAnthony Wilson std::string, dbus::utility::DbusVariantType>>& 1803d500549bSAnthony Wilson interfacesDict = objDictEntry.second; 1804d500549bSAnthony Wilson 1805d500549bSAnthony Wilson for (InventoryItem& inventoryItem : *inventoryItems) 1806d500549bSAnthony Wilson { 1807d500549bSAnthony Wilson inventoryAssocPath = inventoryItem.objectPath; 1808d500549bSAnthony Wilson inventoryAssocPath += "/leds"; 1809d500549bSAnthony Wilson if (objPath == inventoryAssocPath) 1810d500549bSAnthony Wilson { 1811d500549bSAnthony Wilson // Get Association interface for object path 1812d500549bSAnthony Wilson auto assocIt = 1813d500549bSAnthony Wilson interfacesDict.find("xyz.openbmc_project.Association"); 1814d500549bSAnthony Wilson if (assocIt != interfacesDict.end()) 1815d500549bSAnthony Wilson { 1816d500549bSAnthony Wilson // Get inventory item from end point 1817d500549bSAnthony Wilson auto endpointsIt = assocIt->second.find("endpoints"); 1818d500549bSAnthony Wilson if (endpointsIt != assocIt->second.end()) 1819d500549bSAnthony Wilson { 1820d500549bSAnthony Wilson const std::vector<std::string>* endpoints = 1821d500549bSAnthony Wilson std::get_if<std::vector<std::string>>( 1822d500549bSAnthony Wilson &endpointsIt->second); 1823d500549bSAnthony Wilson if ((endpoints != nullptr) && !endpoints->empty()) 1824d500549bSAnthony Wilson { 1825d500549bSAnthony Wilson // Store LED path in inventory item 1826d500549bSAnthony Wilson const std::string& ledPath = endpoints->front(); 1827d500549bSAnthony Wilson inventoryItem.ledObjectPath = ledPath; 1828d500549bSAnthony Wilson } 1829d500549bSAnthony Wilson } 1830d500549bSAnthony Wilson } 1831d500549bSAnthony Wilson break; 1832d500549bSAnthony Wilson } 1833d500549bSAnthony Wilson } 1834d500549bSAnthony Wilson } 1835adc4f0dbSShawn McCarney callback(inventoryItems); 1836adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler exit"; 18378fb49dd6SShawn McCarney }; 18388fb49dd6SShawn McCarney 18398fb49dd6SShawn McCarney // Find DBus object path that implements ObjectManager for ObjectMapper 18408fb49dd6SShawn McCarney std::string connection = "xyz.openbmc_project.ObjectMapper"; 18418fb49dd6SShawn McCarney auto iter = objectMgrPaths->find(connection); 18428fb49dd6SShawn McCarney const std::string& objectMgrPath = 18438fb49dd6SShawn McCarney (iter != objectMgrPaths->end()) ? iter->second : "/"; 18448fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is " 18458fb49dd6SShawn McCarney << objectMgrPath; 18468fb49dd6SShawn McCarney 18478fb49dd6SShawn McCarney // Call GetManagedObjects on the ObjectMapper to get all associations 18488fb49dd6SShawn McCarney crow::connections::systemBus->async_method_call( 18498fb49dd6SShawn McCarney std::move(respHandler), connection, objectMgrPath, 18508fb49dd6SShawn McCarney "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 18518fb49dd6SShawn McCarney 1852adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemAssociations exit"; 18538fb49dd6SShawn McCarney } 18548fb49dd6SShawn McCarney 18558fb49dd6SShawn McCarney /** 1856d500549bSAnthony Wilson * @brief Gets D-Bus data for inventory item leds associated with sensors. 1857d500549bSAnthony Wilson * 1858d500549bSAnthony Wilson * Uses the specified connections (services) to obtain D-Bus data for inventory 1859d500549bSAnthony Wilson * item leds associated with sensors. Stores the resulting data in the 1860d500549bSAnthony Wilson * inventoryItems vector. 1861d500549bSAnthony Wilson * 1862d500549bSAnthony Wilson * This data is later used to provide sensor property values in the JSON 1863d500549bSAnthony Wilson * response. 1864d500549bSAnthony Wilson * 1865d500549bSAnthony Wilson * Finds the inventory item led data asynchronously. Invokes callback when data 1866d500549bSAnthony Wilson * has been obtained. 1867d500549bSAnthony Wilson * 1868d500549bSAnthony Wilson * The callback must have the following signature: 1869d500549bSAnthony Wilson * @code 187042cbe538SGunnar Mills * callback() 1871d500549bSAnthony Wilson * @endcode 1872d500549bSAnthony Wilson * 1873d500549bSAnthony Wilson * This function is called recursively, obtaining data asynchronously from one 1874d500549bSAnthony Wilson * connection in each call. This ensures the callback is not invoked until the 1875d500549bSAnthony Wilson * last asynchronous function has completed. 1876d500549bSAnthony Wilson * 1877d500549bSAnthony Wilson * @param sensorsAsyncResp Pointer to object holding response data. 1878d500549bSAnthony Wilson * @param inventoryItems D-Bus inventory items associated with sensors. 1879d500549bSAnthony Wilson * @param ledConnections Connections that provide data for the inventory leds. 1880d500549bSAnthony Wilson * @param callback Callback to invoke when inventory data has been obtained. 1881d500549bSAnthony Wilson * @param ledConnectionsIndex Current index in ledConnections. Only specified 1882d500549bSAnthony Wilson * in recursive calls to this function. 1883d500549bSAnthony Wilson */ 1884d500549bSAnthony Wilson template <typename Callback> 1885d500549bSAnthony Wilson void getInventoryLedData( 1886d500549bSAnthony Wilson std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, 1887d500549bSAnthony Wilson std::shared_ptr<std::vector<InventoryItem>> inventoryItems, 1888d500549bSAnthony Wilson std::shared_ptr<boost::container::flat_map<std::string, std::string>> 1889d500549bSAnthony Wilson ledConnections, 1890d500549bSAnthony Wilson Callback&& callback, size_t ledConnectionsIndex = 0) 1891d500549bSAnthony Wilson { 1892d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLedData enter"; 1893d500549bSAnthony Wilson 1894d500549bSAnthony Wilson // If no more connections left, call callback 1895d500549bSAnthony Wilson if (ledConnectionsIndex >= ledConnections->size()) 1896d500549bSAnthony Wilson { 189742cbe538SGunnar Mills callback(); 1898d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLedData exit"; 1899d500549bSAnthony Wilson return; 1900d500549bSAnthony Wilson } 1901d500549bSAnthony Wilson 1902d500549bSAnthony Wilson // Get inventory item data from current connection 1903d500549bSAnthony Wilson auto it = ledConnections->nth(ledConnectionsIndex); 1904d500549bSAnthony Wilson if (it != ledConnections->end()) 1905d500549bSAnthony Wilson { 1906d500549bSAnthony Wilson const std::string& ledPath = (*it).first; 1907d500549bSAnthony Wilson const std::string& ledConnection = (*it).second; 1908d500549bSAnthony Wilson // Response handler for Get State property 1909d500549bSAnthony Wilson auto respHandler = 1910d500549bSAnthony Wilson [sensorsAsyncResp, inventoryItems, ledConnections, ledPath, 1911d500549bSAnthony Wilson callback{std::move(callback)}, 1912d500549bSAnthony Wilson ledConnectionsIndex](const boost::system::error_code ec, 1913d500549bSAnthony Wilson const std::variant<std::string>& ledState) { 1914d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter"; 1915d500549bSAnthony Wilson if (ec) 1916d500549bSAnthony Wilson { 1917d500549bSAnthony Wilson BMCWEB_LOG_ERROR 1918d500549bSAnthony Wilson << "getInventoryLedData respHandler DBus error " << ec; 1919d500549bSAnthony Wilson messages::internalError(sensorsAsyncResp->res); 1920d500549bSAnthony Wilson return; 1921d500549bSAnthony Wilson } 1922d500549bSAnthony Wilson 1923d500549bSAnthony Wilson const std::string* state = std::get_if<std::string>(&ledState); 1924d500549bSAnthony Wilson if (state != nullptr) 1925d500549bSAnthony Wilson { 1926d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "Led state: " << *state; 1927d500549bSAnthony Wilson // Find inventory item with this LED object path 1928d500549bSAnthony Wilson InventoryItem* inventoryItem = 1929d500549bSAnthony Wilson findInventoryItemForLed(*inventoryItems, ledPath); 1930d500549bSAnthony Wilson if (inventoryItem != nullptr) 1931d500549bSAnthony Wilson { 1932d500549bSAnthony Wilson // Store LED state in InventoryItem 1933d500549bSAnthony Wilson if (boost::ends_with(*state, "On")) 1934d500549bSAnthony Wilson { 1935d500549bSAnthony Wilson inventoryItem->ledState = LedState::ON; 1936d500549bSAnthony Wilson } 1937d500549bSAnthony Wilson else if (boost::ends_with(*state, "Blink")) 1938d500549bSAnthony Wilson { 1939d500549bSAnthony Wilson inventoryItem->ledState = LedState::BLINK; 1940d500549bSAnthony Wilson } 1941d500549bSAnthony Wilson else if (boost::ends_with(*state, "Off")) 1942d500549bSAnthony Wilson { 1943d500549bSAnthony Wilson inventoryItem->ledState = LedState::OFF; 1944d500549bSAnthony Wilson } 1945d500549bSAnthony Wilson else 1946d500549bSAnthony Wilson { 1947d500549bSAnthony Wilson inventoryItem->ledState = LedState::UNKNOWN; 1948d500549bSAnthony Wilson } 1949d500549bSAnthony Wilson } 1950d500549bSAnthony Wilson } 1951d500549bSAnthony Wilson else 1952d500549bSAnthony Wilson { 1953d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "Failed to find State data for LED: " 1954d500549bSAnthony Wilson << ledPath; 1955d500549bSAnthony Wilson } 1956d500549bSAnthony Wilson 1957d500549bSAnthony Wilson // Recurse to get LED data from next connection 1958d500549bSAnthony Wilson getInventoryLedData(sensorsAsyncResp, inventoryItems, 1959d500549bSAnthony Wilson ledConnections, std::move(callback), 1960d500549bSAnthony Wilson ledConnectionsIndex + 1); 1961d500549bSAnthony Wilson 1962d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler exit"; 1963d500549bSAnthony Wilson }; 1964d500549bSAnthony Wilson 1965d500549bSAnthony Wilson // Get the State property for the current LED 1966d500549bSAnthony Wilson crow::connections::systemBus->async_method_call( 1967d500549bSAnthony Wilson std::move(respHandler), ledConnection, ledPath, 1968d500549bSAnthony Wilson "org.freedesktop.DBus.Properties", "Get", 1969d500549bSAnthony Wilson "xyz.openbmc_project.Led.Physical", "State"); 1970d500549bSAnthony Wilson } 1971d500549bSAnthony Wilson 1972d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLedData exit"; 1973d500549bSAnthony Wilson } 1974d500549bSAnthony Wilson 1975d500549bSAnthony Wilson /** 1976d500549bSAnthony Wilson * @brief Gets LED data for LEDs associated with given inventory items. 1977d500549bSAnthony Wilson * 1978d500549bSAnthony Wilson * Gets the D-Bus connections (services) that provide LED data for the LEDs 1979d500549bSAnthony Wilson * associated with the specified inventory items. Then gets the LED data from 1980d500549bSAnthony Wilson * each connection and stores it in the inventory item. 1981d500549bSAnthony Wilson * 1982d500549bSAnthony Wilson * This data is later used to provide sensor property values in the JSON 1983d500549bSAnthony Wilson * response. 1984d500549bSAnthony Wilson * 1985d500549bSAnthony Wilson * Finds the LED data asynchronously. Invokes callback when information has 1986d500549bSAnthony Wilson * been obtained. 1987d500549bSAnthony Wilson * 1988d500549bSAnthony Wilson * The callback must have the following signature: 1989d500549bSAnthony Wilson * @code 199042cbe538SGunnar Mills * callback() 1991d500549bSAnthony Wilson * @endcode 1992d500549bSAnthony Wilson * 1993d500549bSAnthony Wilson * @param sensorsAsyncResp Pointer to object holding response data. 1994d500549bSAnthony Wilson * @param inventoryItems D-Bus inventory items associated with sensors. 1995d500549bSAnthony Wilson * @param callback Callback to invoke when inventory items have been obtained. 1996d500549bSAnthony Wilson */ 1997d500549bSAnthony Wilson template <typename Callback> 1998d500549bSAnthony Wilson void getInventoryLeds( 1999d500549bSAnthony Wilson std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, 2000d500549bSAnthony Wilson std::shared_ptr<std::vector<InventoryItem>> inventoryItems, 2001d500549bSAnthony Wilson Callback&& callback) 2002d500549bSAnthony Wilson { 2003d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLeds enter"; 2004d500549bSAnthony Wilson 2005d500549bSAnthony Wilson const std::string path = "/xyz/openbmc_project"; 2006d500549bSAnthony Wilson const std::array<std::string, 1> interfaces = { 2007d500549bSAnthony Wilson "xyz.openbmc_project.Led.Physical"}; 2008d500549bSAnthony Wilson 2009d500549bSAnthony Wilson // Response handler for parsing output from GetSubTree 2010d500549bSAnthony Wilson auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp, 2011d500549bSAnthony Wilson inventoryItems](const boost::system::error_code ec, 2012d500549bSAnthony Wilson const GetSubTreeType& subtree) { 2013d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLeds respHandler enter"; 2014d500549bSAnthony Wilson if (ec) 2015d500549bSAnthony Wilson { 2016d500549bSAnthony Wilson messages::internalError(sensorsAsyncResp->res); 2017d500549bSAnthony Wilson BMCWEB_LOG_ERROR << "getInventoryLeds respHandler DBus error " 2018d500549bSAnthony Wilson << ec; 2019d500549bSAnthony Wilson return; 2020d500549bSAnthony Wilson } 2021d500549bSAnthony Wilson 2022d500549bSAnthony Wilson // Build map of LED object paths to connections 2023d500549bSAnthony Wilson std::shared_ptr<boost::container::flat_map<std::string, std::string>> 2024d500549bSAnthony Wilson ledConnections = std::make_shared< 2025d500549bSAnthony Wilson boost::container::flat_map<std::string, std::string>>(); 2026d500549bSAnthony Wilson 2027d500549bSAnthony Wilson // Loop through objects from GetSubTree 2028d500549bSAnthony Wilson for (const std::pair< 2029d500549bSAnthony Wilson std::string, 2030d500549bSAnthony Wilson std::vector<std::pair<std::string, std::vector<std::string>>>>& 2031d500549bSAnthony Wilson object : subtree) 2032d500549bSAnthony Wilson { 2033d500549bSAnthony Wilson // Check if object path is LED for one of the specified inventory 2034d500549bSAnthony Wilson // items 2035d500549bSAnthony Wilson const std::string& ledPath = object.first; 2036d500549bSAnthony Wilson if (findInventoryItemForLed(*inventoryItems, ledPath) != nullptr) 2037d500549bSAnthony Wilson { 2038d500549bSAnthony Wilson // Add mapping from ledPath to connection 2039d500549bSAnthony Wilson const std::string& connection = object.second.begin()->first; 2040d500549bSAnthony Wilson (*ledConnections)[ledPath] = connection; 2041d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "Added mapping " << ledPath << " -> " 2042d500549bSAnthony Wilson << connection; 2043d500549bSAnthony Wilson } 2044d500549bSAnthony Wilson } 2045d500549bSAnthony Wilson 2046d500549bSAnthony Wilson getInventoryLedData(sensorsAsyncResp, inventoryItems, ledConnections, 2047d500549bSAnthony Wilson std::move(callback)); 2048d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLeds respHandler exit"; 2049d500549bSAnthony Wilson }; 2050d500549bSAnthony Wilson // Make call to ObjectMapper to find all inventory items 2051d500549bSAnthony Wilson crow::connections::systemBus->async_method_call( 2052d500549bSAnthony Wilson std::move(respHandler), "xyz.openbmc_project.ObjectMapper", 2053d500549bSAnthony Wilson "/xyz/openbmc_project/object_mapper", 2054d500549bSAnthony Wilson "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 0, interfaces); 2055d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryLeds exit"; 2056d500549bSAnthony Wilson } 2057d500549bSAnthony Wilson 2058d500549bSAnthony Wilson /** 205942cbe538SGunnar Mills * @brief Gets D-Bus data for Power Supply Attributes such as EfficiencyPercent 206042cbe538SGunnar Mills * 206142cbe538SGunnar Mills * Uses the specified connections (services) (currently assumes just one) to 206242cbe538SGunnar Mills * obtain D-Bus data for Power Supply Attributes. Stores the resulting data in 206342cbe538SGunnar Mills * the inventoryItems vector. Only stores data in Power Supply inventoryItems. 206442cbe538SGunnar Mills * 206542cbe538SGunnar Mills * This data is later used to provide sensor property values in the JSON 206642cbe538SGunnar Mills * response. 206742cbe538SGunnar Mills * 206842cbe538SGunnar Mills * Finds the Power Supply Attributes data asynchronously. Invokes callback 206942cbe538SGunnar Mills * when data has been obtained. 207042cbe538SGunnar Mills * 207142cbe538SGunnar Mills * The callback must have the following signature: 207242cbe538SGunnar Mills * @code 207342cbe538SGunnar Mills * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) 207442cbe538SGunnar Mills * @endcode 207542cbe538SGunnar Mills * 207642cbe538SGunnar Mills * @param sensorsAsyncResp Pointer to object holding response data. 207742cbe538SGunnar Mills * @param inventoryItems D-Bus inventory items associated with sensors. 207842cbe538SGunnar Mills * @param psAttributesConnections Connections that provide data for the Power 207942cbe538SGunnar Mills * Supply Attributes 208042cbe538SGunnar Mills * @param callback Callback to invoke when data has been obtained. 208142cbe538SGunnar Mills */ 208242cbe538SGunnar Mills template <typename Callback> 208342cbe538SGunnar Mills void getPowerSupplyAttributesData( 2084b5a76932SEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 208542cbe538SGunnar Mills std::shared_ptr<std::vector<InventoryItem>> inventoryItems, 208642cbe538SGunnar Mills const boost::container::flat_map<std::string, std::string>& 208742cbe538SGunnar Mills psAttributesConnections, 208842cbe538SGunnar Mills Callback&& callback) 208942cbe538SGunnar Mills { 209042cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData enter"; 209142cbe538SGunnar Mills 209242cbe538SGunnar Mills if (psAttributesConnections.empty()) 209342cbe538SGunnar Mills { 209442cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "Can't find PowerSupplyAttributes, no connections!"; 209542cbe538SGunnar Mills callback(inventoryItems); 209642cbe538SGunnar Mills return; 209742cbe538SGunnar Mills } 209842cbe538SGunnar Mills 209942cbe538SGunnar Mills // Assuming just one connection (service) for now 210042cbe538SGunnar Mills auto it = psAttributesConnections.nth(0); 210142cbe538SGunnar Mills 210242cbe538SGunnar Mills const std::string& psAttributesPath = (*it).first; 210342cbe538SGunnar Mills const std::string& psAttributesConnection = (*it).second; 210442cbe538SGunnar Mills 210542cbe538SGunnar Mills // Response handler for Get DeratingFactor property 210642cbe538SGunnar Mills auto respHandler = [sensorsAsyncResp, inventoryItems, 210742cbe538SGunnar Mills callback{std::move(callback)}]( 210842cbe538SGunnar Mills const boost::system::error_code ec, 210942cbe538SGunnar Mills const std::variant<uint32_t>& deratingFactor) { 211042cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler enter"; 211142cbe538SGunnar Mills if (ec) 211242cbe538SGunnar Mills { 211342cbe538SGunnar Mills BMCWEB_LOG_ERROR 211442cbe538SGunnar Mills << "getPowerSupplyAttributesData respHandler DBus error " << ec; 211542cbe538SGunnar Mills messages::internalError(sensorsAsyncResp->res); 211642cbe538SGunnar Mills return; 211742cbe538SGunnar Mills } 211842cbe538SGunnar Mills 211942cbe538SGunnar Mills const uint32_t* value = std::get_if<uint32_t>(&deratingFactor); 212042cbe538SGunnar Mills if (value != nullptr) 212142cbe538SGunnar Mills { 212242cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "PS EfficiencyPercent value: " << *value; 212342cbe538SGunnar Mills // Store value in Power Supply Inventory Items 212442cbe538SGunnar Mills for (InventoryItem& inventoryItem : *inventoryItems) 212542cbe538SGunnar Mills { 212642cbe538SGunnar Mills if (inventoryItem.isPowerSupply == true) 212742cbe538SGunnar Mills { 212842cbe538SGunnar Mills inventoryItem.powerSupplyEfficiencyPercent = 212942cbe538SGunnar Mills static_cast<int>(*value); 213042cbe538SGunnar Mills } 213142cbe538SGunnar Mills } 213242cbe538SGunnar Mills } 213342cbe538SGunnar Mills else 213442cbe538SGunnar Mills { 213542cbe538SGunnar Mills BMCWEB_LOG_DEBUG 213642cbe538SGunnar Mills << "Failed to find EfficiencyPercent value for PowerSupplies"; 213742cbe538SGunnar Mills } 213842cbe538SGunnar Mills 213942cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler exit"; 214042cbe538SGunnar Mills callback(inventoryItems); 214142cbe538SGunnar Mills }; 214242cbe538SGunnar Mills 214342cbe538SGunnar Mills // Get the DeratingFactor property for the PowerSupplyAttributes 214442cbe538SGunnar Mills // Currently only property on the interface/only one we care about 214542cbe538SGunnar Mills crow::connections::systemBus->async_method_call( 214642cbe538SGunnar Mills std::move(respHandler), psAttributesConnection, psAttributesPath, 214742cbe538SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 214842cbe538SGunnar Mills "xyz.openbmc_project.Control.PowerSupplyAttributes", "DeratingFactor"); 214942cbe538SGunnar Mills 215042cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData exit"; 215142cbe538SGunnar Mills } 215242cbe538SGunnar Mills 215342cbe538SGunnar Mills /** 215442cbe538SGunnar Mills * @brief Gets the Power Supply Attributes such as EfficiencyPercent 215542cbe538SGunnar Mills * 215642cbe538SGunnar Mills * Gets the D-Bus connection (service) that provides Power Supply Attributes 215742cbe538SGunnar Mills * data. Then gets the Power Supply Attributes data from the connection 215842cbe538SGunnar Mills * (currently just assumes 1 connection) and stores the data in the inventory 215942cbe538SGunnar Mills * item. 216042cbe538SGunnar Mills * 216142cbe538SGunnar Mills * This data is later used to provide sensor property values in the JSON 216242cbe538SGunnar Mills * response. DeratingFactor on D-Bus is mapped to EfficiencyPercent on Redfish. 216342cbe538SGunnar Mills * 216442cbe538SGunnar Mills * Finds the Power Supply Attributes data asynchronously. Invokes callback 216542cbe538SGunnar Mills * when information has been obtained. 216642cbe538SGunnar Mills * 216742cbe538SGunnar Mills * The callback must have the following signature: 216842cbe538SGunnar Mills * @code 216942cbe538SGunnar Mills * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) 217042cbe538SGunnar Mills * @endcode 217142cbe538SGunnar Mills * 217242cbe538SGunnar Mills * @param sensorsAsyncResp Pointer to object holding response data. 217342cbe538SGunnar Mills * @param inventoryItems D-Bus inventory items associated with sensors. 217442cbe538SGunnar Mills * @param callback Callback to invoke when data has been obtained. 217542cbe538SGunnar Mills */ 217642cbe538SGunnar Mills template <typename Callback> 217742cbe538SGunnar Mills void getPowerSupplyAttributes( 217842cbe538SGunnar Mills std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, 217942cbe538SGunnar Mills std::shared_ptr<std::vector<InventoryItem>> inventoryItems, 218042cbe538SGunnar Mills Callback&& callback) 218142cbe538SGunnar Mills { 218242cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes enter"; 218342cbe538SGunnar Mills 218442cbe538SGunnar Mills // Only need the power supply attributes when the Power Schema 2185a0ec28b6SAdrian Ambrożewicz if (sensorsAsyncResp->chassisSubNode != sensors::node::power) 218642cbe538SGunnar Mills { 218742cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes exit since not Power"; 218842cbe538SGunnar Mills callback(inventoryItems); 218942cbe538SGunnar Mills return; 219042cbe538SGunnar Mills } 219142cbe538SGunnar Mills 219242cbe538SGunnar Mills const std::array<std::string, 1> interfaces = { 219342cbe538SGunnar Mills "xyz.openbmc_project.Control.PowerSupplyAttributes"}; 219442cbe538SGunnar Mills 219542cbe538SGunnar Mills // Response handler for parsing output from GetSubTree 219642cbe538SGunnar Mills auto respHandler = [callback{std::move(callback)}, sensorsAsyncResp, 219742cbe538SGunnar Mills inventoryItems](const boost::system::error_code ec, 219842cbe538SGunnar Mills const GetSubTreeType& subtree) { 219942cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes respHandler enter"; 220042cbe538SGunnar Mills if (ec) 220142cbe538SGunnar Mills { 220242cbe538SGunnar Mills messages::internalError(sensorsAsyncResp->res); 220342cbe538SGunnar Mills BMCWEB_LOG_ERROR 220442cbe538SGunnar Mills << "getPowerSupplyAttributes respHandler DBus error " << ec; 220542cbe538SGunnar Mills return; 220642cbe538SGunnar Mills } 220742cbe538SGunnar Mills if (subtree.size() == 0) 220842cbe538SGunnar Mills { 220942cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "Can't find Power Supply Attributes!"; 221042cbe538SGunnar Mills callback(inventoryItems); 221142cbe538SGunnar Mills return; 221242cbe538SGunnar Mills } 221342cbe538SGunnar Mills 221442cbe538SGunnar Mills // Currently we only support 1 power supply attribute, use this for 221542cbe538SGunnar Mills // all the power supplies. Build map of object path to connection. 221642cbe538SGunnar Mills // Assume just 1 connection and 1 path for now. 221742cbe538SGunnar Mills boost::container::flat_map<std::string, std::string> 221842cbe538SGunnar Mills psAttributesConnections; 221942cbe538SGunnar Mills 222042cbe538SGunnar Mills if (subtree[0].first.empty() || subtree[0].second.empty()) 222142cbe538SGunnar Mills { 222242cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "Power Supply Attributes mapper error!"; 222342cbe538SGunnar Mills callback(inventoryItems); 222442cbe538SGunnar Mills return; 222542cbe538SGunnar Mills } 222642cbe538SGunnar Mills 222742cbe538SGunnar Mills const std::string& psAttributesPath = subtree[0].first; 222842cbe538SGunnar Mills const std::string& connection = subtree[0].second.begin()->first; 222942cbe538SGunnar Mills 223042cbe538SGunnar Mills if (connection.empty()) 223142cbe538SGunnar Mills { 223242cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "Power Supply Attributes mapper error!"; 223342cbe538SGunnar Mills callback(inventoryItems); 223442cbe538SGunnar Mills return; 223542cbe538SGunnar Mills } 223642cbe538SGunnar Mills 223742cbe538SGunnar Mills psAttributesConnections[psAttributesPath] = connection; 223842cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "Added mapping " << psAttributesPath << " -> " 223942cbe538SGunnar Mills << connection; 224042cbe538SGunnar Mills 224142cbe538SGunnar Mills getPowerSupplyAttributesData(sensorsAsyncResp, inventoryItems, 224242cbe538SGunnar Mills psAttributesConnections, 224342cbe538SGunnar Mills std::move(callback)); 224442cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes respHandler exit"; 224542cbe538SGunnar Mills }; 224642cbe538SGunnar Mills // Make call to ObjectMapper to find the PowerSupplyAttributes service 224742cbe538SGunnar Mills crow::connections::systemBus->async_method_call( 224842cbe538SGunnar Mills std::move(respHandler), "xyz.openbmc_project.ObjectMapper", 224942cbe538SGunnar Mills "/xyz/openbmc_project/object_mapper", 225042cbe538SGunnar Mills "xyz.openbmc_project.ObjectMapper", "GetSubTree", 225142cbe538SGunnar Mills "/xyz/openbmc_project", 0, interfaces); 225242cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes exit"; 225342cbe538SGunnar Mills } 225442cbe538SGunnar Mills 225542cbe538SGunnar Mills /** 2256adc4f0dbSShawn McCarney * @brief Gets inventory items associated with sensors. 22578fb49dd6SShawn McCarney * 22588fb49dd6SShawn McCarney * Finds the inventory items that are associated with the specified sensors. 2259adc4f0dbSShawn McCarney * Then gets D-Bus data for the inventory items, such as presence and VPD. 22608fb49dd6SShawn McCarney * 2261adc4f0dbSShawn McCarney * This data is later used to provide sensor property values in the JSON 2262adc4f0dbSShawn McCarney * response. 22638fb49dd6SShawn McCarney * 2264adc4f0dbSShawn McCarney * Finds the inventory items asynchronously. Invokes callback when the 2265adc4f0dbSShawn McCarney * inventory items have been obtained. 2266adc4f0dbSShawn McCarney * 2267adc4f0dbSShawn McCarney * The callback must have the following signature: 2268adc4f0dbSShawn McCarney * @code 2269adc4f0dbSShawn McCarney * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) 2270adc4f0dbSShawn McCarney * @endcode 22718fb49dd6SShawn McCarney * 22728fb49dd6SShawn McCarney * @param sensorsAsyncResp Pointer to object holding response data. 22738fb49dd6SShawn McCarney * @param sensorNames All sensors within the current chassis. 22748fb49dd6SShawn McCarney * @param objectMgrPaths Mappings from connection name to DBus object path that 22758fb49dd6SShawn McCarney * implements ObjectManager. 2276adc4f0dbSShawn McCarney * @param callback Callback to invoke when inventory items have been obtained. 22778fb49dd6SShawn McCarney */ 2278adc4f0dbSShawn McCarney template <typename Callback> 2279adc4f0dbSShawn McCarney static void getInventoryItems( 22808fb49dd6SShawn McCarney std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, 22818fb49dd6SShawn McCarney const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames, 22828fb49dd6SShawn McCarney std::shared_ptr<boost::container::flat_map<std::string, std::string>> 2283adc4f0dbSShawn McCarney objectMgrPaths, 2284adc4f0dbSShawn McCarney Callback&& callback) 22858fb49dd6SShawn McCarney { 2286adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItems enter"; 2287adc4f0dbSShawn McCarney auto getInventoryItemAssociationsCb = 2288adc4f0dbSShawn McCarney [sensorsAsyncResp, objectMgrPaths, callback{std::move(callback)}]( 2289adc4f0dbSShawn McCarney std::shared_ptr<std::vector<InventoryItem>> inventoryItems) { 2290adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb enter"; 22918fb49dd6SShawn McCarney auto getInventoryItemsConnectionsCb = 2292adc4f0dbSShawn McCarney [sensorsAsyncResp, inventoryItems, objectMgrPaths, 2293adc4f0dbSShawn McCarney callback{std::move(callback)}]( 22948fb49dd6SShawn McCarney std::shared_ptr<boost::container::flat_set<std::string>> 22958fb49dd6SShawn McCarney invConnections) { 22968fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb enter"; 2297d500549bSAnthony Wilson auto getInventoryItemsDataCb = 2298d500549bSAnthony Wilson [sensorsAsyncResp, inventoryItems, 2299d500549bSAnthony Wilson callback{std::move(callback)}]() { 2300d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryItemsDataCb enter"; 230142cbe538SGunnar Mills 230242cbe538SGunnar Mills auto getInventoryLedsCb = [sensorsAsyncResp, 230342cbe538SGunnar Mills inventoryItems, 230442cbe538SGunnar Mills callback{std::move( 230542cbe538SGunnar Mills callback)}]() { 230642cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getInventoryLedsCb enter"; 230742cbe538SGunnar Mills // Find Power Supply Attributes and get the data 230842cbe538SGunnar Mills getPowerSupplyAttributes(sensorsAsyncResp, 230942cbe538SGunnar Mills inventoryItems, 231042cbe538SGunnar Mills std::move(callback)); 231142cbe538SGunnar Mills BMCWEB_LOG_DEBUG << "getInventoryLedsCb exit"; 231242cbe538SGunnar Mills }; 231342cbe538SGunnar Mills 2314d500549bSAnthony Wilson // Find led connections and get the data 2315d500549bSAnthony Wilson getInventoryLeds(sensorsAsyncResp, inventoryItems, 231642cbe538SGunnar Mills std::move(getInventoryLedsCb)); 2317d500549bSAnthony Wilson BMCWEB_LOG_DEBUG << "getInventoryItemsDataCb exit"; 2318d500549bSAnthony Wilson }; 23198fb49dd6SShawn McCarney 2320adc4f0dbSShawn McCarney // Get inventory item data from connections 2321adc4f0dbSShawn McCarney getInventoryItemsData(sensorsAsyncResp, inventoryItems, 2322adc4f0dbSShawn McCarney invConnections, objectMgrPaths, 2323d500549bSAnthony Wilson std::move(getInventoryItemsDataCb)); 23248fb49dd6SShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb exit"; 23258fb49dd6SShawn McCarney }; 23268fb49dd6SShawn McCarney 2327adc4f0dbSShawn McCarney // Get connections that provide inventory item data 23288fb49dd6SShawn McCarney getInventoryItemsConnections( 2329adc4f0dbSShawn McCarney sensorsAsyncResp, inventoryItems, 23308fb49dd6SShawn McCarney std::move(getInventoryItemsConnectionsCb)); 2331adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb exit"; 23328fb49dd6SShawn McCarney }; 23338fb49dd6SShawn McCarney 2334adc4f0dbSShawn McCarney // Get associations from sensors to inventory items 2335adc4f0dbSShawn McCarney getInventoryItemAssociations(sensorsAsyncResp, sensorNames, objectMgrPaths, 2336adc4f0dbSShawn McCarney std::move(getInventoryItemAssociationsCb)); 2337adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItems exit"; 2338adc4f0dbSShawn McCarney } 2339adc4f0dbSShawn McCarney 2340adc4f0dbSShawn McCarney /** 2341adc4f0dbSShawn McCarney * @brief Returns JSON PowerSupply object for the specified inventory item. 2342adc4f0dbSShawn McCarney * 2343adc4f0dbSShawn McCarney * Searches for a JSON PowerSupply object that matches the specified inventory 2344adc4f0dbSShawn McCarney * item. If one is not found, a new PowerSupply object is added to the JSON 2345adc4f0dbSShawn McCarney * array. 2346adc4f0dbSShawn McCarney * 2347adc4f0dbSShawn McCarney * Multiple sensors are often associated with one power supply inventory item. 2348adc4f0dbSShawn McCarney * As a result, multiple sensor values are stored in one JSON PowerSupply 2349adc4f0dbSShawn McCarney * object. 2350adc4f0dbSShawn McCarney * 2351adc4f0dbSShawn McCarney * @param powerSupplyArray JSON array containing Redfish PowerSupply objects. 2352adc4f0dbSShawn McCarney * @param inventoryItem Inventory item for the power supply. 2353adc4f0dbSShawn McCarney * @param chassisId Chassis that contains the power supply. 2354adc4f0dbSShawn McCarney * @return JSON PowerSupply object for the specified inventory item. 2355adc4f0dbSShawn McCarney */ 235623a21a1cSEd Tanous inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray, 2357adc4f0dbSShawn McCarney const InventoryItem& inventoryItem, 2358adc4f0dbSShawn McCarney const std::string& chassisId) 2359adc4f0dbSShawn McCarney { 2360adc4f0dbSShawn McCarney // Check if matching PowerSupply object already exists in JSON array 2361adc4f0dbSShawn McCarney for (nlohmann::json& powerSupply : powerSupplyArray) 2362adc4f0dbSShawn McCarney { 2363adc4f0dbSShawn McCarney if (powerSupply["MemberId"] == inventoryItem.name) 2364adc4f0dbSShawn McCarney { 2365adc4f0dbSShawn McCarney return powerSupply; 2366adc4f0dbSShawn McCarney } 2367adc4f0dbSShawn McCarney } 2368adc4f0dbSShawn McCarney 2369adc4f0dbSShawn McCarney // Add new PowerSupply object to JSON array 2370adc4f0dbSShawn McCarney powerSupplyArray.push_back({}); 2371adc4f0dbSShawn McCarney nlohmann::json& powerSupply = powerSupplyArray.back(); 2372adc4f0dbSShawn McCarney powerSupply["@odata.id"] = 2373adc4f0dbSShawn McCarney "/redfish/v1/Chassis/" + chassisId + "/Power#/PowerSupplies/"; 2374adc4f0dbSShawn McCarney powerSupply["MemberId"] = inventoryItem.name; 2375adc4f0dbSShawn McCarney powerSupply["Name"] = boost::replace_all_copy(inventoryItem.name, "_", " "); 2376adc4f0dbSShawn McCarney powerSupply["Manufacturer"] = inventoryItem.manufacturer; 2377adc4f0dbSShawn McCarney powerSupply["Model"] = inventoryItem.model; 2378adc4f0dbSShawn McCarney powerSupply["PartNumber"] = inventoryItem.partNumber; 2379adc4f0dbSShawn McCarney powerSupply["SerialNumber"] = inventoryItem.serialNumber; 2380d500549bSAnthony Wilson setLedState(powerSupply, &inventoryItem); 2381adc4f0dbSShawn McCarney 238242cbe538SGunnar Mills if (inventoryItem.powerSupplyEfficiencyPercent >= 0) 238342cbe538SGunnar Mills { 238442cbe538SGunnar Mills powerSupply["EfficiencyPercent"] = 238542cbe538SGunnar Mills inventoryItem.powerSupplyEfficiencyPercent; 238642cbe538SGunnar Mills } 238742cbe538SGunnar Mills 238842cbe538SGunnar Mills powerSupply["Status"]["State"] = getState(&inventoryItem); 2389adc4f0dbSShawn McCarney const char* health = inventoryItem.isFunctional ? "OK" : "Critical"; 2390adc4f0dbSShawn McCarney powerSupply["Status"]["Health"] = health; 2391adc4f0dbSShawn McCarney 2392adc4f0dbSShawn McCarney return powerSupply; 23938fb49dd6SShawn McCarney } 23948fb49dd6SShawn McCarney 23958fb49dd6SShawn McCarney /** 2396de629b6eSShawn McCarney * @brief Gets the values of the specified sensors. 2397de629b6eSShawn McCarney * 2398de629b6eSShawn McCarney * Stores the results as JSON in the SensorsAsyncResp. 2399de629b6eSShawn McCarney * 2400de629b6eSShawn McCarney * Gets the sensor values asynchronously. Stores the results later when the 2401de629b6eSShawn McCarney * information has been obtained. 2402de629b6eSShawn McCarney * 2403adc4f0dbSShawn McCarney * The sensorNames set contains all requested sensors for the current chassis. 2404de629b6eSShawn McCarney * 2405de629b6eSShawn McCarney * To minimize the number of DBus calls, the DBus method 2406de629b6eSShawn McCarney * org.freedesktop.DBus.ObjectManager.GetManagedObjects() is used to get the 2407de629b6eSShawn McCarney * values of all sensors provided by a connection (service). 2408de629b6eSShawn McCarney * 2409de629b6eSShawn McCarney * The connections set contains all the connections that provide sensor values. 2410de629b6eSShawn McCarney * 2411de629b6eSShawn McCarney * The objectMgrPaths map contains mappings from a connection name to the 2412de629b6eSShawn McCarney * corresponding DBus object path that implements ObjectManager. 2413de629b6eSShawn McCarney * 2414adc4f0dbSShawn McCarney * The InventoryItem vector contains D-Bus inventory items associated with the 2415adc4f0dbSShawn McCarney * sensors. Inventory item data is needed for some Redfish sensor properties. 2416adc4f0dbSShawn McCarney * 2417de629b6eSShawn McCarney * @param SensorsAsyncResp Pointer to object holding response data. 2418adc4f0dbSShawn McCarney * @param sensorNames All requested sensors within the current chassis. 2419de629b6eSShawn McCarney * @param connections Connections that provide sensor values. 2420de629b6eSShawn McCarney * @param objectMgrPaths Mappings from connection name to DBus object path that 2421de629b6eSShawn McCarney * implements ObjectManager. 2422adc4f0dbSShawn McCarney * @param inventoryItems Inventory items associated with the sensors. 2423de629b6eSShawn McCarney */ 242423a21a1cSEd Tanous inline void getSensorData( 242581ce609eSEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 2426b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames, 2427de629b6eSShawn McCarney const boost::container::flat_set<std::string>& connections, 2428b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_map<std::string, std::string>>& 2429adc4f0dbSShawn McCarney objectMgrPaths, 2430b5a76932SEd Tanous const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems) 2431de629b6eSShawn McCarney { 2432de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getSensorData enter"; 2433de629b6eSShawn McCarney // Get managed objects from all services exposing sensors 2434de629b6eSShawn McCarney for (const std::string& connection : connections) 2435de629b6eSShawn McCarney { 2436de629b6eSShawn McCarney // Response handler to process managed objects 243781ce609eSEd Tanous auto getManagedObjectsCb = [sensorsAsyncResp, sensorNames, 2438adc4f0dbSShawn McCarney inventoryItems]( 2439de629b6eSShawn McCarney const boost::system::error_code ec, 2440de629b6eSShawn McCarney ManagedObjectsVectorType& resp) { 2441de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getManagedObjectsCb enter"; 2442de629b6eSShawn McCarney if (ec) 2443de629b6eSShawn McCarney { 2444de629b6eSShawn McCarney BMCWEB_LOG_ERROR << "getManagedObjectsCb DBUS error: " << ec; 244581ce609eSEd Tanous messages::internalError(sensorsAsyncResp->res); 2446de629b6eSShawn McCarney return; 2447de629b6eSShawn McCarney } 2448de629b6eSShawn McCarney // Go through all objects and update response with sensor data 2449de629b6eSShawn McCarney for (const auto& objDictEntry : resp) 2450de629b6eSShawn McCarney { 2451de629b6eSShawn McCarney const std::string& objPath = 2452de629b6eSShawn McCarney static_cast<const std::string&>(objDictEntry.first); 2453de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getManagedObjectsCb parsing object " 2454de629b6eSShawn McCarney << objPath; 2455de629b6eSShawn McCarney 2456de629b6eSShawn McCarney std::vector<std::string> split; 2457de629b6eSShawn McCarney // Reserve space for 2458de629b6eSShawn McCarney // /xyz/openbmc_project/sensors/<name>/<subname> 2459de629b6eSShawn McCarney split.reserve(6); 2460de629b6eSShawn McCarney boost::algorithm::split(split, objPath, boost::is_any_of("/")); 2461de629b6eSShawn McCarney if (split.size() < 6) 2462de629b6eSShawn McCarney { 2463de629b6eSShawn McCarney BMCWEB_LOG_ERROR << "Got path that isn't long enough " 2464de629b6eSShawn McCarney << objPath; 2465de629b6eSShawn McCarney continue; 2466de629b6eSShawn McCarney } 2467de629b6eSShawn McCarney // These indexes aren't intuitive, as boost::split puts an empty 2468de629b6eSShawn McCarney // string at the beginning 2469de629b6eSShawn McCarney const std::string& sensorType = split[4]; 2470de629b6eSShawn McCarney const std::string& sensorName = split[5]; 2471de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "sensorName " << sensorName 2472de629b6eSShawn McCarney << " sensorType " << sensorType; 247349c53ac9SJohnathan Mantey if (sensorNames->find(objPath) == sensorNames->end()) 2474de629b6eSShawn McCarney { 2475de629b6eSShawn McCarney BMCWEB_LOG_ERROR << sensorName << " not in sensor list "; 2476de629b6eSShawn McCarney continue; 2477de629b6eSShawn McCarney } 2478de629b6eSShawn McCarney 2479adc4f0dbSShawn McCarney // Find inventory item (if any) associated with sensor 2480adc4f0dbSShawn McCarney InventoryItem* inventoryItem = 2481adc4f0dbSShawn McCarney findInventoryItemForSensor(inventoryItems, objPath); 2482adc4f0dbSShawn McCarney 248395a3ecadSAnthony Wilson const std::string& sensorSchema = 248481ce609eSEd Tanous sensorsAsyncResp->chassisSubNode; 248595a3ecadSAnthony Wilson 248695a3ecadSAnthony Wilson nlohmann::json* sensorJson = nullptr; 248795a3ecadSAnthony Wilson 2488a0ec28b6SAdrian Ambrożewicz if (sensorSchema == sensors::node::sensors) 248995a3ecadSAnthony Wilson { 249081ce609eSEd Tanous sensorsAsyncResp->res.jsonValue["@odata.id"] = 249181ce609eSEd Tanous "/redfish/v1/Chassis/" + sensorsAsyncResp->chassisId + 249281ce609eSEd Tanous "/" + sensorsAsyncResp->chassisSubNode + "/" + 249395a3ecadSAnthony Wilson sensorName; 249481ce609eSEd Tanous sensorJson = &(sensorsAsyncResp->res.jsonValue); 249595a3ecadSAnthony Wilson } 249695a3ecadSAnthony Wilson else 249795a3ecadSAnthony Wilson { 2498271584abSEd Tanous std::string fieldName; 2499de629b6eSShawn McCarney if (sensorType == "temperature") 2500de629b6eSShawn McCarney { 2501de629b6eSShawn McCarney fieldName = "Temperatures"; 2502de629b6eSShawn McCarney } 2503de629b6eSShawn McCarney else if (sensorType == "fan" || sensorType == "fan_tach" || 2504de629b6eSShawn McCarney sensorType == "fan_pwm") 2505de629b6eSShawn McCarney { 2506de629b6eSShawn McCarney fieldName = "Fans"; 2507de629b6eSShawn McCarney } 2508de629b6eSShawn McCarney else if (sensorType == "voltage") 2509de629b6eSShawn McCarney { 2510de629b6eSShawn McCarney fieldName = "Voltages"; 2511de629b6eSShawn McCarney } 2512de629b6eSShawn McCarney else if (sensorType == "power") 2513de629b6eSShawn McCarney { 2514028f7ebcSEddie James if (!sensorName.compare("total_power")) 2515028f7ebcSEddie James { 2516028f7ebcSEddie James fieldName = "PowerControl"; 2517028f7ebcSEddie James } 2518adc4f0dbSShawn McCarney else if ((inventoryItem != nullptr) && 2519adc4f0dbSShawn McCarney (inventoryItem->isPowerSupply)) 2520028f7ebcSEddie James { 2521de629b6eSShawn McCarney fieldName = "PowerSupplies"; 2522de629b6eSShawn McCarney } 2523adc4f0dbSShawn McCarney else 2524adc4f0dbSShawn McCarney { 2525adc4f0dbSShawn McCarney // Other power sensors are in SensorCollection 2526adc4f0dbSShawn McCarney continue; 2527adc4f0dbSShawn McCarney } 2528028f7ebcSEddie James } 2529de629b6eSShawn McCarney else 2530de629b6eSShawn McCarney { 2531de629b6eSShawn McCarney BMCWEB_LOG_ERROR << "Unsure how to handle sensorType " 2532de629b6eSShawn McCarney << sensorType; 2533de629b6eSShawn McCarney continue; 2534de629b6eSShawn McCarney } 2535de629b6eSShawn McCarney 2536de629b6eSShawn McCarney nlohmann::json& tempArray = 253781ce609eSEd Tanous sensorsAsyncResp->res.jsonValue[fieldName]; 2538adc4f0dbSShawn McCarney if (fieldName == "PowerControl") 253949c53ac9SJohnathan Mantey { 2540adc4f0dbSShawn McCarney if (tempArray.empty()) 25417ab06f49SGunnar Mills { 254295a3ecadSAnthony Wilson // Put multiple "sensors" into a single 254395a3ecadSAnthony Wilson // PowerControl. Follows MemberId naming and 254495a3ecadSAnthony Wilson // naming in power.hpp. 25457ab06f49SGunnar Mills tempArray.push_back( 2546adc4f0dbSShawn McCarney {{"@odata.id", 2547adc4f0dbSShawn McCarney "/redfish/v1/Chassis/" + 254881ce609eSEd Tanous sensorsAsyncResp->chassisId + "/" + 254981ce609eSEd Tanous sensorsAsyncResp->chassisSubNode + "#/" + 2550adc4f0dbSShawn McCarney fieldName + "/0"}}); 2551adc4f0dbSShawn McCarney } 2552adc4f0dbSShawn McCarney sensorJson = &(tempArray.back()); 2553adc4f0dbSShawn McCarney } 2554adc4f0dbSShawn McCarney else if (fieldName == "PowerSupplies") 2555adc4f0dbSShawn McCarney { 2556adc4f0dbSShawn McCarney if (inventoryItem != nullptr) 2557adc4f0dbSShawn McCarney { 2558adc4f0dbSShawn McCarney sensorJson = 2559adc4f0dbSShawn McCarney &(getPowerSupply(tempArray, *inventoryItem, 256081ce609eSEd Tanous sensorsAsyncResp->chassisId)); 2561adc4f0dbSShawn McCarney } 256249c53ac9SJohnathan Mantey } 256349c53ac9SJohnathan Mantey else 256449c53ac9SJohnathan Mantey { 2565de629b6eSShawn McCarney tempArray.push_back( 256695a3ecadSAnthony Wilson {{"@odata.id", 256795a3ecadSAnthony Wilson "/redfish/v1/Chassis/" + 256881ce609eSEd Tanous sensorsAsyncResp->chassisId + "/" + 256981ce609eSEd Tanous sensorsAsyncResp->chassisSubNode + "#/" + 257095a3ecadSAnthony Wilson fieldName + "/"}}); 2571adc4f0dbSShawn McCarney sensorJson = &(tempArray.back()); 257249c53ac9SJohnathan Mantey } 257395a3ecadSAnthony Wilson } 2574de629b6eSShawn McCarney 2575adc4f0dbSShawn McCarney if (sensorJson != nullptr) 2576adc4f0dbSShawn McCarney { 2577a0ec28b6SAdrian Ambrożewicz objectInterfacesToJson( 257881ce609eSEd Tanous sensorName, sensorType, sensorsAsyncResp, 2579a0ec28b6SAdrian Ambrożewicz objDictEntry.second, *sensorJson, inventoryItem); 2580adc4f0dbSShawn McCarney } 2581de629b6eSShawn McCarney } 258281ce609eSEd Tanous if (sensorsAsyncResp.use_count() == 1) 258349c53ac9SJohnathan Mantey { 258481ce609eSEd Tanous sortJSONResponse(sensorsAsyncResp); 258581ce609eSEd Tanous if (sensorsAsyncResp->chassisSubNode == sensors::node::thermal) 25868bd25ccdSJames Feist { 258781ce609eSEd Tanous populateFanRedundancy(sensorsAsyncResp); 25888bd25ccdSJames Feist } 258949c53ac9SJohnathan Mantey } 2590de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getManagedObjectsCb exit"; 2591de629b6eSShawn McCarney }; 2592de629b6eSShawn McCarney 2593de629b6eSShawn McCarney // Find DBus object path that implements ObjectManager for the current 2594de629b6eSShawn McCarney // connection. If no mapping found, default to "/". 25958fb49dd6SShawn McCarney auto iter = objectMgrPaths->find(connection); 2596de629b6eSShawn McCarney const std::string& objectMgrPath = 25978fb49dd6SShawn McCarney (iter != objectMgrPaths->end()) ? iter->second : "/"; 2598de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is " 2599de629b6eSShawn McCarney << objectMgrPath; 2600de629b6eSShawn McCarney 2601de629b6eSShawn McCarney crow::connections::systemBus->async_method_call( 2602de629b6eSShawn McCarney getManagedObjectsCb, connection, objectMgrPath, 2603de629b6eSShawn McCarney "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 260423a21a1cSEd Tanous } 2605de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getSensorData exit"; 2606de629b6eSShawn McCarney } 2607de629b6eSShawn McCarney 260823a21a1cSEd Tanous inline void processSensorList( 260981ce609eSEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, 2610b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames) 26111abe55efSEd Tanous { 261295a3ecadSAnthony Wilson auto getConnectionCb = 261381ce609eSEd Tanous [sensorsAsyncResp, sensorNames]( 261495a3ecadSAnthony Wilson const boost::container::flat_set<std::string>& connections) { 261555c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "getConnectionCb enter"; 2616de629b6eSShawn McCarney auto getObjectManagerPathsCb = 261781ce609eSEd Tanous [sensorsAsyncResp, sensorNames, 2618b5a76932SEd Tanous connections](const std::shared_ptr<boost::container::flat_map< 2619b5a76932SEd Tanous std::string, std::string>>& objectMgrPaths) { 2620de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb enter"; 2621adc4f0dbSShawn McCarney auto getInventoryItemsCb = 262281ce609eSEd Tanous [sensorsAsyncResp, sensorNames, connections, 2623adc4f0dbSShawn McCarney objectMgrPaths]( 2624f23b7296SEd Tanous const std::shared_ptr<std::vector<InventoryItem>>& 2625adc4f0dbSShawn McCarney inventoryItems) { 2626adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsCb enter"; 262749c53ac9SJohnathan Mantey // Get sensor data and store results in JSON 262881ce609eSEd Tanous getSensorData(sensorsAsyncResp, sensorNames, 2629adc4f0dbSShawn McCarney connections, objectMgrPaths, 2630f23b7296SEd Tanous inventoryItems); 2631adc4f0dbSShawn McCarney BMCWEB_LOG_DEBUG << "getInventoryItemsCb exit"; 2632adc4f0dbSShawn McCarney }; 2633adc4f0dbSShawn McCarney 2634adc4f0dbSShawn McCarney // Get inventory items associated with sensors 263581ce609eSEd Tanous getInventoryItems(sensorsAsyncResp, sensorNames, 2636adc4f0dbSShawn McCarney objectMgrPaths, 2637adc4f0dbSShawn McCarney std::move(getInventoryItemsCb)); 2638adc4f0dbSShawn McCarney 2639de629b6eSShawn McCarney BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb exit"; 264008777fb0SLewanczyk, Dawid }; 2641de629b6eSShawn McCarney 264249c53ac9SJohnathan Mantey // Get mapping from connection names to the DBus object 264349c53ac9SJohnathan Mantey // paths that implement the ObjectManager interface 264481ce609eSEd Tanous getObjectManagerPaths(sensorsAsyncResp, 2645de629b6eSShawn McCarney std::move(getObjectManagerPathsCb)); 264655c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "getConnectionCb exit"; 264708777fb0SLewanczyk, Dawid }; 2648de629b6eSShawn McCarney 2649de629b6eSShawn McCarney // Get set of connections that provide sensor values 265081ce609eSEd Tanous getConnections(sensorsAsyncResp, sensorNames, std::move(getConnectionCb)); 265195a3ecadSAnthony Wilson } 265295a3ecadSAnthony Wilson 265395a3ecadSAnthony Wilson /** 265495a3ecadSAnthony Wilson * @brief Entry point for retrieving sensors data related to requested 265595a3ecadSAnthony Wilson * chassis. 265695a3ecadSAnthony Wilson * @param SensorsAsyncResp Pointer to object holding response data 265795a3ecadSAnthony Wilson */ 2658b5a76932SEd Tanous inline void 265981ce609eSEd Tanous getChassisData(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp) 266095a3ecadSAnthony Wilson { 266195a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "getChassisData enter"; 266295a3ecadSAnthony Wilson auto getChassisCb = 266381ce609eSEd Tanous [sensorsAsyncResp]( 2664f23b7296SEd Tanous const std::shared_ptr<boost::container::flat_set<std::string>>& 266595a3ecadSAnthony Wilson sensorNames) { 266695a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "getChassisCb enter"; 266781ce609eSEd Tanous processSensorList(sensorsAsyncResp, sensorNames); 266855c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "getChassisCb exit"; 266908777fb0SLewanczyk, Dawid }; 267081ce609eSEd Tanous sensorsAsyncResp->res.jsonValue["Redundancy"] = nlohmann::json::array(); 267108777fb0SLewanczyk, Dawid 267226f03899SShawn McCarney // Get set of sensors in chassis 267381ce609eSEd Tanous getChassis(sensorsAsyncResp, std::move(getChassisCb)); 267455c7b7a2SEd Tanous BMCWEB_LOG_DEBUG << "getChassisData exit"; 2675271584abSEd Tanous } 267608777fb0SLewanczyk, Dawid 2677413961deSRichard Marian Thomaiyar /** 267849c53ac9SJohnathan Mantey * @brief Find the requested sensorName in the list of all sensors supplied by 267949c53ac9SJohnathan Mantey * the chassis node 268049c53ac9SJohnathan Mantey * 268149c53ac9SJohnathan Mantey * @param sensorName The sensor name supplied in the PATCH request 268249c53ac9SJohnathan Mantey * @param sensorsList The list of sensors managed by the chassis node 268349c53ac9SJohnathan Mantey * @param sensorsModified The list of sensors that were found as a result of 268449c53ac9SJohnathan Mantey * repeated calls to this function 268549c53ac9SJohnathan Mantey */ 268623a21a1cSEd Tanous inline bool findSensorNameUsingSensorPath( 26870a86febdSRichard Marian Thomaiyar std::string_view sensorName, 268849c53ac9SJohnathan Mantey boost::container::flat_set<std::string>& sensorsList, 268949c53ac9SJohnathan Mantey boost::container::flat_set<std::string>& sensorsModified) 269049c53ac9SJohnathan Mantey { 269128aa8de5SGeorge Liu for (auto& chassisSensor : sensorsList) 269249c53ac9SJohnathan Mantey { 269328aa8de5SGeorge Liu sdbusplus::message::object_path path(chassisSensor); 2694*b00dcc27SEd Tanous std::string thisSensorName = path.filename(); 269528aa8de5SGeorge Liu if (thisSensorName.empty()) 269649c53ac9SJohnathan Mantey { 269749c53ac9SJohnathan Mantey continue; 269849c53ac9SJohnathan Mantey } 269949c53ac9SJohnathan Mantey if (thisSensorName == sensorName) 270049c53ac9SJohnathan Mantey { 270149c53ac9SJohnathan Mantey sensorsModified.emplace(chassisSensor); 270249c53ac9SJohnathan Mantey return true; 270349c53ac9SJohnathan Mantey } 270449c53ac9SJohnathan Mantey } 270549c53ac9SJohnathan Mantey return false; 270649c53ac9SJohnathan Mantey } 270749c53ac9SJohnathan Mantey 270849c53ac9SJohnathan Mantey /** 2709413961deSRichard Marian Thomaiyar * @brief Entry point for overriding sensor values of given sensor 2710413961deSRichard Marian Thomaiyar * 2711413961deSRichard Marian Thomaiyar * @param res response object 27124bb3dc34SCarol Wang * @param allCollections Collections extract from sensors' request patch info 2713413961deSRichard Marian Thomaiyar * @param chassisSubNode Chassis Node for which the query has to happen 2714413961deSRichard Marian Thomaiyar */ 271523a21a1cSEd Tanous inline void setSensorsOverride( 2716b5a76932SEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp, 27174bb3dc34SCarol Wang std::unordered_map<std::string, std::vector<nlohmann::json>>& 2718397fd61fSjayaprakash Mutyala allCollections) 2719413961deSRichard Marian Thomaiyar { 272070d1d0aaSjayaprakash Mutyala BMCWEB_LOG_INFO << "setSensorsOverride for subNode" 27214bb3dc34SCarol Wang << sensorAsyncResp->chassisSubNode << "\n"; 2722413961deSRichard Marian Thomaiyar 2723f65af9e8SRichard Marian Thomaiyar const char* propertyValueName; 2724f65af9e8SRichard Marian Thomaiyar std::unordered_map<std::string, std::pair<double, std::string>> overrideMap; 2725413961deSRichard Marian Thomaiyar std::string memberId; 2726413961deSRichard Marian Thomaiyar double value; 2727f65af9e8SRichard Marian Thomaiyar for (auto& collectionItems : allCollections) 2728f65af9e8SRichard Marian Thomaiyar { 2729f65af9e8SRichard Marian Thomaiyar if (collectionItems.first == "Temperatures") 2730f65af9e8SRichard Marian Thomaiyar { 2731f65af9e8SRichard Marian Thomaiyar propertyValueName = "ReadingCelsius"; 2732f65af9e8SRichard Marian Thomaiyar } 2733f65af9e8SRichard Marian Thomaiyar else if (collectionItems.first == "Fans") 2734f65af9e8SRichard Marian Thomaiyar { 2735f65af9e8SRichard Marian Thomaiyar propertyValueName = "Reading"; 2736f65af9e8SRichard Marian Thomaiyar } 2737f65af9e8SRichard Marian Thomaiyar else 2738f65af9e8SRichard Marian Thomaiyar { 2739f65af9e8SRichard Marian Thomaiyar propertyValueName = "ReadingVolts"; 2740f65af9e8SRichard Marian Thomaiyar } 2741f65af9e8SRichard Marian Thomaiyar for (auto& item : collectionItems.second) 2742f65af9e8SRichard Marian Thomaiyar { 27434bb3dc34SCarol Wang if (!json_util::readJson(item, sensorAsyncResp->res, "MemberId", 27444bb3dc34SCarol Wang memberId, propertyValueName, value)) 2745413961deSRichard Marian Thomaiyar { 2746413961deSRichard Marian Thomaiyar return; 2747413961deSRichard Marian Thomaiyar } 2748f65af9e8SRichard Marian Thomaiyar overrideMap.emplace(memberId, 2749f65af9e8SRichard Marian Thomaiyar std::make_pair(value, collectionItems.first)); 2750f65af9e8SRichard Marian Thomaiyar } 2751f65af9e8SRichard Marian Thomaiyar } 27524bb3dc34SCarol Wang 2753b5a76932SEd Tanous auto getChassisSensorListCb = [sensorAsyncResp, overrideMap]( 2754b5a76932SEd Tanous const std::shared_ptr< 275549c53ac9SJohnathan Mantey boost::container::flat_set< 2756b5a76932SEd Tanous std::string>>& sensorsList) { 275749c53ac9SJohnathan Mantey // Match sensor names in the PATCH request to those managed by the 275849c53ac9SJohnathan Mantey // chassis node 275949c53ac9SJohnathan Mantey const std::shared_ptr<boost::container::flat_set<std::string>> 276049c53ac9SJohnathan Mantey sensorNames = 276149c53ac9SJohnathan Mantey std::make_shared<boost::container::flat_set<std::string>>(); 2762f65af9e8SRichard Marian Thomaiyar for (const auto& item : overrideMap) 2763413961deSRichard Marian Thomaiyar { 2764f65af9e8SRichard Marian Thomaiyar const auto& sensor = item.first; 276549c53ac9SJohnathan Mantey if (!findSensorNameUsingSensorPath(sensor, *sensorsList, 276649c53ac9SJohnathan Mantey *sensorNames)) 2767f65af9e8SRichard Marian Thomaiyar { 2768f65af9e8SRichard Marian Thomaiyar BMCWEB_LOG_INFO << "Unable to find memberId " << item.first; 2769413961deSRichard Marian Thomaiyar messages::resourceNotFound(sensorAsyncResp->res, 2770f65af9e8SRichard Marian Thomaiyar item.second.second, item.first); 2771413961deSRichard Marian Thomaiyar return; 2772413961deSRichard Marian Thomaiyar } 2773f65af9e8SRichard Marian Thomaiyar } 2774413961deSRichard Marian Thomaiyar // Get the connection to which the memberId belongs 2775413961deSRichard Marian Thomaiyar auto getObjectsWithConnectionCb = 2776f65af9e8SRichard Marian Thomaiyar [sensorAsyncResp, overrideMap]( 2777cb13a392SEd Tanous const boost::container::flat_set<std::string>& /*connections*/, 2778413961deSRichard Marian Thomaiyar const std::set<std::pair<std::string, std::string>>& 2779413961deSRichard Marian Thomaiyar objectsWithConnection) { 2780f65af9e8SRichard Marian Thomaiyar if (objectsWithConnection.size() != overrideMap.size()) 2781413961deSRichard Marian Thomaiyar { 2782413961deSRichard Marian Thomaiyar BMCWEB_LOG_INFO 2783f65af9e8SRichard Marian Thomaiyar << "Unable to find all objects with proper connection " 2784f65af9e8SRichard Marian Thomaiyar << objectsWithConnection.size() << " requested " 2785f65af9e8SRichard Marian Thomaiyar << overrideMap.size() << "\n"; 2786413961deSRichard Marian Thomaiyar messages::resourceNotFound( 2787413961deSRichard Marian Thomaiyar sensorAsyncResp->res, 2788a0ec28b6SAdrian Ambrożewicz sensorAsyncResp->chassisSubNode == 2789a0ec28b6SAdrian Ambrożewicz sensors::node::thermal 2790413961deSRichard Marian Thomaiyar ? "Temperatures" 2791413961deSRichard Marian Thomaiyar : "Voltages", 2792f65af9e8SRichard Marian Thomaiyar "Count"); 2793f65af9e8SRichard Marian Thomaiyar return; 2794f65af9e8SRichard Marian Thomaiyar } 2795f65af9e8SRichard Marian Thomaiyar for (const auto& item : objectsWithConnection) 2796f65af9e8SRichard Marian Thomaiyar { 279728aa8de5SGeorge Liu sdbusplus::message::object_path path(item.first); 279828aa8de5SGeorge Liu std::string sensorName = path.filename(); 279928aa8de5SGeorge Liu if (sensorName.empty()) 2800f65af9e8SRichard Marian Thomaiyar { 2801f65af9e8SRichard Marian Thomaiyar messages::internalError(sensorAsyncResp->res); 2802f65af9e8SRichard Marian Thomaiyar return; 2803f65af9e8SRichard Marian Thomaiyar } 2804f65af9e8SRichard Marian Thomaiyar 2805f65af9e8SRichard Marian Thomaiyar const auto& iterator = overrideMap.find(sensorName); 2806f65af9e8SRichard Marian Thomaiyar if (iterator == overrideMap.end()) 2807f65af9e8SRichard Marian Thomaiyar { 2808f65af9e8SRichard Marian Thomaiyar BMCWEB_LOG_INFO << "Unable to find sensor object" 2809f65af9e8SRichard Marian Thomaiyar << item.first << "\n"; 2810f65af9e8SRichard Marian Thomaiyar messages::internalError(sensorAsyncResp->res); 2811413961deSRichard Marian Thomaiyar return; 2812413961deSRichard Marian Thomaiyar } 2813413961deSRichard Marian Thomaiyar crow::connections::systemBus->async_method_call( 2814f65af9e8SRichard Marian Thomaiyar [sensorAsyncResp](const boost::system::error_code ec) { 2815413961deSRichard Marian Thomaiyar if (ec) 2816413961deSRichard Marian Thomaiyar { 2817413961deSRichard Marian Thomaiyar BMCWEB_LOG_DEBUG 2818f65af9e8SRichard Marian Thomaiyar << "setOverrideValueStatus DBUS error: " 2819413961deSRichard Marian Thomaiyar << ec; 2820413961deSRichard Marian Thomaiyar messages::internalError(sensorAsyncResp->res); 2821413961deSRichard Marian Thomaiyar return; 2822413961deSRichard Marian Thomaiyar } 2823413961deSRichard Marian Thomaiyar }, 2824f65af9e8SRichard Marian Thomaiyar item.second, item.first, 2825413961deSRichard Marian Thomaiyar "org.freedesktop.DBus.Properties", "Set", 2826413961deSRichard Marian Thomaiyar "xyz.openbmc_project.Sensor.Value", "Value", 282719bd78d9SPatrick Williams std::variant<double>(iterator->second.first)); 2828f65af9e8SRichard Marian Thomaiyar } 2829413961deSRichard Marian Thomaiyar }; 2830413961deSRichard Marian Thomaiyar // Get object with connection for the given sensor name 2831413961deSRichard Marian Thomaiyar getObjectsWithConnection(sensorAsyncResp, sensorNames, 2832413961deSRichard Marian Thomaiyar std::move(getObjectsWithConnectionCb)); 2833413961deSRichard Marian Thomaiyar }; 2834413961deSRichard Marian Thomaiyar // get full sensor list for the given chassisId and cross verify the sensor. 2835413961deSRichard Marian Thomaiyar getChassis(sensorAsyncResp, std::move(getChassisSensorListCb)); 2836413961deSRichard Marian Thomaiyar } 2837413961deSRichard Marian Thomaiyar 283823a21a1cSEd Tanous inline bool isOverridingAllowed(const std::string& manufacturingModeStatus) 283970d1d0aaSjayaprakash Mutyala { 284070d1d0aaSjayaprakash Mutyala if (manufacturingModeStatus == 284170d1d0aaSjayaprakash Mutyala "xyz.openbmc_project.Control.Security.SpecialMode.Modes.Manufacturing") 284270d1d0aaSjayaprakash Mutyala { 284370d1d0aaSjayaprakash Mutyala return true; 284470d1d0aaSjayaprakash Mutyala } 284570d1d0aaSjayaprakash Mutyala 284670d1d0aaSjayaprakash Mutyala #ifdef BMCWEB_ENABLE_VALIDATION_UNSECURE_FEATURE 284770d1d0aaSjayaprakash Mutyala if (manufacturingModeStatus == "xyz.openbmc_project.Control.Security." 284870d1d0aaSjayaprakash Mutyala "SpecialMode.Modes.ValidationUnsecure") 284970d1d0aaSjayaprakash Mutyala { 285070d1d0aaSjayaprakash Mutyala return true; 285170d1d0aaSjayaprakash Mutyala } 285270d1d0aaSjayaprakash Mutyala 285370d1d0aaSjayaprakash Mutyala #endif 285470d1d0aaSjayaprakash Mutyala 285570d1d0aaSjayaprakash Mutyala return false; 285670d1d0aaSjayaprakash Mutyala } 285770d1d0aaSjayaprakash Mutyala 285870d1d0aaSjayaprakash Mutyala /** 285970d1d0aaSjayaprakash Mutyala * @brief Entry point for Checking the manufacturing mode before doing sensor 286070d1d0aaSjayaprakash Mutyala * override values of given sensor 286170d1d0aaSjayaprakash Mutyala * 286270d1d0aaSjayaprakash Mutyala * @param res response object 286370d1d0aaSjayaprakash Mutyala * @param allCollections Collections extract from sensors' request patch info 286470d1d0aaSjayaprakash Mutyala * @param chassisSubNode Chassis Node for which the query has to happen 286570d1d0aaSjayaprakash Mutyala */ 286623a21a1cSEd Tanous inline void checkAndDoSensorsOverride( 2867b5a76932SEd Tanous const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp, 2868397fd61fSjayaprakash Mutyala std::unordered_map<std::string, std::vector<nlohmann::json>>& 2869397fd61fSjayaprakash Mutyala allCollections) 287070d1d0aaSjayaprakash Mutyala { 287170d1d0aaSjayaprakash Mutyala BMCWEB_LOG_INFO << "checkAndDoSensorsOverride for subnode" 287270d1d0aaSjayaprakash Mutyala << sensorAsyncResp->chassisSubNode << "\n"; 287370d1d0aaSjayaprakash Mutyala 287470d1d0aaSjayaprakash Mutyala const std::array<std::string, 1> interfaces = { 287570d1d0aaSjayaprakash Mutyala "xyz.openbmc_project.Security.SpecialMode"}; 287670d1d0aaSjayaprakash Mutyala 287770d1d0aaSjayaprakash Mutyala crow::connections::systemBus->async_method_call( 287823a21a1cSEd Tanous [sensorAsyncResp, allCollections](const boost::system::error_code ec2, 287970d1d0aaSjayaprakash Mutyala const GetSubTreeType& resp) mutable { 288023a21a1cSEd Tanous if (ec2) 288170d1d0aaSjayaprakash Mutyala { 288270d1d0aaSjayaprakash Mutyala BMCWEB_LOG_DEBUG 288370d1d0aaSjayaprakash Mutyala << "Error in querying GetSubTree with Object Mapper. " 288423a21a1cSEd Tanous << ec2; 288570d1d0aaSjayaprakash Mutyala messages::internalError(sensorAsyncResp->res); 288670d1d0aaSjayaprakash Mutyala return; 288770d1d0aaSjayaprakash Mutyala } 288891e130a3Sjayaprakash Mutyala #ifdef BMCWEB_INSECURE_UNRESTRICTED_SENSOR_OVERRIDE 288991e130a3Sjayaprakash Mutyala // Proceed with sensor override 2890397fd61fSjayaprakash Mutyala setSensorsOverride(sensorAsyncResp, allCollections); 289170d1d0aaSjayaprakash Mutyala return; 289291e130a3Sjayaprakash Mutyala #endif 289370d1d0aaSjayaprakash Mutyala 289470d1d0aaSjayaprakash Mutyala if (resp.size() != 1) 289570d1d0aaSjayaprakash Mutyala { 289691e130a3Sjayaprakash Mutyala BMCWEB_LOG_WARNING 289791e130a3Sjayaprakash Mutyala << "Overriding sensor value is not allowed - Internal " 289891e130a3Sjayaprakash Mutyala "error in querying SpecialMode property."; 289970d1d0aaSjayaprakash Mutyala messages::internalError(sensorAsyncResp->res); 290070d1d0aaSjayaprakash Mutyala return; 290170d1d0aaSjayaprakash Mutyala } 290270d1d0aaSjayaprakash Mutyala const std::string& path = resp[0].first; 290370d1d0aaSjayaprakash Mutyala const std::string& serviceName = resp[0].second.begin()->first; 290470d1d0aaSjayaprakash Mutyala 290570d1d0aaSjayaprakash Mutyala if (path.empty() || serviceName.empty()) 290670d1d0aaSjayaprakash Mutyala { 290770d1d0aaSjayaprakash Mutyala BMCWEB_LOG_DEBUG 290870d1d0aaSjayaprakash Mutyala << "Path or service name is returned as empty. "; 290970d1d0aaSjayaprakash Mutyala messages::internalError(sensorAsyncResp->res); 291070d1d0aaSjayaprakash Mutyala return; 291170d1d0aaSjayaprakash Mutyala } 291270d1d0aaSjayaprakash Mutyala 291370d1d0aaSjayaprakash Mutyala // Sensor override is allowed only in manufacturing mode or 291470d1d0aaSjayaprakash Mutyala // validation unsecure mode . 291570d1d0aaSjayaprakash Mutyala crow::connections::systemBus->async_method_call( 2916397fd61fSjayaprakash Mutyala [sensorAsyncResp, allCollections, 291770d1d0aaSjayaprakash Mutyala path](const boost::system::error_code ec, 291870d1d0aaSjayaprakash Mutyala std::variant<std::string>& getManufactMode) mutable { 291970d1d0aaSjayaprakash Mutyala if (ec) 292070d1d0aaSjayaprakash Mutyala { 292170d1d0aaSjayaprakash Mutyala BMCWEB_LOG_DEBUG 292270d1d0aaSjayaprakash Mutyala << "Error in querying Special mode property " << ec; 292370d1d0aaSjayaprakash Mutyala messages::internalError(sensorAsyncResp->res); 292470d1d0aaSjayaprakash Mutyala return; 292570d1d0aaSjayaprakash Mutyala } 292670d1d0aaSjayaprakash Mutyala 292770d1d0aaSjayaprakash Mutyala const std::string* manufacturingModeStatus = 292870d1d0aaSjayaprakash Mutyala std::get_if<std::string>(&getManufactMode); 292970d1d0aaSjayaprakash Mutyala 293070d1d0aaSjayaprakash Mutyala if (nullptr == manufacturingModeStatus) 293170d1d0aaSjayaprakash Mutyala { 293270d1d0aaSjayaprakash Mutyala BMCWEB_LOG_DEBUG << "Sensor override mode is not " 293370d1d0aaSjayaprakash Mutyala "Enabled. Returning ... "; 293470d1d0aaSjayaprakash Mutyala messages::internalError(sensorAsyncResp->res); 293570d1d0aaSjayaprakash Mutyala return; 293670d1d0aaSjayaprakash Mutyala } 293770d1d0aaSjayaprakash Mutyala 293870d1d0aaSjayaprakash Mutyala if (isOverridingAllowed(*manufacturingModeStatus)) 293970d1d0aaSjayaprakash Mutyala { 294070d1d0aaSjayaprakash Mutyala BMCWEB_LOG_INFO << "Manufacturing mode is Enabled. " 294170d1d0aaSjayaprakash Mutyala "Proceeding further... "; 2942397fd61fSjayaprakash Mutyala setSensorsOverride(sensorAsyncResp, allCollections); 294370d1d0aaSjayaprakash Mutyala } 294470d1d0aaSjayaprakash Mutyala else 294570d1d0aaSjayaprakash Mutyala { 294670d1d0aaSjayaprakash Mutyala BMCWEB_LOG_WARNING 294770d1d0aaSjayaprakash Mutyala << "Manufacturing mode is not Enabled...can't " 294870d1d0aaSjayaprakash Mutyala "Override the sensor value. "; 294970d1d0aaSjayaprakash Mutyala 295070d1d0aaSjayaprakash Mutyala messages::actionNotSupported( 295170d1d0aaSjayaprakash Mutyala sensorAsyncResp->res, 295270d1d0aaSjayaprakash Mutyala "Overriding of Sensor Value for non " 295370d1d0aaSjayaprakash Mutyala "manufacturing mode"); 295470d1d0aaSjayaprakash Mutyala return; 295570d1d0aaSjayaprakash Mutyala } 295670d1d0aaSjayaprakash Mutyala }, 295770d1d0aaSjayaprakash Mutyala serviceName, path, "org.freedesktop.DBus.Properties", "Get", 295870d1d0aaSjayaprakash Mutyala "xyz.openbmc_project.Security.SpecialMode", "SpecialMode"); 295970d1d0aaSjayaprakash Mutyala }, 296070d1d0aaSjayaprakash Mutyala 296170d1d0aaSjayaprakash Mutyala "xyz.openbmc_project.ObjectMapper", 296270d1d0aaSjayaprakash Mutyala "/xyz/openbmc_project/object_mapper", 296370d1d0aaSjayaprakash Mutyala "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 5, interfaces); 296470d1d0aaSjayaprakash Mutyala } 296570d1d0aaSjayaprakash Mutyala 2966a0ec28b6SAdrian Ambrożewicz /** 2967a0ec28b6SAdrian Ambrożewicz * @brief Retrieves mapping of Redfish URIs to sensor value property to D-Bus 2968a0ec28b6SAdrian Ambrożewicz * path of the sensor. 2969a0ec28b6SAdrian Ambrożewicz * 2970a0ec28b6SAdrian Ambrożewicz * Function builds valid Redfish response for sensor query of given chassis and 2971a0ec28b6SAdrian Ambrożewicz * node. It then builds metadata about Redfish<->D-Bus correlations and provides 2972a0ec28b6SAdrian Ambrożewicz * it to caller in a callback. 2973a0ec28b6SAdrian Ambrożewicz * 2974a0ec28b6SAdrian Ambrożewicz * @param chassis Chassis for which retrieval should be performed 2975a0ec28b6SAdrian Ambrożewicz * @param node Node (group) of sensors. See sensors::node for supported values 2976a0ec28b6SAdrian Ambrożewicz * @param mapComplete Callback to be called with retrieval result 2977a0ec28b6SAdrian Ambrożewicz */ 297823a21a1cSEd Tanous inline void retrieveUriToDbusMap(const std::string& chassis, 297923a21a1cSEd Tanous const std::string& node, 2980a0ec28b6SAdrian Ambrożewicz SensorsAsyncResp::DataCompleteCb&& mapComplete) 2981a0ec28b6SAdrian Ambrożewicz { 2982a0ec28b6SAdrian Ambrożewicz auto typesIt = sensors::dbus::types.find(node); 2983a0ec28b6SAdrian Ambrożewicz if (typesIt == sensors::dbus::types.end()) 2984a0ec28b6SAdrian Ambrożewicz { 2985a0ec28b6SAdrian Ambrożewicz BMCWEB_LOG_ERROR << "Wrong node provided : " << node; 2986a0ec28b6SAdrian Ambrożewicz mapComplete(boost::beast::http::status::bad_request, {}); 2987a0ec28b6SAdrian Ambrożewicz return; 2988a0ec28b6SAdrian Ambrożewicz } 2989a0ec28b6SAdrian Ambrożewicz 2990a0ec28b6SAdrian Ambrożewicz auto respBuffer = std::make_shared<crow::Response>(); 2991a0ec28b6SAdrian Ambrożewicz auto callback = 2992a0ec28b6SAdrian Ambrożewicz [respBuffer, mapCompleteCb{std::move(mapComplete)}]( 2993a0ec28b6SAdrian Ambrożewicz const boost::beast::http::status status, 2994a0ec28b6SAdrian Ambrożewicz const boost::container::flat_map<std::string, std::string>& 2995a0ec28b6SAdrian Ambrożewicz uriToDbus) { mapCompleteCb(status, uriToDbus); }; 2996a0ec28b6SAdrian Ambrożewicz 2997a0ec28b6SAdrian Ambrożewicz auto resp = std::make_shared<SensorsAsyncResp>( 2998a0ec28b6SAdrian Ambrożewicz *respBuffer, chassis, typesIt->second, node, std::move(callback)); 2999a0ec28b6SAdrian Ambrożewicz getChassisData(resp); 3000a0ec28b6SAdrian Ambrożewicz } 3001a0ec28b6SAdrian Ambrożewicz 300295a3ecadSAnthony Wilson class SensorCollection : public Node 300395a3ecadSAnthony Wilson { 300495a3ecadSAnthony Wilson public: 300552cc112dSEd Tanous SensorCollection(App& app) : 3006f99c379dSGunnar Mills Node(app, "/redfish/v1/Chassis/<str>/Sensors/", std::string()) 300795a3ecadSAnthony Wilson { 300895a3ecadSAnthony Wilson entityPrivileges = { 300995a3ecadSAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 301095a3ecadSAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 301195a3ecadSAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 301295a3ecadSAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 301395a3ecadSAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 301495a3ecadSAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 301595a3ecadSAnthony Wilson } 301695a3ecadSAnthony Wilson 301795a3ecadSAnthony Wilson private: 3018cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 301995a3ecadSAnthony Wilson const std::vector<std::string>& params) override 302095a3ecadSAnthony Wilson { 302195a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "SensorCollection doGet enter"; 302295a3ecadSAnthony Wilson if (params.size() != 1) 302395a3ecadSAnthony Wilson { 302495a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "SensorCollection doGet param size < 1"; 302595a3ecadSAnthony Wilson messages::internalError(res); 302695a3ecadSAnthony Wilson res.end(); 302795a3ecadSAnthony Wilson return; 302895a3ecadSAnthony Wilson } 302995a3ecadSAnthony Wilson 303095a3ecadSAnthony Wilson const std::string& chassisId = params[0]; 303195a3ecadSAnthony Wilson std::shared_ptr<SensorsAsyncResp> asyncResp = 3032a0ec28b6SAdrian Ambrożewicz std::make_shared<SensorsAsyncResp>( 3033a0ec28b6SAdrian Ambrożewicz res, chassisId, sensors::dbus::types.at(sensors::node::sensors), 3034a0ec28b6SAdrian Ambrożewicz sensors::node::sensors); 303595a3ecadSAnthony Wilson 303695a3ecadSAnthony Wilson auto getChassisCb = 3037b5a76932SEd Tanous [asyncResp]( 3038b5a76932SEd Tanous const std::shared_ptr<boost::container::flat_set<std::string>>& 303995a3ecadSAnthony Wilson sensorNames) { 304095a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "getChassisCb enter"; 304195a3ecadSAnthony Wilson 304295a3ecadSAnthony Wilson nlohmann::json& entriesArray = 304395a3ecadSAnthony Wilson asyncResp->res.jsonValue["Members"]; 304495a3ecadSAnthony Wilson for (auto& sensor : *sensorNames) 304595a3ecadSAnthony Wilson { 304695a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "Adding sensor: " << sensor; 304795a3ecadSAnthony Wilson 304828aa8de5SGeorge Liu sdbusplus::message::object_path path(sensor); 304928aa8de5SGeorge Liu std::string sensorName = path.filename(); 305028aa8de5SGeorge Liu if (sensorName.empty()) 305195a3ecadSAnthony Wilson { 305295a3ecadSAnthony Wilson BMCWEB_LOG_ERROR << "Invalid sensor path: " << sensor; 305395a3ecadSAnthony Wilson messages::internalError(asyncResp->res); 305495a3ecadSAnthony Wilson return; 305595a3ecadSAnthony Wilson } 305695a3ecadSAnthony Wilson entriesArray.push_back( 305795a3ecadSAnthony Wilson {{"@odata.id", 305895a3ecadSAnthony Wilson "/redfish/v1/Chassis/" + asyncResp->chassisId + "/" + 305995a3ecadSAnthony Wilson asyncResp->chassisSubNode + "/" + sensorName}}); 306095a3ecadSAnthony Wilson } 306195a3ecadSAnthony Wilson 306295a3ecadSAnthony Wilson asyncResp->res.jsonValue["Members@odata.count"] = 306395a3ecadSAnthony Wilson entriesArray.size(); 306495a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "getChassisCb exit"; 306595a3ecadSAnthony Wilson }; 306695a3ecadSAnthony Wilson 306795a3ecadSAnthony Wilson // Get set of sensors in chassis 306895a3ecadSAnthony Wilson getChassis(asyncResp, std::move(getChassisCb)); 306995a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "SensorCollection doGet exit"; 307095a3ecadSAnthony Wilson } 307195a3ecadSAnthony Wilson }; 307295a3ecadSAnthony Wilson 307395a3ecadSAnthony Wilson class Sensor : public Node 307495a3ecadSAnthony Wilson { 307595a3ecadSAnthony Wilson public: 307652cc112dSEd Tanous Sensor(App& app) : 307795a3ecadSAnthony Wilson Node(app, "/redfish/v1/Chassis/<str>/Sensors/<str>/", std::string(), 307895a3ecadSAnthony Wilson std::string()) 307995a3ecadSAnthony Wilson { 308095a3ecadSAnthony Wilson entityPrivileges = { 308195a3ecadSAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 308295a3ecadSAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 308395a3ecadSAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 308495a3ecadSAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 308595a3ecadSAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 308695a3ecadSAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 308795a3ecadSAnthony Wilson } 308895a3ecadSAnthony Wilson 308995a3ecadSAnthony Wilson private: 3090cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 309195a3ecadSAnthony Wilson const std::vector<std::string>& params) override 309295a3ecadSAnthony Wilson { 309395a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "Sensor doGet enter"; 309495a3ecadSAnthony Wilson if (params.size() != 2) 309595a3ecadSAnthony Wilson { 309695a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "Sensor doGet param size < 2"; 309795a3ecadSAnthony Wilson messages::internalError(res); 309895a3ecadSAnthony Wilson res.end(); 309995a3ecadSAnthony Wilson return; 310095a3ecadSAnthony Wilson } 310195a3ecadSAnthony Wilson const std::string& chassisId = params[0]; 310295a3ecadSAnthony Wilson std::shared_ptr<SensorsAsyncResp> asyncResp = 3103a0ec28b6SAdrian Ambrożewicz std::make_shared<SensorsAsyncResp>(res, chassisId, 3104a0ec28b6SAdrian Ambrożewicz std::vector<const char*>(), 3105a0ec28b6SAdrian Ambrożewicz sensors::node::sensors); 310695a3ecadSAnthony Wilson 310795a3ecadSAnthony Wilson const std::string& sensorName = params[1]; 310895a3ecadSAnthony Wilson const std::array<const char*, 1> interfaces = { 310995a3ecadSAnthony Wilson "xyz.openbmc_project.Sensor.Value"}; 311095a3ecadSAnthony Wilson 311195a3ecadSAnthony Wilson // Get a list of all of the sensors that implement Sensor.Value 311295a3ecadSAnthony Wilson // and get the path and service name associated with the sensor 311395a3ecadSAnthony Wilson crow::connections::systemBus->async_method_call( 311495a3ecadSAnthony Wilson [asyncResp, sensorName](const boost::system::error_code ec, 311595a3ecadSAnthony Wilson const GetSubTreeType& subtree) { 311695a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "respHandler1 enter"; 311795a3ecadSAnthony Wilson if (ec) 311895a3ecadSAnthony Wilson { 311995a3ecadSAnthony Wilson messages::internalError(asyncResp->res); 312095a3ecadSAnthony Wilson BMCWEB_LOG_ERROR << "Sensor getSensorPaths resp_handler: " 312195a3ecadSAnthony Wilson << "Dbus error " << ec; 312295a3ecadSAnthony Wilson return; 312395a3ecadSAnthony Wilson } 312495a3ecadSAnthony Wilson 312595a3ecadSAnthony Wilson GetSubTreeType::const_iterator it = std::find_if( 312695a3ecadSAnthony Wilson subtree.begin(), subtree.end(), 312795a3ecadSAnthony Wilson [sensorName]( 312895a3ecadSAnthony Wilson const std::pair< 312995a3ecadSAnthony Wilson std::string, 313095a3ecadSAnthony Wilson std::vector<std::pair<std::string, 313195a3ecadSAnthony Wilson std::vector<std::string>>>>& 313295a3ecadSAnthony Wilson object) { 313328aa8de5SGeorge Liu sdbusplus::message::object_path path(object.first); 313428aa8de5SGeorge Liu std::string name = path.filename(); 313528aa8de5SGeorge Liu if (name.empty()) 313695a3ecadSAnthony Wilson { 313795a3ecadSAnthony Wilson BMCWEB_LOG_ERROR << "Invalid sensor path: " 313828aa8de5SGeorge Liu << object.first; 313995a3ecadSAnthony Wilson return false; 314095a3ecadSAnthony Wilson } 314195a3ecadSAnthony Wilson 314295a3ecadSAnthony Wilson return name == sensorName; 314395a3ecadSAnthony Wilson }); 314495a3ecadSAnthony Wilson 314595a3ecadSAnthony Wilson if (it == subtree.end()) 314695a3ecadSAnthony Wilson { 314795a3ecadSAnthony Wilson BMCWEB_LOG_ERROR << "Could not find path for sensor: " 314895a3ecadSAnthony Wilson << sensorName; 314995a3ecadSAnthony Wilson messages::resourceNotFound(asyncResp->res, "Sensor", 315095a3ecadSAnthony Wilson sensorName); 315195a3ecadSAnthony Wilson return; 315295a3ecadSAnthony Wilson } 315395a3ecadSAnthony Wilson std::string_view sensorPath = (*it).first; 315495a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "Found sensor path for sensor '" 315595a3ecadSAnthony Wilson << sensorName << "': " << sensorPath; 315695a3ecadSAnthony Wilson 315795a3ecadSAnthony Wilson const std::shared_ptr<boost::container::flat_set<std::string>> 315895a3ecadSAnthony Wilson sensorList = std::make_shared< 315995a3ecadSAnthony Wilson boost::container::flat_set<std::string>>(); 316095a3ecadSAnthony Wilson 316195a3ecadSAnthony Wilson sensorList->emplace(sensorPath); 316295a3ecadSAnthony Wilson processSensorList(asyncResp, sensorList); 316395a3ecadSAnthony Wilson BMCWEB_LOG_DEBUG << "respHandler1 exit"; 316495a3ecadSAnthony Wilson }, 316595a3ecadSAnthony Wilson "xyz.openbmc_project.ObjectMapper", 316695a3ecadSAnthony Wilson "/xyz/openbmc_project/object_mapper", 316795a3ecadSAnthony Wilson "xyz.openbmc_project.ObjectMapper", "GetSubTree", 316895a3ecadSAnthony Wilson "/xyz/openbmc_project/sensors", 2, interfaces); 316995a3ecadSAnthony Wilson } 317095a3ecadSAnthony Wilson }; 317195a3ecadSAnthony Wilson 317208777fb0SLewanczyk, Dawid } // namespace redfish 3173