Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 18 | #include <app.hpp> |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 19 | #include <boost/algorithm/string/predicate.hpp> |
| 20 | #include <boost/algorithm/string/split.hpp> |
| 21 | #include <boost/container/flat_map.hpp> |
| 22 | #include <boost/range/algorithm/replace_copy_if.hpp> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 23 | #include <dbus_singleton.hpp> |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 24 | #include <dbus_utility.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 25 | #include <registries/privilege_registry.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 26 | #include <sdbusplus/asio/property.hpp> |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 27 | #include <utils/json_utils.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 28 | |
| 29 | #include <cmath> |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 30 | #include <utility> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 31 | #include <variant> |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 32 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 33 | namespace redfish |
| 34 | { |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 35 | |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 36 | using GetSubTreeType = std::vector< |
| 37 | std::pair<std::string, |
| 38 | std::vector<std::pair<std::string, std::vector<std::string>>>>>; |
| 39 | |
| 40 | using ManagedObjectsVectorType = std::vector<std::pair< |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 41 | sdbusplus::message::object_path, |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 42 | boost::container::flat_map< |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 43 | std::string, boost::container::flat_map< |
| 44 | std::string, dbus::utility::DbusVariantType>>>>; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 45 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 46 | namespace sensors |
| 47 | { |
| 48 | namespace node |
| 49 | { |
| 50 | static constexpr std::string_view power = "Power"; |
| 51 | static constexpr std::string_view sensors = "Sensors"; |
| 52 | static constexpr std::string_view thermal = "Thermal"; |
| 53 | } // namespace node |
| 54 | |
| 55 | namespace dbus |
| 56 | { |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 57 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 58 | static const boost::container::flat_map<std::string_view, |
| 59 | std::vector<const char*>> |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 60 | paths = {{node::power, |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 61 | {"/xyz/openbmc_project/sensors/voltage", |
| 62 | "/xyz/openbmc_project/sensors/power"}}, |
| 63 | {node::sensors, |
| 64 | {"/xyz/openbmc_project/sensors/power", |
| 65 | "/xyz/openbmc_project/sensors/current", |
Basheer Ahmed Muddebihal | 7088690 | 2021-07-22 02:11:17 -0700 | [diff] [blame] | 66 | "/xyz/openbmc_project/sensors/airflow", |
George Liu | e820493 | 2021-02-01 14:42:49 +0800 | [diff] [blame] | 67 | #ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM |
| 68 | "/xyz/openbmc_project/sensors/voltage", |
| 69 | "/xyz/openbmc_project/sensors/fan_tach", |
| 70 | "/xyz/openbmc_project/sensors/temperature", |
| 71 | "/xyz/openbmc_project/sensors/fan_pwm", |
| 72 | "/xyz/openbmc_project/sensors/altitude", |
| 73 | "/xyz/openbmc_project/sensors/energy", |
| 74 | #endif |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 75 | "/xyz/openbmc_project/sensors/utilization"}}, |
| 76 | {node::thermal, |
| 77 | {"/xyz/openbmc_project/sensors/fan_tach", |
| 78 | "/xyz/openbmc_project/sensors/temperature", |
| 79 | "/xyz/openbmc_project/sensors/fan_pwm"}}}; |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 80 | } // namespace dbus |
| 81 | |
| 82 | inline const char* toReadingType(const std::string& sensorType) |
| 83 | { |
| 84 | if (sensorType == "voltage") |
| 85 | { |
| 86 | return "Voltage"; |
| 87 | } |
| 88 | if (sensorType == "power") |
| 89 | { |
| 90 | return "Power"; |
| 91 | } |
| 92 | if (sensorType == "current") |
| 93 | { |
| 94 | return "Current"; |
| 95 | } |
| 96 | if (sensorType == "fan_tach") |
| 97 | { |
| 98 | return "Rotational"; |
| 99 | } |
| 100 | if (sensorType == "temperature") |
| 101 | { |
| 102 | return "Temperature"; |
| 103 | } |
| 104 | if (sensorType == "fan_pwm" || sensorType == "utilization") |
| 105 | { |
| 106 | return "Percent"; |
| 107 | } |
| 108 | if (sensorType == "altitude") |
| 109 | { |
| 110 | return "Altitude"; |
| 111 | } |
| 112 | if (sensorType == "airflow") |
| 113 | { |
| 114 | return "AirFlow"; |
| 115 | } |
| 116 | if (sensorType == "energy") |
| 117 | { |
| 118 | return "EnergyJoules"; |
| 119 | } |
| 120 | return ""; |
| 121 | } |
| 122 | |
| 123 | inline const char* toReadingUnits(const std::string& sensorType) |
| 124 | { |
| 125 | if (sensorType == "voltage") |
| 126 | { |
| 127 | return "V"; |
| 128 | } |
| 129 | if (sensorType == "power") |
| 130 | { |
| 131 | return "W"; |
| 132 | } |
| 133 | if (sensorType == "current") |
| 134 | { |
| 135 | return "A"; |
| 136 | } |
| 137 | if (sensorType == "fan_tach") |
| 138 | { |
| 139 | return "RPM"; |
| 140 | } |
| 141 | if (sensorType == "temperature") |
| 142 | { |
| 143 | return "Cel"; |
| 144 | } |
| 145 | if (sensorType == "fan_pwm" || sensorType == "utilization") |
| 146 | { |
| 147 | return "%"; |
| 148 | } |
| 149 | if (sensorType == "altitude") |
| 150 | { |
| 151 | return "m"; |
| 152 | } |
| 153 | if (sensorType == "airflow") |
| 154 | { |
| 155 | return "cft_i/min"; |
| 156 | } |
| 157 | if (sensorType == "energy") |
| 158 | { |
| 159 | return "J"; |
| 160 | } |
| 161 | return ""; |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 162 | } |
| 163 | } // namespace sensors |
| 164 | |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 165 | /** |
Kowalski, Kamil | 588c3f0 | 2018-04-03 14:55:27 +0200 | [diff] [blame] | 166 | * SensorsAsyncResp |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 167 | * Gathers data needed for response processing after async calls are done |
| 168 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 169 | class SensorsAsyncResp |
| 170 | { |
| 171 | public: |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 172 | using DataCompleteCb = std::function<void( |
| 173 | const boost::beast::http::status status, |
| 174 | const boost::container::flat_map<std::string, std::string>& uriToDbus)>; |
| 175 | |
| 176 | struct SensorData |
| 177 | { |
| 178 | const std::string name; |
| 179 | std::string uri; |
| 180 | const std::string valueKey; |
| 181 | const std::string dbusPath; |
| 182 | }; |
| 183 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 184 | SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 185 | const std::string& chassisIdIn, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 186 | const std::vector<const char*>& typesIn, |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 187 | const std::string_view& subNode) : |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 188 | asyncResp(asyncResp), |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 189 | chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode) |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 190 | {} |
Kowalski, Kamil | 588c3f0 | 2018-04-03 14:55:27 +0200 | [diff] [blame] | 191 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 192 | // Store extra data about sensor mapping and return it in callback |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 193 | SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 194 | const std::string& chassisIdIn, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 195 | const std::vector<const char*>& typesIn, |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 196 | const std::string_view& subNode, |
| 197 | DataCompleteCb&& creationComplete) : |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 198 | asyncResp(asyncResp), |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 199 | chassisId(chassisIdIn), types(typesIn), |
| 200 | chassisSubNode(subNode), metadata{std::vector<SensorData>()}, |
| 201 | dataComplete{std::move(creationComplete)} |
| 202 | {} |
| 203 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 204 | ~SensorsAsyncResp() |
| 205 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 206 | if (asyncResp->res.result() == |
| 207 | boost::beast::http::status::internal_server_error) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 208 | { |
| 209 | // Reset the json object to clear out any data that made it in |
| 210 | // before the error happened todo(ed) handle error condition with |
| 211 | // proper code |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 212 | asyncResp->res.jsonValue = nlohmann::json::object(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 213 | } |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 214 | |
| 215 | if (dataComplete && metadata) |
| 216 | { |
| 217 | boost::container::flat_map<std::string, std::string> map; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 218 | if (asyncResp->res.result() == boost::beast::http::status::ok) |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 219 | { |
| 220 | for (auto& sensor : *metadata) |
| 221 | { |
| 222 | map.insert(std::make_pair(sensor.uri + sensor.valueKey, |
| 223 | sensor.dbusPath)); |
| 224 | } |
| 225 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 226 | dataComplete(asyncResp->res.result(), map); |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 227 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 228 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 229 | |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 230 | SensorsAsyncResp(const SensorsAsyncResp&) = delete; |
| 231 | SensorsAsyncResp(SensorsAsyncResp&&) = delete; |
| 232 | SensorsAsyncResp& operator=(const SensorsAsyncResp&) = delete; |
| 233 | SensorsAsyncResp& operator=(SensorsAsyncResp&&) = delete; |
| 234 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 235 | void addMetadata(const nlohmann::json& sensorObject, |
| 236 | const std::string& valueKey, const std::string& dbusPath) |
| 237 | { |
| 238 | if (metadata) |
| 239 | { |
| 240 | metadata->emplace_back(SensorData{sensorObject["Name"], |
| 241 | sensorObject["@odata.id"], |
| 242 | valueKey, dbusPath}); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | void updateUri(const std::string& name, const std::string& uri) |
| 247 | { |
| 248 | if (metadata) |
| 249 | { |
| 250 | for (auto& sensor : *metadata) |
| 251 | { |
| 252 | if (sensor.name == name) |
| 253 | { |
| 254 | sensor.uri = uri; |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 260 | const std::shared_ptr<bmcweb::AsyncResp> asyncResp; |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 261 | const std::string chassisId; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 262 | const std::vector<const char*> types; |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 263 | const std::string chassisSubNode; |
| 264 | |
| 265 | private: |
| 266 | std::optional<std::vector<SensorData>> metadata; |
| 267 | DataCompleteCb dataComplete; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | /** |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 271 | * Possible states for physical inventory leds |
| 272 | */ |
| 273 | enum class LedState |
| 274 | { |
| 275 | OFF, |
| 276 | ON, |
| 277 | BLINK, |
| 278 | UNKNOWN |
| 279 | }; |
| 280 | |
| 281 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 282 | * D-Bus inventory item associated with one or more sensors. |
| 283 | */ |
| 284 | class InventoryItem |
| 285 | { |
| 286 | public: |
| 287 | InventoryItem(const std::string& objPath) : |
| 288 | objectPath(objPath), name(), isPresent(true), isFunctional(true), |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 289 | isPowerSupply(false), powerSupplyEfficiencyPercent(-1), manufacturer(), |
| 290 | model(), partNumber(), serialNumber(), sensors(), ledObjectPath(""), |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 291 | ledState(LedState::UNKNOWN) |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 292 | { |
| 293 | // Set inventory item name to last node of object path |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 294 | sdbusplus::message::object_path path(objectPath); |
| 295 | name = path.filename(); |
| 296 | if (name.empty()) |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 297 | { |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 298 | BMCWEB_LOG_ERROR << "Failed to find '/' in " << objectPath; |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | std::string objectPath; |
| 303 | std::string name; |
| 304 | bool isPresent; |
| 305 | bool isFunctional; |
| 306 | bool isPowerSupply; |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 307 | int powerSupplyEfficiencyPercent; |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 308 | std::string manufacturer; |
| 309 | std::string model; |
| 310 | std::string partNumber; |
| 311 | std::string serialNumber; |
| 312 | std::set<std::string> sensors; |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 313 | std::string ledObjectPath; |
| 314 | LedState ledState; |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 315 | }; |
| 316 | |
| 317 | /** |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 318 | * @brief Get objects with connection necessary for sensors |
Kowalski, Kamil | 588c3f0 | 2018-04-03 14:55:27 +0200 | [diff] [blame] | 319 | * @param SensorsAsyncResp Pointer to object holding response data |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 320 | * @param sensorNames Sensors retrieved from chassis |
| 321 | * @param callback Callback for processing gathered connections |
| 322 | */ |
| 323 | template <typename Callback> |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 324 | void getObjectsWithConnection( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 325 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 326 | const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames, |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 327 | Callback&& callback) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 328 | { |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 329 | BMCWEB_LOG_DEBUG << "getObjectsWithConnection enter"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 330 | const std::string path = "/xyz/openbmc_project/sensors"; |
| 331 | const std::array<std::string, 1> interfaces = { |
| 332 | "xyz.openbmc_project.Sensor.Value"}; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 333 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 334 | // Response handler for parsing objects subtree |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 335 | auto respHandler = [callback{std::forward<Callback>(callback)}, |
| 336 | sensorsAsyncResp, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 337 | sensorNames](const boost::system::error_code ec, |
| 338 | const GetSubTreeType& subtree) { |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 339 | BMCWEB_LOG_DEBUG << "getObjectsWithConnection resp_handler enter"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 340 | if (ec) |
| 341 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 342 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 343 | BMCWEB_LOG_ERROR |
| 344 | << "getObjectsWithConnection resp_handler: Dbus error " << ec; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 345 | return; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 346 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 347 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 348 | BMCWEB_LOG_DEBUG << "Found " << subtree.size() << " subtrees"; |
| 349 | |
| 350 | // Make unique list of connections only for requested sensor types and |
| 351 | // found in the chassis |
| 352 | boost::container::flat_set<std::string> connections; |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 353 | std::set<std::pair<std::string, std::string>> objectsWithConnection; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 354 | // Intrinsic to avoid malloc. Most systems will have < 8 sensor |
| 355 | // producers |
| 356 | connections.reserve(8); |
| 357 | |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 358 | BMCWEB_LOG_DEBUG << "sensorNames list count: " << sensorNames->size(); |
| 359 | for (const std::string& tsensor : *sensorNames) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 360 | { |
| 361 | BMCWEB_LOG_DEBUG << "Sensor to find: " << tsensor; |
| 362 | } |
| 363 | |
| 364 | for (const std::pair< |
| 365 | std::string, |
| 366 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 367 | object : subtree) |
| 368 | { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 369 | if (sensorNames->find(object.first) != sensorNames->end()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 370 | { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 371 | for (const std::pair<std::string, std::vector<std::string>>& |
| 372 | objData : object.second) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 373 | { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 374 | BMCWEB_LOG_DEBUG << "Adding connection: " << objData.first; |
| 375 | connections.insert(objData.first); |
| 376 | objectsWithConnection.insert( |
| 377 | std::make_pair(object.first, objData.first)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | } |
| 381 | BMCWEB_LOG_DEBUG << "Found " << connections.size() << " connections"; |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 382 | callback(std::move(connections), std::move(objectsWithConnection)); |
| 383 | BMCWEB_LOG_DEBUG << "getObjectsWithConnection resp_handler exit"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 384 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 385 | // Make call to ObjectMapper to find all sensors objects |
| 386 | crow::connections::systemBus->async_method_call( |
| 387 | std::move(respHandler), "xyz.openbmc_project.ObjectMapper", |
| 388 | "/xyz/openbmc_project/object_mapper", |
| 389 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 2, interfaces); |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 390 | BMCWEB_LOG_DEBUG << "getObjectsWithConnection exit"; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * @brief Create connections necessary for sensors |
| 395 | * @param SensorsAsyncResp Pointer to object holding response data |
| 396 | * @param sensorNames Sensors retrieved from chassis |
| 397 | * @param callback Callback for processing gathered connections |
| 398 | */ |
| 399 | template <typename Callback> |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 400 | void getConnections( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 401 | std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 402 | const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames, |
| 403 | Callback&& callback) |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 404 | { |
| 405 | auto objectsWithConnectionCb = |
| 406 | [callback](const boost::container::flat_set<std::string>& connections, |
| 407 | const std::set<std::pair<std::string, std::string>>& |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 408 | /*objectsWithConnection*/) { callback(connections); }; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 409 | getObjectsWithConnection(sensorsAsyncResp, sensorNames, |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 410 | std::move(objectsWithConnectionCb)); |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /** |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 414 | * @brief Shrinks the list of sensors for processing |
| 415 | * @param SensorsAysncResp The class holding the Redfish response |
| 416 | * @param allSensors A list of all the sensors associated to the |
| 417 | * chassis element (i.e. baseboard, front panel, etc...) |
| 418 | * @param activeSensors A list that is a reduction of the incoming |
| 419 | * allSensors list. Eliminate Thermal sensors when a Power request is |
| 420 | * made, and eliminate Power sensors when a Thermal request is made. |
| 421 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 422 | inline void reduceSensorList( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 423 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 424 | const std::vector<std::string>* allSensors, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 425 | const std::shared_ptr<boost::container::flat_set<std::string>>& |
| 426 | activeSensors) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 427 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 428 | if (sensorsAsyncResp == nullptr) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 429 | { |
| 430 | return; |
| 431 | } |
| 432 | if ((allSensors == nullptr) || (activeSensors == nullptr)) |
| 433 | { |
| 434 | messages::resourceNotFound( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 435 | sensorsAsyncResp->asyncResp->res, sensorsAsyncResp->chassisSubNode, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 436 | sensorsAsyncResp->chassisSubNode == sensors::node::thermal |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 437 | ? "Temperatures" |
| 438 | : "Voltages"); |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 439 | |
| 440 | return; |
| 441 | } |
| 442 | if (allSensors->empty()) |
| 443 | { |
| 444 | // Nothing to do, the activeSensors object is also empty |
| 445 | return; |
| 446 | } |
| 447 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 448 | for (const char* type : sensorsAsyncResp->types) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 449 | { |
| 450 | for (const std::string& sensor : *allSensors) |
| 451 | { |
| 452 | if (boost::starts_with(sensor, type)) |
| 453 | { |
| 454 | activeSensors->emplace(sensor); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /** |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 461 | * @brief Retrieves valid chassis path |
| 462 | * @param asyncResp Pointer to object holding response data |
| 463 | * @param callback Callback for next step to get valid chassis path |
| 464 | */ |
| 465 | template <typename Callback> |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 466 | void getValidChassisPath(const std::shared_ptr<SensorsAsyncResp>& asyncResp, |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 467 | Callback&& callback) |
| 468 | { |
| 469 | BMCWEB_LOG_DEBUG << "checkChassisId enter"; |
| 470 | const std::array<const char*, 2> interfaces = { |
| 471 | "xyz.openbmc_project.Inventory.Item.Board", |
| 472 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 473 | |
| 474 | auto respHandler = |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 475 | [callback{std::forward<Callback>(callback)}, |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 476 | asyncResp](const boost::system::error_code ec, |
| 477 | const std::vector<std::string>& chassisPaths) mutable { |
| 478 | BMCWEB_LOG_DEBUG << "getValidChassisPath respHandler enter"; |
| 479 | if (ec) |
| 480 | { |
| 481 | BMCWEB_LOG_ERROR |
| 482 | << "getValidChassisPath respHandler DBUS error: " << ec; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 483 | messages::internalError(asyncResp->asyncResp->res); |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 484 | return; |
| 485 | } |
| 486 | |
| 487 | std::optional<std::string> chassisPath; |
| 488 | std::string chassisName; |
| 489 | for (const std::string& chassis : chassisPaths) |
| 490 | { |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 491 | sdbusplus::message::object_path path(chassis); |
| 492 | chassisName = path.filename(); |
| 493 | if (chassisName.empty()) |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 494 | { |
| 495 | BMCWEB_LOG_ERROR << "Failed to find '/' in " << chassis; |
| 496 | continue; |
| 497 | } |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 498 | if (chassisName == asyncResp->chassisId) |
| 499 | { |
| 500 | chassisPath = chassis; |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | callback(chassisPath); |
| 505 | }; |
| 506 | |
| 507 | // Get the Chassis Collection |
| 508 | crow::connections::systemBus->async_method_call( |
| 509 | respHandler, "xyz.openbmc_project.ObjectMapper", |
| 510 | "/xyz/openbmc_project/object_mapper", |
| 511 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", |
| 512 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 513 | BMCWEB_LOG_DEBUG << "checkChassisId exit"; |
| 514 | } |
| 515 | |
| 516 | /** |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 517 | * @brief Retrieves requested chassis sensors and redundancy data from DBus . |
Kowalski, Kamil | 588c3f0 | 2018-04-03 14:55:27 +0200 | [diff] [blame] | 518 | * @param SensorsAsyncResp Pointer to object holding response data |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 519 | * @param callback Callback for next step in gathered sensor processing |
| 520 | */ |
| 521 | template <typename Callback> |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 522 | void getChassis(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 523 | Callback&& callback) |
| 524 | { |
| 525 | BMCWEB_LOG_DEBUG << "getChassis enter"; |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 526 | const std::array<const char*, 2> interfaces = { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 527 | "xyz.openbmc_project.Inventory.Item.Board", |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 528 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 529 | auto respHandler = [callback{std::forward<Callback>(callback)}, |
| 530 | sensorsAsyncResp]( |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 531 | const boost::system::error_code ec, |
| 532 | const std::vector<std::string>& chassisPaths) { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 533 | BMCWEB_LOG_DEBUG << "getChassis respHandler enter"; |
| 534 | if (ec) |
| 535 | { |
| 536 | BMCWEB_LOG_ERROR << "getChassis respHandler DBUS error: " << ec; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 537 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 538 | return; |
| 539 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 540 | |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 541 | const std::string* chassisPath = nullptr; |
| 542 | std::string chassisName; |
| 543 | for (const std::string& chassis : chassisPaths) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 544 | { |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 545 | sdbusplus::message::object_path path(chassis); |
| 546 | chassisName = path.filename(); |
| 547 | if (chassisName.empty()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 548 | { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 549 | BMCWEB_LOG_ERROR << "Failed to find '/' in " << chassis; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 550 | continue; |
| 551 | } |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 552 | if (chassisName == sensorsAsyncResp->chassisId) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 553 | { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 554 | chassisPath = &chassis; |
| 555 | break; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 556 | } |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 557 | } |
| 558 | if (chassisPath == nullptr) |
| 559 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 560 | messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, |
| 561 | "Chassis", sensorsAsyncResp->chassisId); |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 562 | return; |
| 563 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 564 | |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 565 | const std::string& chassisSubNode = sensorsAsyncResp->chassisSubNode; |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 566 | if (chassisSubNode == sensors::node::power) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 567 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 568 | sensorsAsyncResp->asyncResp->res.jsonValue["@odata.type"] = |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 569 | "#Power.v1_5_2.Power"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 570 | } |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 571 | else if (chassisSubNode == sensors::node::thermal) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 572 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 573 | sensorsAsyncResp->asyncResp->res.jsonValue["@odata.type"] = |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 574 | "#Thermal.v1_4_0.Thermal"; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 575 | sensorsAsyncResp->asyncResp->res.jsonValue["Fans"] = |
| 576 | nlohmann::json::array(); |
| 577 | sensorsAsyncResp->asyncResp->res.jsonValue["Temperatures"] = |
Jennifer Lee | 4f9a213 | 2019-03-04 12:45:19 -0800 | [diff] [blame] | 578 | nlohmann::json::array(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 579 | } |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 580 | else if (chassisSubNode == sensors::node::sensors) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 581 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 582 | sensorsAsyncResp->asyncResp->res.jsonValue["@odata.type"] = |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 583 | "#SensorCollection.SensorCollection"; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 584 | sensorsAsyncResp->asyncResp->res.jsonValue["Description"] = |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 585 | "Collection of Sensors for this Chassis"; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 586 | sensorsAsyncResp->asyncResp->res.jsonValue["Members"] = |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 587 | nlohmann::json::array(); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 588 | sensorsAsyncResp->asyncResp->res.jsonValue["Members@odata.count"] = |
| 589 | 0; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 590 | } |
| 591 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 592 | if (chassisSubNode != sensors::node::sensors) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 593 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 594 | sensorsAsyncResp->asyncResp->res.jsonValue["Id"] = chassisSubNode; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 595 | } |
| 596 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 597 | sensorsAsyncResp->asyncResp->res.jsonValue["@odata.id"] = |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 598 | "/redfish/v1/Chassis/" + sensorsAsyncResp->chassisId + "/" + |
| 599 | chassisSubNode; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 600 | sensorsAsyncResp->asyncResp->res.jsonValue["Name"] = chassisSubNode; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 601 | // Get the list of all sensors for this Chassis element |
| 602 | std::string sensorPath = *chassisPath + "/all_sensors"; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 603 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 604 | *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper", |
| 605 | sensorPath, "xyz.openbmc_project.Association", "endpoints", |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 606 | [sensorsAsyncResp, |
| 607 | callback{std::forward<const Callback>(callback)}]( |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 608 | const boost::system::error_code& e, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 609 | const std::vector<std::string>& nodeSensorList) { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 610 | if (e) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 611 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 612 | if (e.value() != EBADR) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 613 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 614 | messages::internalError( |
| 615 | sensorsAsyncResp->asyncResp->res); |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 616 | return; |
| 617 | } |
| 618 | } |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 619 | const std::shared_ptr<boost::container::flat_set<std::string>> |
| 620 | culledSensorList = std::make_shared< |
| 621 | boost::container::flat_set<std::string>>(); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 622 | reduceSensorList(sensorsAsyncResp, &nodeSensorList, |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 623 | culledSensorList); |
| 624 | callback(culledSensorList); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 625 | }); |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 626 | }; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 627 | |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 628 | // Get the Chassis Collection |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 629 | crow::connections::systemBus->async_method_call( |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 630 | respHandler, "xyz.openbmc_project.ObjectMapper", |
| 631 | "/xyz/openbmc_project/object_mapper", |
| 632 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 633 | "/xyz/openbmc_project/inventory", 0, interfaces); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 634 | BMCWEB_LOG_DEBUG << "getChassis exit"; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /** |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 638 | * @brief Finds all DBus object paths that implement ObjectManager. |
| 639 | * |
| 640 | * Creates a mapping from the associated connection name to the object path. |
| 641 | * |
| 642 | * Finds the object paths asynchronously. Invokes callback when information has |
| 643 | * been obtained. |
| 644 | * |
| 645 | * The callback must have the following signature: |
| 646 | * @code |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 647 | * callback(std::shared_ptr<boost::container::flat_map<std::string, |
| 648 | * std::string>> objectMgrPaths) |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 649 | * @endcode |
| 650 | * |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 651 | * @param sensorsAsyncResp Pointer to object holding response data. |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 652 | * @param callback Callback to invoke when object paths obtained. |
| 653 | */ |
| 654 | template <typename Callback> |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 655 | void getObjectManagerPaths( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 656 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 657 | Callback&& callback) |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 658 | { |
| 659 | BMCWEB_LOG_DEBUG << "getObjectManagerPaths enter"; |
| 660 | const std::array<std::string, 1> interfaces = { |
| 661 | "org.freedesktop.DBus.ObjectManager"}; |
| 662 | |
| 663 | // Response handler for GetSubTree DBus method |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 664 | auto respHandler = [callback{std::forward<Callback>(callback)}, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 665 | sensorsAsyncResp](const boost::system::error_code ec, |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 666 | const GetSubTreeType& subtree) { |
| 667 | BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler enter"; |
| 668 | if (ec) |
| 669 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 670 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 671 | BMCWEB_LOG_ERROR << "getObjectManagerPaths respHandler: DBus error " |
| 672 | << ec; |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | // Loop over returned object paths |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 677 | std::shared_ptr<boost::container::flat_map<std::string, std::string>> |
| 678 | objectMgrPaths = std::make_shared< |
| 679 | boost::container::flat_map<std::string, std::string>>(); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 680 | for (const std::pair< |
| 681 | std::string, |
| 682 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 683 | object : subtree) |
| 684 | { |
| 685 | // Loop over connections for current object path |
| 686 | const std::string& objectPath = object.first; |
| 687 | for (const std::pair<std::string, std::vector<std::string>>& |
| 688 | objData : object.second) |
| 689 | { |
| 690 | // Add mapping from connection to object path |
| 691 | const std::string& connection = objData.first; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 692 | (*objectMgrPaths)[connection] = objectPath; |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 693 | BMCWEB_LOG_DEBUG << "Added mapping " << connection << " -> " |
| 694 | << objectPath; |
| 695 | } |
| 696 | } |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 697 | callback(objectMgrPaths); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 698 | BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler exit"; |
| 699 | }; |
| 700 | |
| 701 | // Query mapper for all DBus object paths that implement ObjectManager |
| 702 | crow::connections::systemBus->async_method_call( |
| 703 | std::move(respHandler), "xyz.openbmc_project.ObjectMapper", |
| 704 | "/xyz/openbmc_project/object_mapper", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 705 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, interfaces); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 706 | BMCWEB_LOG_DEBUG << "getObjectManagerPaths exit"; |
| 707 | } |
| 708 | |
| 709 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 710 | * @brief Returns the Redfish State value for the specified inventory item. |
| 711 | * @param inventoryItem D-Bus inventory item associated with a sensor. |
| 712 | * @return State value for inventory item. |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 713 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 714 | inline std::string getState(const InventoryItem* inventoryItem) |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 715 | { |
| 716 | if ((inventoryItem != nullptr) && !(inventoryItem->isPresent)) |
| 717 | { |
| 718 | return "Absent"; |
| 719 | } |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 720 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 721 | return "Enabled"; |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * @brief Returns the Redfish Health value for the specified sensor. |
| 726 | * @param sensorJson Sensor JSON object. |
| 727 | * @param interfacesDict Map of all sensor interfaces. |
| 728 | * @param inventoryItem D-Bus inventory item associated with the sensor. Will |
| 729 | * be nullptr if no associated inventory item was found. |
| 730 | * @return Health value for sensor. |
| 731 | */ |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 732 | inline std::string |
| 733 | getHealth(nlohmann::json& sensorJson, |
| 734 | const dbus::utility::DBusInteracesMap& interfacesDict, |
| 735 | const InventoryItem* inventoryItem) |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 736 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 737 | // Get current health value (if any) in the sensor JSON object. Some JSON |
| 738 | // objects contain multiple sensors (such as PowerSupplies). We want to set |
| 739 | // the overall health to be the most severe of any of the sensors. |
| 740 | std::string currentHealth; |
| 741 | auto statusIt = sensorJson.find("Status"); |
| 742 | if (statusIt != sensorJson.end()) |
| 743 | { |
| 744 | auto healthIt = statusIt->find("Health"); |
| 745 | if (healthIt != statusIt->end()) |
| 746 | { |
| 747 | std::string* health = healthIt->get_ptr<std::string*>(); |
| 748 | if (health != nullptr) |
| 749 | { |
| 750 | currentHealth = *health; |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | // If current health in JSON object is already Critical, return that. This |
| 756 | // should override the sensor health, which might be less severe. |
| 757 | if (currentHealth == "Critical") |
| 758 | { |
| 759 | return "Critical"; |
| 760 | } |
| 761 | |
| 762 | // Check if sensor has critical threshold alarm |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 763 | |
| 764 | for (auto& [interface, values] : interfacesDict) |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 765 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 766 | if (interface == "xyz.openbmc_project.Sensor.Threshold.Critical") |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 767 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 768 | for (auto& [valueName, value] : values) |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 769 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 770 | if (valueName == "CriticalAlarmHigh" || |
| 771 | valueName == "CriticalAlarmLow") |
| 772 | { |
| 773 | const bool* asserted = std::get_if<bool>(&value); |
| 774 | if (asserted == nullptr) |
| 775 | { |
| 776 | BMCWEB_LOG_ERROR << "Illegal sensor threshold"; |
| 777 | } |
| 778 | else if (*asserted) |
| 779 | { |
| 780 | return "Critical"; |
| 781 | } |
| 782 | } |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 787 | // Check if associated inventory item is not functional |
| 788 | if ((inventoryItem != nullptr) && !(inventoryItem->isFunctional)) |
| 789 | { |
| 790 | return "Critical"; |
| 791 | } |
| 792 | |
| 793 | // If current health in JSON object is already Warning, return that. This |
| 794 | // should override the sensor status, which might be less severe. |
| 795 | if (currentHealth == "Warning") |
| 796 | { |
| 797 | return "Warning"; |
| 798 | } |
| 799 | |
| 800 | // Check if sensor has warning threshold alarm |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 801 | for (auto& [interface, values] : interfacesDict) |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 802 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 803 | if (interface == "xyz.openbmc_project.Sensor.Threshold.Warning") |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 804 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 805 | for (auto& [valueName, value] : values) |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 806 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 807 | if (valueName == "WarningAlarmHigh" || |
| 808 | valueName == "WarningAlarmLow") |
| 809 | { |
| 810 | const bool* asserted = std::get_if<bool>(&value); |
| 811 | if (asserted == nullptr) |
| 812 | { |
| 813 | BMCWEB_LOG_ERROR << "Illegal sensor threshold"; |
| 814 | } |
| 815 | else if (*asserted) |
| 816 | { |
Ed Tanous | ebe4d91 | 2022-01-12 12:38:17 -0800 | [diff] [blame] | 817 | return "Warning"; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 818 | } |
| 819 | } |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | } |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 823 | |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 824 | return "OK"; |
| 825 | } |
| 826 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 827 | inline void setLedState(nlohmann::json& sensorJson, |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 828 | const InventoryItem* inventoryItem) |
| 829 | { |
| 830 | if (inventoryItem != nullptr && !inventoryItem->ledObjectPath.empty()) |
| 831 | { |
| 832 | switch (inventoryItem->ledState) |
| 833 | { |
| 834 | case LedState::OFF: |
| 835 | sensorJson["IndicatorLED"] = "Off"; |
| 836 | break; |
| 837 | case LedState::ON: |
| 838 | sensorJson["IndicatorLED"] = "Lit"; |
| 839 | break; |
| 840 | case LedState::BLINK: |
| 841 | sensorJson["IndicatorLED"] = "Blinking"; |
| 842 | break; |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 843 | case LedState::UNKNOWN: |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 844 | break; |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
James Feist | 34dd179 | 2019-05-17 14:10:54 -0700 | [diff] [blame] | 849 | /** |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 850 | * @brief Builds a json sensor representation of a sensor. |
| 851 | * @param sensorName The name of the sensor to be built |
Gunnar Mills | 274fad5 | 2018-06-13 15:45:36 -0500 | [diff] [blame] | 852 | * @param sensorType The type (temperature, fan_tach, etc) of the sensor to |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 853 | * build |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 854 | * @param sensorsAsyncResp Sensor metadata |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 855 | * @param interfacesDict A dictionary of the interfaces and properties of said |
| 856 | * interfaces to be built from |
| 857 | * @param sensor_json The json object to fill |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 858 | * @param inventoryItem D-Bus inventory item associated with the sensor. Will |
| 859 | * be nullptr if no associated inventory item was found. |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 860 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 861 | inline void objectInterfacesToJson( |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 862 | const std::string& sensorName, const std::string& sensorType, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 863 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 864 | const dbus::utility::DBusInteracesMap& interfacesDict, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 865 | nlohmann::json& sensorJson, InventoryItem* inventoryItem) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 866 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 867 | // Assume values exist as is (10^0 == 1) if no scale exists |
| 868 | int64_t scaleMultiplier = 0; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 869 | for (auto& [interface, values] : interfacesDict) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 870 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 871 | if (interface == "xyz.openbmc_project.Sensor.Value") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 872 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 873 | for (auto& [valueName, value] : values) |
| 874 | { |
| 875 | if (valueName == "Scale") |
| 876 | { |
| 877 | const int64_t* int64Value = std::get_if<int64_t>(&value); |
| 878 | if (int64Value != nullptr) |
| 879 | { |
| 880 | scaleMultiplier = *int64Value; |
| 881 | } |
| 882 | } |
| 883 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 884 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 885 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 886 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 887 | if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 888 | { |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 889 | // For sensors in SensorCollection we set Id instead of MemberId, |
| 890 | // including power sensors. |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 891 | sensorJson["Id"] = sensorName; |
| 892 | sensorJson["Name"] = boost::replace_all_copy(sensorName, "_", " "); |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 893 | } |
| 894 | else if (sensorType != "power") |
| 895 | { |
| 896 | // Set MemberId and Name for non-power sensors. For PowerSupplies and |
| 897 | // PowerControl, those properties have more general values because |
| 898 | // multiple sensors can be stored in the same JSON object. |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 899 | sensorJson["MemberId"] = sensorName; |
| 900 | sensorJson["Name"] = boost::replace_all_copy(sensorName, "_", " "); |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 901 | } |
Ed Tanous | e742b6c | 2019-05-03 15:06:53 -0700 | [diff] [blame] | 902 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 903 | sensorJson["Status"]["State"] = getState(inventoryItem); |
| 904 | sensorJson["Status"]["Health"] = |
| 905 | getHealth(sensorJson, interfacesDict, inventoryItem); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 906 | |
| 907 | // Parameter to set to override the type we get from dbus, and force it to |
| 908 | // int, regardless of what is available. This is used for schemas like fan, |
| 909 | // that require integers, not floats. |
| 910 | bool forceToInt = false; |
| 911 | |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 912 | nlohmann::json::json_pointer unit("/Reading"); |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 913 | if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 914 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 915 | sensorJson["@odata.type"] = "#Sensor.v1_0_0.Sensor"; |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 916 | |
| 917 | const std::string& readingType = sensors::toReadingType(sensorType); |
| 918 | if (readingType.empty()) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 919 | { |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 920 | BMCWEB_LOG_ERROR << "Redfish cannot map reading type for " |
| 921 | << sensorType; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 922 | } |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 923 | else |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 924 | { |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 925 | sensorJson["ReadingType"] = readingType; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 926 | } |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 927 | |
| 928 | const std::string& readingUnits = sensors::toReadingUnits(sensorType); |
| 929 | if (readingUnits.empty()) |
Adrian Ambrożewicz | f8ede15 | 2020-06-02 13:26:33 +0200 | [diff] [blame] | 930 | { |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 931 | BMCWEB_LOG_ERROR << "Redfish cannot map reading unit for " |
| 932 | << sensorType; |
| 933 | } |
| 934 | else |
| 935 | { |
| 936 | sensorJson["ReadingUnits"] = readingUnits; |
Adrian Ambrożewicz | f8ede15 | 2020-06-02 13:26:33 +0200 | [diff] [blame] | 937 | } |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 938 | } |
| 939 | else if (sensorType == "temperature") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 940 | { |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 941 | unit = "/ReadingCelsius"_json_pointer; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 942 | sensorJson["@odata.type"] = "#Thermal.v1_3_0.Temperature"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 943 | // TODO(ed) Documentation says that path should be type fan_tach, |
| 944 | // implementation seems to implement fan |
| 945 | } |
| 946 | else if (sensorType == "fan" || sensorType == "fan_tach") |
| 947 | { |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 948 | unit = "/Reading"_json_pointer; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 949 | sensorJson["ReadingUnits"] = "RPM"; |
| 950 | sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan"; |
| 951 | setLedState(sensorJson, inventoryItem); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 952 | forceToInt = true; |
| 953 | } |
Ed Tanous | 6f6d0d3 | 2018-10-12 11:16:43 -0700 | [diff] [blame] | 954 | else if (sensorType == "fan_pwm") |
| 955 | { |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 956 | unit = "/Reading"_json_pointer; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 957 | sensorJson["ReadingUnits"] = "Percent"; |
| 958 | sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan"; |
| 959 | setLedState(sensorJson, inventoryItem); |
Ed Tanous | 6f6d0d3 | 2018-10-12 11:16:43 -0700 | [diff] [blame] | 960 | forceToInt = true; |
| 961 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 962 | else if (sensorType == "voltage") |
| 963 | { |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 964 | unit = "/ReadingVolts"_json_pointer; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 965 | sensorJson["@odata.type"] = "#Power.v1_0_0.Voltage"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 966 | } |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 967 | else if (sensorType == "power") |
| 968 | { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 969 | std::string sensorNameLower = |
| 970 | boost::algorithm::to_lower_copy(sensorName); |
| 971 | |
Eddie James | 028f7eb | 2019-05-17 21:24:36 +0000 | [diff] [blame] | 972 | if (!sensorName.compare("total_power")) |
| 973 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 974 | sensorJson["@odata.type"] = "#Power.v1_0_0.PowerControl"; |
Gunnar Mills | 7ab06f4 | 2019-07-02 13:07:16 -0500 | [diff] [blame] | 975 | // Put multiple "sensors" into a single PowerControl, so have |
| 976 | // generic names for MemberId and Name. Follows Redfish mockup. |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 977 | sensorJson["MemberId"] = "0"; |
| 978 | sensorJson["Name"] = "Chassis Power Control"; |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 979 | unit = "/PowerConsumedWatts"_json_pointer; |
Eddie James | 028f7eb | 2019-05-17 21:24:36 +0000 | [diff] [blame] | 980 | } |
| 981 | else if (sensorNameLower.find("input") != std::string::npos) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 982 | { |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 983 | unit = "/PowerInputWatts"_json_pointer; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 984 | } |
| 985 | else |
| 986 | { |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 987 | unit = "/PowerOutputWatts"_json_pointer; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 988 | } |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 989 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 990 | else |
| 991 | { |
| 992 | BMCWEB_LOG_ERROR << "Redfish cannot map object type for " << sensorName; |
| 993 | return; |
| 994 | } |
| 995 | // Map of dbus interface name, dbus property name and redfish property_name |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 996 | std::vector< |
| 997 | std::tuple<const char*, const char*, nlohmann::json::json_pointer>> |
| 998 | properties; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 999 | properties.reserve(7); |
| 1000 | |
| 1001 | properties.emplace_back("xyz.openbmc_project.Sensor.Value", "Value", unit); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 1002 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 1003 | if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1004 | { |
| 1005 | properties.emplace_back( |
| 1006 | "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningHigh", |
| 1007 | "/Thresholds/UpperCaution/Reading"_json_pointer); |
| 1008 | properties.emplace_back( |
| 1009 | "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningLow", |
| 1010 | "/Thresholds/LowerCaution/Reading"_json_pointer); |
| 1011 | properties.emplace_back( |
| 1012 | "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalHigh", |
| 1013 | "/Thresholds/UpperCritical/Reading"_json_pointer); |
| 1014 | properties.emplace_back( |
| 1015 | "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalLow", |
| 1016 | "/Thresholds/LowerCritical/Reading"_json_pointer); |
| 1017 | } |
| 1018 | else if (sensorType != "power") |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 1019 | { |
| 1020 | properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1021 | "WarningHigh", |
| 1022 | "/UpperThresholdNonCritical"_json_pointer); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 1023 | properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1024 | "WarningLow", |
| 1025 | "/LowerThresholdNonCritical"_json_pointer); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 1026 | properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1027 | "CriticalHigh", |
| 1028 | "/UpperThresholdCritical"_json_pointer); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 1029 | properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1030 | "CriticalLow", |
| 1031 | "/LowerThresholdCritical"_json_pointer); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 1032 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1033 | |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 1034 | // TODO Need to get UpperThresholdFatal and LowerThresholdFatal |
| 1035 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 1036 | if (sensorsAsyncResp->chassisSubNode == sensors::node::sensors) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 1037 | { |
| 1038 | properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1039 | "/ReadingRangeMin"_json_pointer); |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 1040 | properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1041 | "/ReadingRangeMax"_json_pointer); |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 1042 | } |
| 1043 | else if (sensorType == "temperature") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1044 | { |
| 1045 | properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1046 | "/MinReadingRangeTemp"_json_pointer); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1047 | properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1048 | "/MaxReadingRangeTemp"_json_pointer); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1049 | } |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1050 | else if (sensorType != "power") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1051 | { |
| 1052 | properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1053 | "/MinReadingRange"_json_pointer); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1054 | properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue", |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1055 | "/MaxReadingRange"_json_pointer); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1058 | for (const std::tuple<const char*, const char*, |
| 1059 | nlohmann::json::json_pointer>& p : properties) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1060 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1061 | for (auto& [interface, values] : interfacesDict) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1062 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1063 | if (interface != std::get<0>(p)) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1064 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1065 | continue; |
| 1066 | } |
| 1067 | for (auto& [valueName, valueVariant] : values) |
| 1068 | { |
| 1069 | if (valueName != std::get<1>(p)) |
| 1070 | { |
| 1071 | continue; |
| 1072 | } |
Anthony Wilson | 3929aca | 2019-07-19 15:42:33 -0500 | [diff] [blame] | 1073 | |
| 1074 | // The property we want to set may be nested json, so use |
| 1075 | // a json_pointer for easy indexing into the json structure. |
| 1076 | const nlohmann::json::json_pointer& key = std::get<2>(p); |
| 1077 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1078 | // Attempt to pull the int64 directly |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1079 | const int64_t* int64Value = std::get_if<int64_t>(&valueVariant); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1080 | |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 1081 | const double* doubleValue = std::get_if<double>(&valueVariant); |
Eddie James | 028f7eb | 2019-05-17 21:24:36 +0000 | [diff] [blame] | 1082 | const uint32_t* uValue = std::get_if<uint32_t>(&valueVariant); |
Ed Tanous | 6f6d0d3 | 2018-10-12 11:16:43 -0700 | [diff] [blame] | 1083 | double temp = 0.0; |
| 1084 | if (int64Value != nullptr) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1085 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1086 | temp = static_cast<double>(*int64Value); |
Ed Tanous | 6f6d0d3 | 2018-10-12 11:16:43 -0700 | [diff] [blame] | 1087 | } |
| 1088 | else if (doubleValue != nullptr) |
| 1089 | { |
| 1090 | temp = *doubleValue; |
| 1091 | } |
Eddie James | 028f7eb | 2019-05-17 21:24:36 +0000 | [diff] [blame] | 1092 | else if (uValue != nullptr) |
| 1093 | { |
| 1094 | temp = *uValue; |
| 1095 | } |
Ed Tanous | 6f6d0d3 | 2018-10-12 11:16:43 -0700 | [diff] [blame] | 1096 | else |
| 1097 | { |
| 1098 | BMCWEB_LOG_ERROR |
| 1099 | << "Got value interface that wasn't int or double"; |
| 1100 | continue; |
| 1101 | } |
| 1102 | temp = temp * std::pow(10, scaleMultiplier); |
| 1103 | if (forceToInt) |
| 1104 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 1105 | sensorJson[key] = static_cast<int64_t>(temp); |
Ed Tanous | 6f6d0d3 | 2018-10-12 11:16:43 -0700 | [diff] [blame] | 1106 | } |
| 1107 | else |
| 1108 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 1109 | sensorJson[key] = temp; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | } |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 1114 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 1115 | sensorsAsyncResp->addMetadata(sensorJson, unit.to_string(), |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 1116 | "/xyz/openbmc_project/sensors/" + sensorType + |
| 1117 | "/" + sensorName); |
| 1118 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1119 | BMCWEB_LOG_DEBUG << "Added sensor " << sensorName; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 1120 | } |
| 1121 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1122 | inline void populateFanRedundancy( |
| 1123 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp) |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1124 | { |
| 1125 | crow::connections::systemBus->async_method_call( |
| 1126 | [sensorsAsyncResp](const boost::system::error_code ec, |
| 1127 | const GetSubTreeType& resp) { |
| 1128 | if (ec) |
| 1129 | { |
| 1130 | return; // don't have to have this interface |
| 1131 | } |
Ed Tanous | e278c18 | 2019-03-13 16:23:37 -0700 | [diff] [blame] | 1132 | for (const std::pair<std::string, |
| 1133 | std::vector<std::pair< |
| 1134 | std::string, std::vector<std::string>>>>& |
| 1135 | pathPair : resp) |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1136 | { |
Ed Tanous | e278c18 | 2019-03-13 16:23:37 -0700 | [diff] [blame] | 1137 | const std::string& path = pathPair.first; |
| 1138 | const std::vector< |
| 1139 | std::pair<std::string, std::vector<std::string>>>& objDict = |
| 1140 | pathPair.second; |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1141 | if (objDict.empty()) |
| 1142 | { |
| 1143 | continue; // this should be impossible |
| 1144 | } |
| 1145 | |
| 1146 | const std::string& owner = objDict.begin()->first; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1147 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 1148 | *crow::connections::systemBus, |
| 1149 | "xyz.openbmc_project.ObjectMapper", path + "/chassis", |
| 1150 | "xyz.openbmc_project.Association", "endpoints", |
| 1151 | [path, owner, sensorsAsyncResp]( |
| 1152 | const boost::system::error_code e, |
| 1153 | const std::vector<std::string>& endpoints) { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1154 | if (e) |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1155 | { |
| 1156 | return; // if they don't have an association we |
| 1157 | // can't tell what chassis is |
| 1158 | } |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1159 | auto found = std::find_if( |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1160 | endpoints.begin(), endpoints.end(), |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1161 | [sensorsAsyncResp](const std::string& entry) { |
| 1162 | return entry.find( |
| 1163 | sensorsAsyncResp->chassisId) != |
| 1164 | std::string::npos; |
| 1165 | }); |
| 1166 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1167 | if (found == endpoints.end()) |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1168 | { |
| 1169 | return; |
| 1170 | } |
| 1171 | crow::connections::systemBus->async_method_call( |
| 1172 | [path, sensorsAsyncResp]( |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1173 | const boost::system::error_code& err, |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1174 | const boost::container::flat_map< |
| 1175 | std::string, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1176 | dbus::utility::DbusVariantType>& ret) { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1177 | if (err) |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1178 | { |
| 1179 | return; // don't have to have this |
| 1180 | // interface |
| 1181 | } |
| 1182 | auto findFailures = ret.find("AllowedFailures"); |
| 1183 | auto findCollection = ret.find("Collection"); |
| 1184 | auto findStatus = ret.find("Status"); |
| 1185 | |
| 1186 | if (findFailures == ret.end() || |
| 1187 | findCollection == ret.end() || |
| 1188 | findStatus == ret.end()) |
| 1189 | { |
| 1190 | BMCWEB_LOG_ERROR |
| 1191 | << "Invalid redundancy interface"; |
| 1192 | messages::internalError( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1193 | sensorsAsyncResp->asyncResp->res); |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1194 | return; |
| 1195 | } |
| 1196 | |
| 1197 | auto allowedFailures = std::get_if<uint8_t>( |
| 1198 | &(findFailures->second)); |
| 1199 | auto collection = |
| 1200 | std::get_if<std::vector<std::string>>( |
| 1201 | &(findCollection->second)); |
| 1202 | auto status = std::get_if<std::string>( |
| 1203 | &(findStatus->second)); |
| 1204 | |
| 1205 | if (allowedFailures == nullptr || |
| 1206 | collection == nullptr || status == nullptr) |
| 1207 | { |
| 1208 | |
| 1209 | BMCWEB_LOG_ERROR |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1210 | << "Invalid redundancy interface types"; |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1211 | messages::internalError( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1212 | sensorsAsyncResp->asyncResp->res); |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1213 | return; |
| 1214 | } |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 1215 | sdbusplus::message::object_path objectPath( |
| 1216 | path); |
| 1217 | std::string name = objectPath.filename(); |
| 1218 | if (name.empty()) |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1219 | { |
| 1220 | // this should be impossible |
| 1221 | messages::internalError( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1222 | sensorsAsyncResp->asyncResp->res); |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1223 | return; |
| 1224 | } |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1225 | std::replace(name.begin(), name.end(), '_', |
| 1226 | ' '); |
| 1227 | |
| 1228 | std::string health; |
| 1229 | |
| 1230 | if (boost::ends_with(*status, "Full")) |
| 1231 | { |
| 1232 | health = "OK"; |
| 1233 | } |
| 1234 | else if (boost::ends_with(*status, "Degraded")) |
| 1235 | { |
| 1236 | health = "Warning"; |
| 1237 | } |
| 1238 | else |
| 1239 | { |
| 1240 | health = "Critical"; |
| 1241 | } |
| 1242 | std::vector<nlohmann::json> redfishCollection; |
| 1243 | const auto& fanRedfish = |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1244 | sensorsAsyncResp->asyncResp->res |
| 1245 | .jsonValue["Fans"]; |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1246 | for (const std::string& item : *collection) |
| 1247 | { |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 1248 | sdbusplus::message::object_path path(item); |
| 1249 | std::string itemName = path.filename(); |
| 1250 | if (itemName.empty()) |
| 1251 | { |
| 1252 | continue; |
| 1253 | } |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1254 | /* |
| 1255 | todo(ed): merge patch that fixes the names |
| 1256 | std::replace(itemName.begin(), |
| 1257 | itemName.end(), '_', ' ');*/ |
| 1258 | auto schemaItem = std::find_if( |
| 1259 | fanRedfish.begin(), fanRedfish.end(), |
| 1260 | [itemName](const nlohmann::json& fan) { |
| 1261 | return fan["MemberId"] == itemName; |
| 1262 | }); |
| 1263 | if (schemaItem != fanRedfish.end()) |
| 1264 | { |
| 1265 | redfishCollection.push_back( |
| 1266 | {{"@odata.id", |
| 1267 | (*schemaItem)["@odata.id"]}}); |
| 1268 | } |
| 1269 | else |
| 1270 | { |
| 1271 | BMCWEB_LOG_ERROR |
| 1272 | << "failed to find fan in schema"; |
| 1273 | messages::internalError( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1274 | sensorsAsyncResp->asyncResp->res); |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1275 | return; |
| 1276 | } |
| 1277 | } |
| 1278 | |
Kuiying Wang | 3e9e72e | 2020-07-07 10:18:32 +0800 | [diff] [blame] | 1279 | size_t minNumNeeded = |
| 1280 | collection->size() > 0 |
| 1281 | ? collection->size() - *allowedFailures |
| 1282 | : 0; |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1283 | nlohmann::json& jResp = |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1284 | sensorsAsyncResp->asyncResp->res |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1285 | .jsonValue["Redundancy"]; |
| 1286 | jResp.push_back( |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1287 | {{"@odata.id", |
AppaRao Puli | 717794d | 2019-10-18 22:54:53 +0530 | [diff] [blame] | 1288 | "/redfish/v1/Chassis/" + |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1289 | sensorsAsyncResp->chassisId + "/" + |
| 1290 | sensorsAsyncResp->chassisSubNode + |
| 1291 | "#/Redundancy/" + |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1292 | std::to_string(jResp.size())}, |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1293 | {"@odata.type", |
| 1294 | "#Redundancy.v1_3_2.Redundancy"}, |
Kuiying Wang | 3e9e72e | 2020-07-07 10:18:32 +0800 | [diff] [blame] | 1295 | {"MinNumNeeded", minNumNeeded}, |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1296 | {"MemberId", name}, |
| 1297 | {"Mode", "N+m"}, |
| 1298 | {"Name", name}, |
| 1299 | {"RedundancySet", redfishCollection}, |
| 1300 | {"Status", |
| 1301 | {{"Health", health}, |
| 1302 | {"State", "Enabled"}}}}); |
| 1303 | }, |
| 1304 | owner, path, "org.freedesktop.DBus.Properties", |
| 1305 | "GetAll", |
| 1306 | "xyz.openbmc_project.Control.FanRedundancy"); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1307 | }); |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 1308 | } |
| 1309 | }, |
| 1310 | "xyz.openbmc_project.ObjectMapper", |
| 1311 | "/xyz/openbmc_project/object_mapper", |
| 1312 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 1313 | "/xyz/openbmc_project/control", 2, |
| 1314 | std::array<const char*, 1>{ |
| 1315 | "xyz.openbmc_project.Control.FanRedundancy"}); |
| 1316 | } |
| 1317 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1318 | inline void |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 1319 | sortJSONResponse(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 1320 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1321 | nlohmann::json& response = sensorsAsyncResp->asyncResp->res.jsonValue; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 1322 | std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"}; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 1323 | if (sensorsAsyncResp->chassisSubNode == sensors::node::power) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 1324 | { |
| 1325 | sensorHeaders = {"Voltages", "PowerSupplies"}; |
| 1326 | } |
| 1327 | for (const std::string& sensorGroup : sensorHeaders) |
| 1328 | { |
| 1329 | nlohmann::json::iterator entry = response.find(sensorGroup); |
| 1330 | if (entry != response.end()) |
| 1331 | { |
| 1332 | std::sort(entry->begin(), entry->end(), |
| 1333 | [](nlohmann::json& c1, nlohmann::json& c2) { |
| 1334 | return c1["Name"] < c2["Name"]; |
| 1335 | }); |
| 1336 | |
| 1337 | // add the index counts to the end of each entry |
| 1338 | size_t count = 0; |
| 1339 | for (nlohmann::json& sensorJson : *entry) |
| 1340 | { |
| 1341 | nlohmann::json::iterator odata = sensorJson.find("@odata.id"); |
| 1342 | if (odata == sensorJson.end()) |
| 1343 | { |
| 1344 | continue; |
| 1345 | } |
| 1346 | std::string* value = odata->get_ptr<std::string*>(); |
| 1347 | if (value != nullptr) |
| 1348 | { |
| 1349 | *value += std::to_string(count); |
| 1350 | count++; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 1351 | sensorsAsyncResp->updateUri(sensorJson["Name"], *value); |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | } |
| 1357 | |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 1358 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1359 | * @brief Finds the inventory item with the specified object path. |
| 1360 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 1361 | * @param invItemObjPath D-Bus object path of inventory item. |
| 1362 | * @return Inventory item within vector, or nullptr if no match found. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1363 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1364 | inline InventoryItem* findInventoryItem( |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1365 | const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1366 | const std::string& invItemObjPath) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1367 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1368 | for (InventoryItem& inventoryItem : *inventoryItems) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1369 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1370 | if (inventoryItem.objectPath == invItemObjPath) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1371 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1372 | return &inventoryItem; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1373 | } |
| 1374 | } |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1375 | return nullptr; |
| 1376 | } |
| 1377 | |
| 1378 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1379 | * @brief Finds the inventory item associated with the specified sensor. |
| 1380 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 1381 | * @param sensorObjPath D-Bus object path of sensor. |
| 1382 | * @return Inventory item within vector, or nullptr if no match found. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1383 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1384 | inline InventoryItem* findInventoryItemForSensor( |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1385 | const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1386 | const std::string& sensorObjPath) |
| 1387 | { |
| 1388 | for (InventoryItem& inventoryItem : *inventoryItems) |
| 1389 | { |
| 1390 | if (inventoryItem.sensors.count(sensorObjPath) > 0) |
| 1391 | { |
| 1392 | return &inventoryItem; |
| 1393 | } |
| 1394 | } |
| 1395 | return nullptr; |
| 1396 | } |
| 1397 | |
| 1398 | /** |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1399 | * @brief Finds the inventory item associated with the specified led path. |
| 1400 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 1401 | * @param ledObjPath D-Bus object path of led. |
| 1402 | * @return Inventory item within vector, or nullptr if no match found. |
| 1403 | */ |
| 1404 | inline InventoryItem* |
| 1405 | findInventoryItemForLed(std::vector<InventoryItem>& inventoryItems, |
| 1406 | const std::string& ledObjPath) |
| 1407 | { |
| 1408 | for (InventoryItem& inventoryItem : inventoryItems) |
| 1409 | { |
| 1410 | if (inventoryItem.ledObjectPath == ledObjPath) |
| 1411 | { |
| 1412 | return &inventoryItem; |
| 1413 | } |
| 1414 | } |
| 1415 | return nullptr; |
| 1416 | } |
| 1417 | |
| 1418 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1419 | * @brief Adds inventory item and associated sensor to specified vector. |
| 1420 | * |
| 1421 | * Adds a new InventoryItem to the vector if necessary. Searches for an |
| 1422 | * existing InventoryItem with the specified object path. If not found, one is |
| 1423 | * added to the vector. |
| 1424 | * |
| 1425 | * Next, the specified sensor is added to the set of sensors associated with the |
| 1426 | * InventoryItem. |
| 1427 | * |
| 1428 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 1429 | * @param invItemObjPath D-Bus object path of inventory item. |
| 1430 | * @param sensorObjPath D-Bus object path of sensor |
| 1431 | */ |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1432 | inline void addInventoryItem( |
| 1433 | const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, |
| 1434 | const std::string& invItemObjPath, const std::string& sensorObjPath) |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1435 | { |
| 1436 | // Look for inventory item in vector |
| 1437 | InventoryItem* inventoryItem = |
| 1438 | findInventoryItem(inventoryItems, invItemObjPath); |
| 1439 | |
| 1440 | // If inventory item doesn't exist in vector, add it |
| 1441 | if (inventoryItem == nullptr) |
| 1442 | { |
| 1443 | inventoryItems->emplace_back(invItemObjPath); |
| 1444 | inventoryItem = &(inventoryItems->back()); |
| 1445 | } |
| 1446 | |
| 1447 | // Add sensor to set of sensors associated with inventory item |
| 1448 | inventoryItem->sensors.emplace(sensorObjPath); |
| 1449 | } |
| 1450 | |
| 1451 | /** |
| 1452 | * @brief Stores D-Bus data in the specified inventory item. |
| 1453 | * |
| 1454 | * Finds D-Bus data in the specified map of interfaces. Stores the data in the |
| 1455 | * specified InventoryItem. |
| 1456 | * |
| 1457 | * This data is later used to provide sensor property values in the JSON |
| 1458 | * response. |
| 1459 | * |
| 1460 | * @param inventoryItem Inventory item where data will be stored. |
| 1461 | * @param interfacesDict Map containing D-Bus interfaces and their properties |
| 1462 | * for the specified inventory item. |
| 1463 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1464 | inline void storeInventoryItemData( |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1465 | InventoryItem& inventoryItem, |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1466 | const dbus::utility::DBusInteracesMap& interfacesDict) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1467 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1468 | // Get properties from Inventory.Item interface |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1469 | |
| 1470 | for (auto& [interface, values] : interfacesDict) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1471 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1472 | if (interface == "xyz.openbmc_project.Inventory.Item") |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1473 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1474 | for (auto& [name, dbusValue] : values) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1475 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1476 | if (name == "Present") |
| 1477 | { |
| 1478 | const bool* value = std::get_if<bool>(&dbusValue); |
| 1479 | if (value != nullptr) |
| 1480 | { |
| 1481 | inventoryItem.isPresent = *value; |
| 1482 | } |
| 1483 | } |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1484 | } |
| 1485 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1486 | // Check if Inventory.Item.PowerSupply interface is present |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1487 | |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1488 | if (interface == "xyz.openbmc_project.Inventory.Item.PowerSupply") |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1489 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1490 | inventoryItem.isPowerSupply = true; |
| 1491 | } |
| 1492 | |
| 1493 | // Get properties from Inventory.Decorator.Asset interface |
| 1494 | if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") |
| 1495 | { |
| 1496 | for (auto& [name, dbusValue] : values) |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1497 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1498 | if (name == "Manufacturer") |
| 1499 | { |
| 1500 | const std::string* value = |
| 1501 | std::get_if<std::string>(&dbusValue); |
| 1502 | if (value != nullptr) |
| 1503 | { |
| 1504 | inventoryItem.manufacturer = *value; |
| 1505 | } |
| 1506 | } |
| 1507 | if (name == "Model") |
| 1508 | { |
| 1509 | const std::string* value = |
| 1510 | std::get_if<std::string>(&dbusValue); |
| 1511 | if (value != nullptr) |
| 1512 | { |
| 1513 | inventoryItem.model = *value; |
| 1514 | } |
| 1515 | } |
| 1516 | if (name == "SerialNumber") |
| 1517 | { |
| 1518 | const std::string* value = |
| 1519 | std::get_if<std::string>(&dbusValue); |
| 1520 | if (value != nullptr) |
| 1521 | { |
| 1522 | inventoryItem.serialNumber = *value; |
| 1523 | } |
| 1524 | } |
| 1525 | if (name == "PartNumber") |
| 1526 | { |
| 1527 | const std::string* value = |
| 1528 | std::get_if<std::string>(&dbusValue); |
| 1529 | if (value != nullptr) |
| 1530 | { |
| 1531 | inventoryItem.partNumber = *value; |
| 1532 | } |
| 1533 | } |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1537 | if (interface == |
| 1538 | "xyz.openbmc_project.State.Decorator.OperationalStatus") |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1539 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1540 | for (auto& [name, dbusValue] : values) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1541 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1542 | if (name == "Functional") |
| 1543 | { |
| 1544 | const bool* value = std::get_if<bool>(&dbusValue); |
| 1545 | if (value != nullptr) |
| 1546 | { |
| 1547 | inventoryItem.isFunctional = *value; |
| 1548 | } |
| 1549 | } |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1556 | * @brief Gets D-Bus data for inventory items associated with sensors. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1557 | * |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1558 | * Uses the specified connections (services) to obtain D-Bus data for inventory |
| 1559 | * items associated with sensors. Stores the resulting data in the |
| 1560 | * inventoryItems vector. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1561 | * |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1562 | * This data is later used to provide sensor property values in the JSON |
| 1563 | * response. |
| 1564 | * |
| 1565 | * Finds the inventory item data asynchronously. Invokes callback when data has |
| 1566 | * been obtained. |
| 1567 | * |
| 1568 | * The callback must have the following signature: |
| 1569 | * @code |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1570 | * callback(void) |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1571 | * @endcode |
| 1572 | * |
| 1573 | * This function is called recursively, obtaining data asynchronously from one |
| 1574 | * connection in each call. This ensures the callback is not invoked until the |
| 1575 | * last asynchronous function has completed. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1576 | * |
| 1577 | * @param sensorsAsyncResp Pointer to object holding response data. |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1578 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 1579 | * @param invConnections Connections that provide data for the inventory items. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1580 | * @param objectMgrPaths Mappings from connection name to DBus object path that |
| 1581 | * implements ObjectManager. |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1582 | * @param callback Callback to invoke when inventory data has been obtained. |
| 1583 | * @param invConnectionsIndex Current index in invConnections. Only specified |
| 1584 | * in recursive calls to this function. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1585 | */ |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1586 | template <typename Callback> |
| 1587 | static void getInventoryItemsData( |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1588 | std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1589 | std::shared_ptr<std::vector<InventoryItem>> inventoryItems, |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1590 | std::shared_ptr<boost::container::flat_set<std::string>> invConnections, |
| 1591 | std::shared_ptr<boost::container::flat_map<std::string, std::string>> |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1592 | objectMgrPaths, |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 1593 | Callback&& callback, size_t invConnectionsIndex = 0) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1594 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1595 | BMCWEB_LOG_DEBUG << "getInventoryItemsData enter"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1596 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1597 | // If no more connections left, call callback |
| 1598 | if (invConnectionsIndex >= invConnections->size()) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1599 | { |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1600 | callback(); |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1601 | BMCWEB_LOG_DEBUG << "getInventoryItemsData exit"; |
| 1602 | return; |
| 1603 | } |
| 1604 | |
| 1605 | // Get inventory item data from current connection |
| 1606 | auto it = invConnections->nth(invConnectionsIndex); |
| 1607 | if (it != invConnections->end()) |
| 1608 | { |
| 1609 | const std::string& invConnection = *it; |
| 1610 | |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1611 | // Response handler for GetManagedObjects |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1612 | auto respHandler = [sensorsAsyncResp, inventoryItems, invConnections, |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 1613 | objectMgrPaths, |
| 1614 | callback{std::forward<Callback>(callback)}, |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1615 | invConnectionsIndex]( |
| 1616 | const boost::system::error_code ec, |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1617 | dbus::utility::ManagedObjectType& resp) { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1618 | BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler enter"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1619 | if (ec) |
| 1620 | { |
| 1621 | BMCWEB_LOG_ERROR |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1622 | << "getInventoryItemsData respHandler DBus error " << ec; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1623 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1624 | return; |
| 1625 | } |
| 1626 | |
| 1627 | // Loop through returned object paths |
| 1628 | for (const auto& objDictEntry : resp) |
| 1629 | { |
| 1630 | const std::string& objPath = |
| 1631 | static_cast<const std::string&>(objDictEntry.first); |
| 1632 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1633 | // If this object path is one of the specified inventory items |
| 1634 | InventoryItem* inventoryItem = |
| 1635 | findInventoryItem(inventoryItems, objPath); |
| 1636 | if (inventoryItem != nullptr) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1637 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1638 | // Store inventory data in InventoryItem |
| 1639 | storeInventoryItemData(*inventoryItem, objDictEntry.second); |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1640 | } |
| 1641 | } |
| 1642 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1643 | // Recurse to get inventory item data from next connection |
| 1644 | getInventoryItemsData(sensorsAsyncResp, inventoryItems, |
| 1645 | invConnections, objectMgrPaths, |
| 1646 | std::move(callback), invConnectionsIndex + 1); |
| 1647 | |
| 1648 | BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler exit"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1649 | }; |
| 1650 | |
| 1651 | // Find DBus object path that implements ObjectManager for the current |
| 1652 | // connection. If no mapping found, default to "/". |
| 1653 | auto iter = objectMgrPaths->find(invConnection); |
| 1654 | const std::string& objectMgrPath = |
| 1655 | (iter != objectMgrPaths->end()) ? iter->second : "/"; |
| 1656 | BMCWEB_LOG_DEBUG << "ObjectManager path for " << invConnection << " is " |
| 1657 | << objectMgrPath; |
| 1658 | |
| 1659 | // Get all object paths and their interfaces for current connection |
| 1660 | crow::connections::systemBus->async_method_call( |
| 1661 | std::move(respHandler), invConnection, objectMgrPath, |
| 1662 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 1663 | } |
| 1664 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1665 | BMCWEB_LOG_DEBUG << "getInventoryItemsData exit"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1669 | * @brief Gets connections that provide D-Bus data for inventory items. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1670 | * |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1671 | * Gets the D-Bus connections (services) that provide data for the inventory |
| 1672 | * items that are associated with sensors. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1673 | * |
| 1674 | * Finds the connections asynchronously. Invokes callback when information has |
| 1675 | * been obtained. |
| 1676 | * |
| 1677 | * The callback must have the following signature: |
| 1678 | * @code |
| 1679 | * callback(std::shared_ptr<boost::container::flat_set<std::string>> |
| 1680 | * invConnections) |
| 1681 | * @endcode |
| 1682 | * |
| 1683 | * @param sensorsAsyncResp Pointer to object holding response data. |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1684 | * @param inventoryItems D-Bus inventory items associated with sensors. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1685 | * @param callback Callback to invoke when connections have been obtained. |
| 1686 | */ |
| 1687 | template <typename Callback> |
| 1688 | static void getInventoryItemsConnections( |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1689 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
| 1690 | const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems, |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1691 | Callback&& callback) |
| 1692 | { |
| 1693 | BMCWEB_LOG_DEBUG << "getInventoryItemsConnections enter"; |
| 1694 | |
| 1695 | const std::string path = "/xyz/openbmc_project/inventory"; |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1696 | const std::array<std::string, 4> interfaces = { |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1697 | "xyz.openbmc_project.Inventory.Item", |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1698 | "xyz.openbmc_project.Inventory.Item.PowerSupply", |
| 1699 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1700 | "xyz.openbmc_project.State.Decorator.OperationalStatus"}; |
| 1701 | |
| 1702 | // Response handler for parsing output from GetSubTree |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 1703 | auto respHandler = [callback{std::forward<Callback>(callback)}, |
| 1704 | sensorsAsyncResp, |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1705 | inventoryItems](const boost::system::error_code ec, |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1706 | const GetSubTreeType& subtree) { |
| 1707 | BMCWEB_LOG_DEBUG << "getInventoryItemsConnections respHandler enter"; |
| 1708 | if (ec) |
| 1709 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1710 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1711 | BMCWEB_LOG_ERROR |
| 1712 | << "getInventoryItemsConnections respHandler DBus error " << ec; |
| 1713 | return; |
| 1714 | } |
| 1715 | |
| 1716 | // Make unique list of connections for desired inventory items |
| 1717 | std::shared_ptr<boost::container::flat_set<std::string>> |
| 1718 | invConnections = |
| 1719 | std::make_shared<boost::container::flat_set<std::string>>(); |
| 1720 | invConnections->reserve(8); |
| 1721 | |
| 1722 | // Loop through objects from GetSubTree |
| 1723 | for (const std::pair< |
| 1724 | std::string, |
| 1725 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 1726 | object : subtree) |
| 1727 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1728 | // Check if object path is one of the specified inventory items |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1729 | const std::string& objPath = object.first; |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1730 | if (findInventoryItem(inventoryItems, objPath) != nullptr) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1731 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1732 | // Store all connections to inventory item |
| 1733 | for (const std::pair<std::string, std::vector<std::string>>& |
| 1734 | objData : object.second) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1735 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1736 | const std::string& invConnection = objData.first; |
| 1737 | invConnections->insert(invConnection); |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1738 | } |
| 1739 | } |
| 1740 | } |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1741 | |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1742 | callback(invConnections); |
| 1743 | BMCWEB_LOG_DEBUG << "getInventoryItemsConnections respHandler exit"; |
| 1744 | }; |
| 1745 | |
| 1746 | // Make call to ObjectMapper to find all inventory items |
| 1747 | crow::connections::systemBus->async_method_call( |
| 1748 | std::move(respHandler), "xyz.openbmc_project.ObjectMapper", |
| 1749 | "/xyz/openbmc_project/object_mapper", |
| 1750 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 0, interfaces); |
| 1751 | BMCWEB_LOG_DEBUG << "getInventoryItemsConnections exit"; |
| 1752 | } |
| 1753 | |
| 1754 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1755 | * @brief Gets associations from sensors to inventory items. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1756 | * |
| 1757 | * Looks for ObjectMapper associations from the specified sensors to related |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1758 | * inventory items. Then finds the associations from those inventory items to |
| 1759 | * their LEDs, if any. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1760 | * |
| 1761 | * Finds the inventory items asynchronously. Invokes callback when information |
| 1762 | * has been obtained. |
| 1763 | * |
| 1764 | * The callback must have the following signature: |
| 1765 | * @code |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1766 | * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1767 | * @endcode |
| 1768 | * |
| 1769 | * @param sensorsAsyncResp Pointer to object holding response data. |
| 1770 | * @param sensorNames All sensors within the current chassis. |
| 1771 | * @param objectMgrPaths Mappings from connection name to DBus object path that |
| 1772 | * implements ObjectManager. |
| 1773 | * @param callback Callback to invoke when inventory items have been obtained. |
| 1774 | */ |
| 1775 | template <typename Callback> |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1776 | static void getInventoryItemAssociations( |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1777 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
| 1778 | const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames, |
| 1779 | const std::shared_ptr<boost::container::flat_map<std::string, std::string>>& |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1780 | objectMgrPaths, |
| 1781 | Callback&& callback) |
| 1782 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1783 | BMCWEB_LOG_DEBUG << "getInventoryItemAssociations enter"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1784 | |
| 1785 | // Response handler for GetManagedObjects |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 1786 | auto respHandler = [callback{std::forward<Callback>(callback)}, |
| 1787 | sensorsAsyncResp, |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1788 | sensorNames](const boost::system::error_code ec, |
| 1789 | dbus::utility::ManagedObjectType& resp) { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1790 | BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler enter"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1791 | if (ec) |
| 1792 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1793 | BMCWEB_LOG_ERROR |
| 1794 | << "getInventoryItemAssociations respHandler DBus error " << ec; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1795 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1796 | return; |
| 1797 | } |
| 1798 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1799 | // Create vector to hold list of inventory items |
| 1800 | std::shared_ptr<std::vector<InventoryItem>> inventoryItems = |
| 1801 | std::make_shared<std::vector<InventoryItem>>(); |
| 1802 | |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1803 | // Loop through returned object paths |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1804 | std::string sensorAssocPath; |
| 1805 | sensorAssocPath.reserve(128); // avoid memory allocations |
| 1806 | for (const auto& objDictEntry : resp) |
| 1807 | { |
| 1808 | const std::string& objPath = |
| 1809 | static_cast<const std::string&>(objDictEntry.first); |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1810 | |
| 1811 | // If path is inventory association for one of the specified sensors |
| 1812 | for (const std::string& sensorName : *sensorNames) |
| 1813 | { |
| 1814 | sensorAssocPath = sensorName; |
| 1815 | sensorAssocPath += "/inventory"; |
| 1816 | if (objPath == sensorAssocPath) |
| 1817 | { |
| 1818 | // Get Association interface for object path |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1819 | for (const auto& [interface, values] : objDictEntry.second) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1820 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1821 | if (interface == "xyz.openbmc_project.Association") |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1822 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1823 | for (const auto& [valueName, value] : values) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1824 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1825 | if (valueName == "endpoints") |
| 1826 | { |
| 1827 | const std::vector<std::string>* endpoints = |
| 1828 | std::get_if<std::vector<std::string>>( |
| 1829 | &value); |
| 1830 | if ((endpoints != nullptr) && |
| 1831 | !endpoints->empty()) |
| 1832 | { |
| 1833 | // Add inventory item to vector |
| 1834 | const std::string& invItemPath = |
| 1835 | endpoints->front(); |
| 1836 | addInventoryItem(inventoryItems, |
| 1837 | invItemPath, |
| 1838 | sensorName); |
| 1839 | } |
| 1840 | } |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1841 | } |
| 1842 | } |
| 1843 | } |
| 1844 | break; |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1849 | // Now loop through the returned object paths again, this time to |
| 1850 | // find the leds associated with the inventory items we just found |
| 1851 | std::string inventoryAssocPath; |
| 1852 | inventoryAssocPath.reserve(128); // avoid memory allocations |
| 1853 | for (const auto& objDictEntry : resp) |
| 1854 | { |
| 1855 | const std::string& objPath = |
| 1856 | static_cast<const std::string&>(objDictEntry.first); |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1857 | |
| 1858 | for (InventoryItem& inventoryItem : *inventoryItems) |
| 1859 | { |
| 1860 | inventoryAssocPath = inventoryItem.objectPath; |
| 1861 | inventoryAssocPath += "/leds"; |
| 1862 | if (objPath == inventoryAssocPath) |
| 1863 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1864 | for (const auto& [interface, values] : objDictEntry.second) |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1865 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1866 | if (interface == "xyz.openbmc_project.Association") |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1867 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1868 | for (const auto& [valueName, value] : values) |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1869 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1870 | if (valueName == "endpoints") |
| 1871 | { |
| 1872 | const std::vector<std::string>* endpoints = |
| 1873 | std::get_if<std::vector<std::string>>( |
| 1874 | &value); |
| 1875 | if ((endpoints != nullptr) && |
| 1876 | !endpoints->empty()) |
| 1877 | { |
| 1878 | // Add inventory item to vector |
| 1879 | // Store LED path in inventory item |
| 1880 | const std::string& ledPath = |
| 1881 | endpoints->front(); |
| 1882 | inventoryItem.ledObjectPath = ledPath; |
| 1883 | } |
| 1884 | } |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 1888 | |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1889 | break; |
| 1890 | } |
| 1891 | } |
| 1892 | } |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1893 | callback(inventoryItems); |
| 1894 | BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler exit"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1895 | }; |
| 1896 | |
| 1897 | // Find DBus object path that implements ObjectManager for ObjectMapper |
| 1898 | std::string connection = "xyz.openbmc_project.ObjectMapper"; |
| 1899 | auto iter = objectMgrPaths->find(connection); |
| 1900 | const std::string& objectMgrPath = |
| 1901 | (iter != objectMgrPaths->end()) ? iter->second : "/"; |
| 1902 | BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is " |
| 1903 | << objectMgrPath; |
| 1904 | |
| 1905 | // Call GetManagedObjects on the ObjectMapper to get all associations |
| 1906 | crow::connections::systemBus->async_method_call( |
| 1907 | std::move(respHandler), connection, objectMgrPath, |
| 1908 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 1909 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 1910 | BMCWEB_LOG_DEBUG << "getInventoryItemAssociations exit"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | /** |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1914 | * @brief Gets D-Bus data for inventory item leds associated with sensors. |
| 1915 | * |
| 1916 | * Uses the specified connections (services) to obtain D-Bus data for inventory |
| 1917 | * item leds associated with sensors. Stores the resulting data in the |
| 1918 | * inventoryItems vector. |
| 1919 | * |
| 1920 | * This data is later used to provide sensor property values in the JSON |
| 1921 | * response. |
| 1922 | * |
| 1923 | * Finds the inventory item led data asynchronously. Invokes callback when data |
| 1924 | * has been obtained. |
| 1925 | * |
| 1926 | * The callback must have the following signature: |
| 1927 | * @code |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 1928 | * callback() |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1929 | * @endcode |
| 1930 | * |
| 1931 | * This function is called recursively, obtaining data asynchronously from one |
| 1932 | * connection in each call. This ensures the callback is not invoked until the |
| 1933 | * last asynchronous function has completed. |
| 1934 | * |
| 1935 | * @param sensorsAsyncResp Pointer to object holding response data. |
| 1936 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 1937 | * @param ledConnections Connections that provide data for the inventory leds. |
| 1938 | * @param callback Callback to invoke when inventory data has been obtained. |
| 1939 | * @param ledConnectionsIndex Current index in ledConnections. Only specified |
| 1940 | * in recursive calls to this function. |
| 1941 | */ |
| 1942 | template <typename Callback> |
| 1943 | void getInventoryLedData( |
| 1944 | std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, |
| 1945 | std::shared_ptr<std::vector<InventoryItem>> inventoryItems, |
| 1946 | std::shared_ptr<boost::container::flat_map<std::string, std::string>> |
| 1947 | ledConnections, |
| 1948 | Callback&& callback, size_t ledConnectionsIndex = 0) |
| 1949 | { |
| 1950 | BMCWEB_LOG_DEBUG << "getInventoryLedData enter"; |
| 1951 | |
| 1952 | // If no more connections left, call callback |
| 1953 | if (ledConnectionsIndex >= ledConnections->size()) |
| 1954 | { |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 1955 | callback(); |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1956 | BMCWEB_LOG_DEBUG << "getInventoryLedData exit"; |
| 1957 | return; |
| 1958 | } |
| 1959 | |
| 1960 | // Get inventory item data from current connection |
| 1961 | auto it = ledConnections->nth(ledConnectionsIndex); |
| 1962 | if (it != ledConnections->end()) |
| 1963 | { |
| 1964 | const std::string& ledPath = (*it).first; |
| 1965 | const std::string& ledConnection = (*it).second; |
| 1966 | // Response handler for Get State property |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1967 | auto respHandler = |
| 1968 | [sensorsAsyncResp, inventoryItems, ledConnections, ledPath, |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 1969 | callback{std::forward<Callback>(callback)}, ledConnectionsIndex]( |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1970 | const boost::system::error_code ec, const std::string& state) { |
| 1971 | BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter"; |
| 1972 | if (ec) |
| 1973 | { |
| 1974 | BMCWEB_LOG_ERROR |
| 1975 | << "getInventoryLedData respHandler DBus error " << ec; |
| 1976 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
| 1977 | return; |
| 1978 | } |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1979 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1980 | BMCWEB_LOG_DEBUG << "Led state: " << state; |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1981 | // Find inventory item with this LED object path |
| 1982 | InventoryItem* inventoryItem = |
| 1983 | findInventoryItemForLed(*inventoryItems, ledPath); |
| 1984 | if (inventoryItem != nullptr) |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1985 | { |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1986 | // Store LED state in InventoryItem |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1987 | if (boost::ends_with(state, "On")) |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 1988 | { |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1989 | inventoryItem->ledState = LedState::ON; |
| 1990 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1991 | else if (boost::ends_with(state, "Blink")) |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1992 | { |
| 1993 | inventoryItem->ledState = LedState::BLINK; |
| 1994 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1995 | else if (boost::ends_with(state, "Off")) |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 1996 | { |
| 1997 | inventoryItem->ledState = LedState::OFF; |
| 1998 | } |
| 1999 | else |
| 2000 | { |
| 2001 | inventoryItem->ledState = LedState::UNKNOWN; |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2002 | } |
| 2003 | } |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2004 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2005 | // Recurse to get LED data from next connection |
| 2006 | getInventoryLedData(sensorsAsyncResp, inventoryItems, |
| 2007 | ledConnections, std::move(callback), |
| 2008 | ledConnectionsIndex + 1); |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2009 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2010 | BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler exit"; |
| 2011 | }; |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2012 | |
| 2013 | // Get the State property for the current LED |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2014 | sdbusplus::asio::getProperty<std::string>( |
| 2015 | *crow::connections::systemBus, ledConnection, ledPath, |
| 2016 | "xyz.openbmc_project.Led.Physical", "State", |
| 2017 | std::move(respHandler)); |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | BMCWEB_LOG_DEBUG << "getInventoryLedData exit"; |
| 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * @brief Gets LED data for LEDs associated with given inventory items. |
| 2025 | * |
| 2026 | * Gets the D-Bus connections (services) that provide LED data for the LEDs |
| 2027 | * associated with the specified inventory items. Then gets the LED data from |
| 2028 | * each connection and stores it in the inventory item. |
| 2029 | * |
| 2030 | * This data is later used to provide sensor property values in the JSON |
| 2031 | * response. |
| 2032 | * |
| 2033 | * Finds the LED data asynchronously. Invokes callback when information has |
| 2034 | * been obtained. |
| 2035 | * |
| 2036 | * The callback must have the following signature: |
| 2037 | * @code |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2038 | * callback() |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2039 | * @endcode |
| 2040 | * |
| 2041 | * @param sensorsAsyncResp Pointer to object holding response data. |
| 2042 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 2043 | * @param callback Callback to invoke when inventory items have been obtained. |
| 2044 | */ |
| 2045 | template <typename Callback> |
| 2046 | void getInventoryLeds( |
| 2047 | std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, |
| 2048 | std::shared_ptr<std::vector<InventoryItem>> inventoryItems, |
| 2049 | Callback&& callback) |
| 2050 | { |
| 2051 | BMCWEB_LOG_DEBUG << "getInventoryLeds enter"; |
| 2052 | |
| 2053 | const std::string path = "/xyz/openbmc_project"; |
| 2054 | const std::array<std::string, 1> interfaces = { |
| 2055 | "xyz.openbmc_project.Led.Physical"}; |
| 2056 | |
| 2057 | // Response handler for parsing output from GetSubTree |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 2058 | auto respHandler = [callback{std::forward<Callback>(callback)}, |
| 2059 | sensorsAsyncResp, |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2060 | inventoryItems](const boost::system::error_code ec, |
| 2061 | const GetSubTreeType& subtree) { |
| 2062 | BMCWEB_LOG_DEBUG << "getInventoryLeds respHandler enter"; |
| 2063 | if (ec) |
| 2064 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2065 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2066 | BMCWEB_LOG_ERROR << "getInventoryLeds respHandler DBus error " |
| 2067 | << ec; |
| 2068 | return; |
| 2069 | } |
| 2070 | |
| 2071 | // Build map of LED object paths to connections |
| 2072 | std::shared_ptr<boost::container::flat_map<std::string, std::string>> |
| 2073 | ledConnections = std::make_shared< |
| 2074 | boost::container::flat_map<std::string, std::string>>(); |
| 2075 | |
| 2076 | // Loop through objects from GetSubTree |
| 2077 | for (const std::pair< |
| 2078 | std::string, |
| 2079 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 2080 | object : subtree) |
| 2081 | { |
| 2082 | // Check if object path is LED for one of the specified inventory |
| 2083 | // items |
| 2084 | const std::string& ledPath = object.first; |
| 2085 | if (findInventoryItemForLed(*inventoryItems, ledPath) != nullptr) |
| 2086 | { |
| 2087 | // Add mapping from ledPath to connection |
| 2088 | const std::string& connection = object.second.begin()->first; |
| 2089 | (*ledConnections)[ledPath] = connection; |
| 2090 | BMCWEB_LOG_DEBUG << "Added mapping " << ledPath << " -> " |
| 2091 | << connection; |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | getInventoryLedData(sensorsAsyncResp, inventoryItems, ledConnections, |
| 2096 | std::move(callback)); |
| 2097 | BMCWEB_LOG_DEBUG << "getInventoryLeds respHandler exit"; |
| 2098 | }; |
| 2099 | // Make call to ObjectMapper to find all inventory items |
| 2100 | crow::connections::systemBus->async_method_call( |
| 2101 | std::move(respHandler), "xyz.openbmc_project.ObjectMapper", |
| 2102 | "/xyz/openbmc_project/object_mapper", |
| 2103 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 0, interfaces); |
| 2104 | BMCWEB_LOG_DEBUG << "getInventoryLeds exit"; |
| 2105 | } |
| 2106 | |
| 2107 | /** |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2108 | * @brief Gets D-Bus data for Power Supply Attributes such as EfficiencyPercent |
| 2109 | * |
| 2110 | * Uses the specified connections (services) (currently assumes just one) to |
| 2111 | * obtain D-Bus data for Power Supply Attributes. Stores the resulting data in |
| 2112 | * the inventoryItems vector. Only stores data in Power Supply inventoryItems. |
| 2113 | * |
| 2114 | * This data is later used to provide sensor property values in the JSON |
| 2115 | * response. |
| 2116 | * |
| 2117 | * Finds the Power Supply Attributes data asynchronously. Invokes callback |
| 2118 | * when data has been obtained. |
| 2119 | * |
| 2120 | * The callback must have the following signature: |
| 2121 | * @code |
| 2122 | * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) |
| 2123 | * @endcode |
| 2124 | * |
| 2125 | * @param sensorsAsyncResp Pointer to object holding response data. |
| 2126 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 2127 | * @param psAttributesConnections Connections that provide data for the Power |
| 2128 | * Supply Attributes |
| 2129 | * @param callback Callback to invoke when data has been obtained. |
| 2130 | */ |
| 2131 | template <typename Callback> |
| 2132 | void getPowerSupplyAttributesData( |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2133 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2134 | std::shared_ptr<std::vector<InventoryItem>> inventoryItems, |
| 2135 | const boost::container::flat_map<std::string, std::string>& |
| 2136 | psAttributesConnections, |
| 2137 | Callback&& callback) |
| 2138 | { |
| 2139 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData enter"; |
| 2140 | |
| 2141 | if (psAttributesConnections.empty()) |
| 2142 | { |
| 2143 | BMCWEB_LOG_DEBUG << "Can't find PowerSupplyAttributes, no connections!"; |
| 2144 | callback(inventoryItems); |
| 2145 | return; |
| 2146 | } |
| 2147 | |
| 2148 | // Assuming just one connection (service) for now |
| 2149 | auto it = psAttributesConnections.nth(0); |
| 2150 | |
| 2151 | const std::string& psAttributesPath = (*it).first; |
| 2152 | const std::string& psAttributesConnection = (*it).second; |
| 2153 | |
| 2154 | // Response handler for Get DeratingFactor property |
| 2155 | auto respHandler = [sensorsAsyncResp, inventoryItems, |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 2156 | callback{std::forward<Callback>(callback)}]( |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2157 | const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2158 | const uint32_t value) { |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2159 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler enter"; |
| 2160 | if (ec) |
| 2161 | { |
| 2162 | BMCWEB_LOG_ERROR |
| 2163 | << "getPowerSupplyAttributesData respHandler DBus error " << ec; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2164 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2165 | return; |
| 2166 | } |
| 2167 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2168 | BMCWEB_LOG_DEBUG << "PS EfficiencyPercent value: " << value; |
| 2169 | // Store value in Power Supply Inventory Items |
| 2170 | for (InventoryItem& inventoryItem : *inventoryItems) |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2171 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2172 | if (inventoryItem.isPowerSupply == true) |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2173 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2174 | inventoryItem.powerSupplyEfficiencyPercent = |
| 2175 | static_cast<int>(value); |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2176 | } |
| 2177 | } |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2178 | |
| 2179 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler exit"; |
| 2180 | callback(inventoryItems); |
| 2181 | }; |
| 2182 | |
| 2183 | // Get the DeratingFactor property for the PowerSupplyAttributes |
| 2184 | // Currently only property on the interface/only one we care about |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 2185 | sdbusplus::asio::getProperty<uint32_t>( |
| 2186 | *crow::connections::systemBus, psAttributesConnection, psAttributesPath, |
| 2187 | "xyz.openbmc_project.Control.PowerSupplyAttributes", "DeratingFactor", |
| 2188 | std::move(respHandler)); |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2189 | |
| 2190 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData exit"; |
| 2191 | } |
| 2192 | |
| 2193 | /** |
| 2194 | * @brief Gets the Power Supply Attributes such as EfficiencyPercent |
| 2195 | * |
| 2196 | * Gets the D-Bus connection (service) that provides Power Supply Attributes |
| 2197 | * data. Then gets the Power Supply Attributes data from the connection |
| 2198 | * (currently just assumes 1 connection) and stores the data in the inventory |
| 2199 | * item. |
| 2200 | * |
| 2201 | * This data is later used to provide sensor property values in the JSON |
| 2202 | * response. DeratingFactor on D-Bus is mapped to EfficiencyPercent on Redfish. |
| 2203 | * |
| 2204 | * Finds the Power Supply Attributes data asynchronously. Invokes callback |
| 2205 | * when information has been obtained. |
| 2206 | * |
| 2207 | * The callback must have the following signature: |
| 2208 | * @code |
| 2209 | * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) |
| 2210 | * @endcode |
| 2211 | * |
| 2212 | * @param sensorsAsyncResp Pointer to object holding response data. |
| 2213 | * @param inventoryItems D-Bus inventory items associated with sensors. |
| 2214 | * @param callback Callback to invoke when data has been obtained. |
| 2215 | */ |
| 2216 | template <typename Callback> |
| 2217 | void getPowerSupplyAttributes( |
| 2218 | std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, |
| 2219 | std::shared_ptr<std::vector<InventoryItem>> inventoryItems, |
| 2220 | Callback&& callback) |
| 2221 | { |
| 2222 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes enter"; |
| 2223 | |
| 2224 | // Only need the power supply attributes when the Power Schema |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2225 | if (sensorsAsyncResp->chassisSubNode != sensors::node::power) |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2226 | { |
| 2227 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes exit since not Power"; |
| 2228 | callback(inventoryItems); |
| 2229 | return; |
| 2230 | } |
| 2231 | |
| 2232 | const std::array<std::string, 1> interfaces = { |
| 2233 | "xyz.openbmc_project.Control.PowerSupplyAttributes"}; |
| 2234 | |
| 2235 | // Response handler for parsing output from GetSubTree |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 2236 | auto respHandler = [callback{std::forward<Callback>(callback)}, |
| 2237 | sensorsAsyncResp, |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2238 | inventoryItems](const boost::system::error_code ec, |
| 2239 | const GetSubTreeType& subtree) { |
| 2240 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes respHandler enter"; |
| 2241 | if (ec) |
| 2242 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2243 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2244 | BMCWEB_LOG_ERROR |
| 2245 | << "getPowerSupplyAttributes respHandler DBus error " << ec; |
| 2246 | return; |
| 2247 | } |
| 2248 | if (subtree.size() == 0) |
| 2249 | { |
| 2250 | BMCWEB_LOG_DEBUG << "Can't find Power Supply Attributes!"; |
| 2251 | callback(inventoryItems); |
| 2252 | return; |
| 2253 | } |
| 2254 | |
| 2255 | // Currently we only support 1 power supply attribute, use this for |
| 2256 | // all the power supplies. Build map of object path to connection. |
| 2257 | // Assume just 1 connection and 1 path for now. |
| 2258 | boost::container::flat_map<std::string, std::string> |
| 2259 | psAttributesConnections; |
| 2260 | |
| 2261 | if (subtree[0].first.empty() || subtree[0].second.empty()) |
| 2262 | { |
| 2263 | BMCWEB_LOG_DEBUG << "Power Supply Attributes mapper error!"; |
| 2264 | callback(inventoryItems); |
| 2265 | return; |
| 2266 | } |
| 2267 | |
| 2268 | const std::string& psAttributesPath = subtree[0].first; |
| 2269 | const std::string& connection = subtree[0].second.begin()->first; |
| 2270 | |
| 2271 | if (connection.empty()) |
| 2272 | { |
| 2273 | BMCWEB_LOG_DEBUG << "Power Supply Attributes mapper error!"; |
| 2274 | callback(inventoryItems); |
| 2275 | return; |
| 2276 | } |
| 2277 | |
| 2278 | psAttributesConnections[psAttributesPath] = connection; |
| 2279 | BMCWEB_LOG_DEBUG << "Added mapping " << psAttributesPath << " -> " |
| 2280 | << connection; |
| 2281 | |
| 2282 | getPowerSupplyAttributesData(sensorsAsyncResp, inventoryItems, |
| 2283 | psAttributesConnections, |
| 2284 | std::move(callback)); |
| 2285 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes respHandler exit"; |
| 2286 | }; |
| 2287 | // Make call to ObjectMapper to find the PowerSupplyAttributes service |
| 2288 | crow::connections::systemBus->async_method_call( |
| 2289 | std::move(respHandler), "xyz.openbmc_project.ObjectMapper", |
| 2290 | "/xyz/openbmc_project/object_mapper", |
| 2291 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 2292 | "/xyz/openbmc_project", 0, interfaces); |
| 2293 | BMCWEB_LOG_DEBUG << "getPowerSupplyAttributes exit"; |
| 2294 | } |
| 2295 | |
| 2296 | /** |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2297 | * @brief Gets inventory items associated with sensors. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2298 | * |
| 2299 | * Finds the inventory items that are associated with the specified sensors. |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2300 | * Then gets D-Bus data for the inventory items, such as presence and VPD. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2301 | * |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2302 | * This data is later used to provide sensor property values in the JSON |
| 2303 | * response. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2304 | * |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2305 | * Finds the inventory items asynchronously. Invokes callback when the |
| 2306 | * inventory items have been obtained. |
| 2307 | * |
| 2308 | * The callback must have the following signature: |
| 2309 | * @code |
| 2310 | * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems) |
| 2311 | * @endcode |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2312 | * |
| 2313 | * @param sensorsAsyncResp Pointer to object holding response data. |
| 2314 | * @param sensorNames All sensors within the current chassis. |
| 2315 | * @param objectMgrPaths Mappings from connection name to DBus object path that |
| 2316 | * implements ObjectManager. |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2317 | * @param callback Callback to invoke when inventory items have been obtained. |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2318 | */ |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2319 | template <typename Callback> |
| 2320 | static void getInventoryItems( |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2321 | std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp, |
| 2322 | const std::shared_ptr<boost::container::flat_set<std::string>> sensorNames, |
| 2323 | std::shared_ptr<boost::container::flat_map<std::string, std::string>> |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2324 | objectMgrPaths, |
| 2325 | Callback&& callback) |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2326 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2327 | BMCWEB_LOG_DEBUG << "getInventoryItems enter"; |
| 2328 | auto getInventoryItemAssociationsCb = |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 2329 | [sensorsAsyncResp, objectMgrPaths, |
| 2330 | callback{std::forward<Callback>(callback)}]( |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2331 | std::shared_ptr<std::vector<InventoryItem>> inventoryItems) { |
| 2332 | BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb enter"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2333 | auto getInventoryItemsConnectionsCb = |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2334 | [sensorsAsyncResp, inventoryItems, objectMgrPaths, |
Ed Tanous | f94c4ec | 2022-01-06 12:44:41 -0800 | [diff] [blame] | 2335 | callback{std::forward<const Callback>(callback)}]( |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2336 | std::shared_ptr<boost::container::flat_set<std::string>> |
| 2337 | invConnections) { |
| 2338 | BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb enter"; |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2339 | auto getInventoryItemsDataCb = |
| 2340 | [sensorsAsyncResp, inventoryItems, |
| 2341 | callback{std::move(callback)}]() { |
| 2342 | BMCWEB_LOG_DEBUG << "getInventoryItemsDataCb enter"; |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2343 | |
| 2344 | auto getInventoryLedsCb = [sensorsAsyncResp, |
| 2345 | inventoryItems, |
| 2346 | callback{std::move( |
| 2347 | callback)}]() { |
| 2348 | BMCWEB_LOG_DEBUG << "getInventoryLedsCb enter"; |
| 2349 | // Find Power Supply Attributes and get the data |
| 2350 | getPowerSupplyAttributes(sensorsAsyncResp, |
| 2351 | inventoryItems, |
| 2352 | std::move(callback)); |
| 2353 | BMCWEB_LOG_DEBUG << "getInventoryLedsCb exit"; |
| 2354 | }; |
| 2355 | |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2356 | // Find led connections and get the data |
| 2357 | getInventoryLeds(sensorsAsyncResp, inventoryItems, |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2358 | std::move(getInventoryLedsCb)); |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2359 | BMCWEB_LOG_DEBUG << "getInventoryItemsDataCb exit"; |
| 2360 | }; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2361 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2362 | // Get inventory item data from connections |
| 2363 | getInventoryItemsData(sensorsAsyncResp, inventoryItems, |
| 2364 | invConnections, objectMgrPaths, |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2365 | std::move(getInventoryItemsDataCb)); |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2366 | BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb exit"; |
| 2367 | }; |
| 2368 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2369 | // Get connections that provide inventory item data |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2370 | getInventoryItemsConnections( |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2371 | sensorsAsyncResp, inventoryItems, |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2372 | std::move(getInventoryItemsConnectionsCb)); |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2373 | BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb exit"; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2374 | }; |
| 2375 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2376 | // Get associations from sensors to inventory items |
| 2377 | getInventoryItemAssociations(sensorsAsyncResp, sensorNames, objectMgrPaths, |
| 2378 | std::move(getInventoryItemAssociationsCb)); |
| 2379 | BMCWEB_LOG_DEBUG << "getInventoryItems exit"; |
| 2380 | } |
| 2381 | |
| 2382 | /** |
| 2383 | * @brief Returns JSON PowerSupply object for the specified inventory item. |
| 2384 | * |
| 2385 | * Searches for a JSON PowerSupply object that matches the specified inventory |
| 2386 | * item. If one is not found, a new PowerSupply object is added to the JSON |
| 2387 | * array. |
| 2388 | * |
| 2389 | * Multiple sensors are often associated with one power supply inventory item. |
| 2390 | * As a result, multiple sensor values are stored in one JSON PowerSupply |
| 2391 | * object. |
| 2392 | * |
| 2393 | * @param powerSupplyArray JSON array containing Redfish PowerSupply objects. |
| 2394 | * @param inventoryItem Inventory item for the power supply. |
| 2395 | * @param chassisId Chassis that contains the power supply. |
| 2396 | * @return JSON PowerSupply object for the specified inventory item. |
| 2397 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2398 | inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray, |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2399 | const InventoryItem& inventoryItem, |
| 2400 | const std::string& chassisId) |
| 2401 | { |
| 2402 | // Check if matching PowerSupply object already exists in JSON array |
| 2403 | for (nlohmann::json& powerSupply : powerSupplyArray) |
| 2404 | { |
| 2405 | if (powerSupply["MemberId"] == inventoryItem.name) |
| 2406 | { |
| 2407 | return powerSupply; |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | // Add new PowerSupply object to JSON array |
| 2412 | powerSupplyArray.push_back({}); |
| 2413 | nlohmann::json& powerSupply = powerSupplyArray.back(); |
| 2414 | powerSupply["@odata.id"] = |
| 2415 | "/redfish/v1/Chassis/" + chassisId + "/Power#/PowerSupplies/"; |
| 2416 | powerSupply["MemberId"] = inventoryItem.name; |
| 2417 | powerSupply["Name"] = boost::replace_all_copy(inventoryItem.name, "_", " "); |
| 2418 | powerSupply["Manufacturer"] = inventoryItem.manufacturer; |
| 2419 | powerSupply["Model"] = inventoryItem.model; |
| 2420 | powerSupply["PartNumber"] = inventoryItem.partNumber; |
| 2421 | powerSupply["SerialNumber"] = inventoryItem.serialNumber; |
Anthony Wilson | d500549 | 2019-07-31 16:34:17 -0500 | [diff] [blame] | 2422 | setLedState(powerSupply, &inventoryItem); |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2423 | |
Gunnar Mills | 42cbe53 | 2019-08-15 15:26:54 -0500 | [diff] [blame] | 2424 | if (inventoryItem.powerSupplyEfficiencyPercent >= 0) |
| 2425 | { |
| 2426 | powerSupply["EfficiencyPercent"] = |
| 2427 | inventoryItem.powerSupplyEfficiencyPercent; |
| 2428 | } |
| 2429 | |
| 2430 | powerSupply["Status"]["State"] = getState(&inventoryItem); |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2431 | const char* health = inventoryItem.isFunctional ? "OK" : "Critical"; |
| 2432 | powerSupply["Status"]["Health"] = health; |
| 2433 | |
| 2434 | return powerSupply; |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | /** |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2438 | * @brief Gets the values of the specified sensors. |
| 2439 | * |
| 2440 | * Stores the results as JSON in the SensorsAsyncResp. |
| 2441 | * |
| 2442 | * Gets the sensor values asynchronously. Stores the results later when the |
| 2443 | * information has been obtained. |
| 2444 | * |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2445 | * The sensorNames set contains all requested sensors for the current chassis. |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2446 | * |
| 2447 | * To minimize the number of DBus calls, the DBus method |
| 2448 | * org.freedesktop.DBus.ObjectManager.GetManagedObjects() is used to get the |
| 2449 | * values of all sensors provided by a connection (service). |
| 2450 | * |
| 2451 | * The connections set contains all the connections that provide sensor values. |
| 2452 | * |
| 2453 | * The objectMgrPaths map contains mappings from a connection name to the |
| 2454 | * corresponding DBus object path that implements ObjectManager. |
| 2455 | * |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2456 | * The InventoryItem vector contains D-Bus inventory items associated with the |
| 2457 | * sensors. Inventory item data is needed for some Redfish sensor properties. |
| 2458 | * |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2459 | * @param SensorsAsyncResp Pointer to object holding response data. |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2460 | * @param sensorNames All requested sensors within the current chassis. |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2461 | * @param connections Connections that provide sensor values. |
| 2462 | * @param objectMgrPaths Mappings from connection name to DBus object path that |
| 2463 | * implements ObjectManager. |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2464 | * @param inventoryItems Inventory items associated with the sensors. |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2465 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2466 | inline void getSensorData( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2467 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2468 | const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames, |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2469 | const boost::container::flat_set<std::string>& connections, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2470 | const std::shared_ptr<boost::container::flat_map<std::string, std::string>>& |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2471 | objectMgrPaths, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2472 | const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems) |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2473 | { |
| 2474 | BMCWEB_LOG_DEBUG << "getSensorData enter"; |
| 2475 | // Get managed objects from all services exposing sensors |
| 2476 | for (const std::string& connection : connections) |
| 2477 | { |
| 2478 | // Response handler to process managed objects |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2479 | auto getManagedObjectsCb = [sensorsAsyncResp, sensorNames, |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2480 | inventoryItems]( |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2481 | const boost::system::error_code ec, |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 2482 | dbus::utility::ManagedObjectType& resp) { |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2483 | BMCWEB_LOG_DEBUG << "getManagedObjectsCb enter"; |
| 2484 | if (ec) |
| 2485 | { |
| 2486 | BMCWEB_LOG_ERROR << "getManagedObjectsCb DBUS error: " << ec; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2487 | messages::internalError(sensorsAsyncResp->asyncResp->res); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2488 | return; |
| 2489 | } |
| 2490 | // Go through all objects and update response with sensor data |
| 2491 | for (const auto& objDictEntry : resp) |
| 2492 | { |
| 2493 | const std::string& objPath = |
| 2494 | static_cast<const std::string&>(objDictEntry.first); |
| 2495 | BMCWEB_LOG_DEBUG << "getManagedObjectsCb parsing object " |
| 2496 | << objPath; |
| 2497 | |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2498 | std::vector<std::string> split; |
| 2499 | // Reserve space for |
| 2500 | // /xyz/openbmc_project/sensors/<name>/<subname> |
| 2501 | split.reserve(6); |
| 2502 | boost::algorithm::split(split, objPath, boost::is_any_of("/")); |
| 2503 | if (split.size() < 6) |
| 2504 | { |
| 2505 | BMCWEB_LOG_ERROR << "Got path that isn't long enough " |
| 2506 | << objPath; |
| 2507 | continue; |
| 2508 | } |
| 2509 | // These indexes aren't intuitive, as boost::split puts an empty |
| 2510 | // string at the beginning |
| 2511 | const std::string& sensorType = split[4]; |
| 2512 | const std::string& sensorName = split[5]; |
| 2513 | BMCWEB_LOG_DEBUG << "sensorName " << sensorName |
| 2514 | << " sensorType " << sensorType; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2515 | if (sensorNames->find(objPath) == sensorNames->end()) |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2516 | { |
Andrew Geissler | accdbb2 | 2021-11-09 15:24:45 -0600 | [diff] [blame] | 2517 | BMCWEB_LOG_DEBUG << sensorName << " not in sensor list "; |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2518 | continue; |
| 2519 | } |
| 2520 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2521 | // Find inventory item (if any) associated with sensor |
| 2522 | InventoryItem* inventoryItem = |
| 2523 | findInventoryItemForSensor(inventoryItems, objPath); |
| 2524 | |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2525 | const std::string& sensorSchema = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2526 | sensorsAsyncResp->chassisSubNode; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2527 | |
| 2528 | nlohmann::json* sensorJson = nullptr; |
| 2529 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2530 | if (sensorSchema == sensors::node::sensors) |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2531 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2532 | sensorsAsyncResp->asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2533 | "/redfish/v1/Chassis/" + sensorsAsyncResp->chassisId + |
| 2534 | "/" + sensorsAsyncResp->chassisSubNode + "/" + |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2535 | sensorName; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2536 | sensorJson = &(sensorsAsyncResp->asyncResp->res.jsonValue); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2537 | } |
| 2538 | else |
| 2539 | { |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 2540 | std::string fieldName; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2541 | if (sensorType == "temperature") |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2542 | { |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2543 | fieldName = "Temperatures"; |
| 2544 | } |
| 2545 | else if (sensorType == "fan" || sensorType == "fan_tach" || |
| 2546 | sensorType == "fan_pwm") |
| 2547 | { |
| 2548 | fieldName = "Fans"; |
| 2549 | } |
| 2550 | else if (sensorType == "voltage") |
| 2551 | { |
| 2552 | fieldName = "Voltages"; |
| 2553 | } |
| 2554 | else if (sensorType == "power") |
| 2555 | { |
| 2556 | if (!sensorName.compare("total_power")) |
| 2557 | { |
| 2558 | fieldName = "PowerControl"; |
| 2559 | } |
| 2560 | else if ((inventoryItem != nullptr) && |
| 2561 | (inventoryItem->isPowerSupply)) |
| 2562 | { |
| 2563 | fieldName = "PowerSupplies"; |
| 2564 | } |
| 2565 | else |
| 2566 | { |
| 2567 | // Other power sensors are in SensorCollection |
| 2568 | continue; |
| 2569 | } |
| 2570 | } |
| 2571 | else |
| 2572 | { |
| 2573 | BMCWEB_LOG_ERROR << "Unsure how to handle sensorType " |
| 2574 | << sensorType; |
| 2575 | continue; |
| 2576 | } |
| 2577 | |
| 2578 | nlohmann::json& tempArray = |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2579 | sensorsAsyncResp->asyncResp->res.jsonValue[fieldName]; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2580 | if (fieldName == "PowerControl") |
| 2581 | { |
| 2582 | if (tempArray.empty()) |
| 2583 | { |
| 2584 | // Put multiple "sensors" into a single |
| 2585 | // PowerControl. Follows MemberId naming and |
| 2586 | // naming in power.hpp. |
| 2587 | tempArray.push_back( |
| 2588 | {{"@odata.id", |
| 2589 | "/redfish/v1/Chassis/" + |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2590 | sensorsAsyncResp->chassisId + "/" + |
| 2591 | sensorsAsyncResp->chassisSubNode + "#/" + |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2592 | fieldName + "/0"}}); |
| 2593 | } |
| 2594 | sensorJson = &(tempArray.back()); |
| 2595 | } |
| 2596 | else if (fieldName == "PowerSupplies") |
| 2597 | { |
| 2598 | if (inventoryItem != nullptr) |
| 2599 | { |
| 2600 | sensorJson = |
| 2601 | &(getPowerSupply(tempArray, *inventoryItem, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2602 | sensorsAsyncResp->chassisId)); |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2603 | } |
| 2604 | } |
| 2605 | else |
| 2606 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2607 | tempArray.push_back( |
| 2608 | {{"@odata.id", |
| 2609 | "/redfish/v1/Chassis/" + |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2610 | sensorsAsyncResp->chassisId + "/" + |
| 2611 | sensorsAsyncResp->chassisSubNode + "#/" + |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2612 | fieldName + "/"}}); |
| 2613 | sensorJson = &(tempArray.back()); |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2614 | } |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2615 | } |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2616 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2617 | if (sensorJson != nullptr) |
| 2618 | { |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2619 | objectInterfacesToJson( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2620 | sensorName, sensorType, sensorsAsyncResp, |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2621 | objDictEntry.second, *sensorJson, inventoryItem); |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 2622 | } |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2623 | } |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2624 | if (sensorsAsyncResp.use_count() == 1) |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 2625 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2626 | sortJSONResponse(sensorsAsyncResp); |
| 2627 | if (sensorsAsyncResp->chassisSubNode == sensors::node::thermal) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2628 | { |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2629 | populateFanRedundancy(sensorsAsyncResp); |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2630 | } |
James Feist | 8bd25cc | 2019-03-15 15:14:00 -0700 | [diff] [blame] | 2631 | } |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2632 | BMCWEB_LOG_DEBUG << "getManagedObjectsCb exit"; |
| 2633 | }; |
| 2634 | |
| 2635 | // Find DBus object path that implements ObjectManager for the current |
| 2636 | // connection. If no mapping found, default to "/". |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2637 | auto iter = objectMgrPaths->find(connection); |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2638 | const std::string& objectMgrPath = |
Shawn McCarney | 8fb49dd | 2019-06-12 17:47:00 -0500 | [diff] [blame] | 2639 | (iter != objectMgrPaths->end()) ? iter->second : "/"; |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2640 | BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is " |
| 2641 | << objectMgrPath; |
| 2642 | |
| 2643 | crow::connections::systemBus->async_method_call( |
| 2644 | getManagedObjectsCb, connection, objectMgrPath, |
| 2645 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2646 | } |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2647 | BMCWEB_LOG_DEBUG << "getSensorData exit"; |
| 2648 | } |
| 2649 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2650 | inline void processSensorList( |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2651 | const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2652 | const std::shared_ptr<boost::container::flat_set<std::string>>& sensorNames) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2653 | { |
| 2654 | auto getConnectionCb = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2655 | [sensorsAsyncResp, sensorNames]( |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2656 | const boost::container::flat_set<std::string>& connections) { |
| 2657 | BMCWEB_LOG_DEBUG << "getConnectionCb enter"; |
| 2658 | auto getObjectManagerPathsCb = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2659 | [sensorsAsyncResp, sensorNames, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2660 | connections](const std::shared_ptr<boost::container::flat_map< |
| 2661 | std::string, std::string>>& objectMgrPaths) { |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2662 | BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb enter"; |
| 2663 | auto getInventoryItemsCb = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2664 | [sensorsAsyncResp, sensorNames, connections, |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2665 | objectMgrPaths]( |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 2666 | const std::shared_ptr<std::vector<InventoryItem>>& |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2667 | inventoryItems) { |
| 2668 | BMCWEB_LOG_DEBUG << "getInventoryItemsCb enter"; |
| 2669 | // Get sensor data and store results in JSON |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2670 | getSensorData(sensorsAsyncResp, sensorNames, |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2671 | connections, objectMgrPaths, |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 2672 | inventoryItems); |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2673 | BMCWEB_LOG_DEBUG << "getInventoryItemsCb exit"; |
| 2674 | }; |
| 2675 | |
| 2676 | // Get inventory items associated with sensors |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2677 | getInventoryItems(sensorsAsyncResp, sensorNames, |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2678 | objectMgrPaths, |
| 2679 | std::move(getInventoryItemsCb)); |
| 2680 | |
| 2681 | BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb exit"; |
| 2682 | }; |
| 2683 | |
| 2684 | // Get mapping from connection names to the DBus object |
| 2685 | // paths that implement the ObjectManager interface |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2686 | getObjectManagerPaths(sensorsAsyncResp, |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2687 | std::move(getObjectManagerPathsCb)); |
| 2688 | BMCWEB_LOG_DEBUG << "getConnectionCb exit"; |
| 2689 | }; |
| 2690 | |
| 2691 | // Get set of connections that provide sensor values |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2692 | getConnections(sensorsAsyncResp, sensorNames, std::move(getConnectionCb)); |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2693 | } |
| 2694 | |
Shawn McCarney | de629b6 | 2019-03-08 10:42:51 -0600 | [diff] [blame] | 2695 | /** |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 2696 | * @brief Entry point for retrieving sensors data related to requested |
| 2697 | * chassis. |
Kowalski, Kamil | 588c3f0 | 2018-04-03 14:55:27 +0200 | [diff] [blame] | 2698 | * @param SensorsAsyncResp Pointer to object holding response data |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 2699 | */ |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2700 | inline void |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2701 | getChassisData(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2702 | { |
| 2703 | BMCWEB_LOG_DEBUG << "getChassisData enter"; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2704 | auto getChassisCb = |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2705 | [sensorsAsyncResp]( |
Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 2706 | const std::shared_ptr<boost::container::flat_set<std::string>>& |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2707 | sensorNames) { |
| 2708 | BMCWEB_LOG_DEBUG << "getChassisCb enter"; |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2709 | processSensorList(sensorsAsyncResp, sensorNames); |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2710 | BMCWEB_LOG_DEBUG << "getChassisCb exit"; |
| 2711 | }; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2712 | sensorsAsyncResp->asyncResp->res.jsonValue["Redundancy"] = |
| 2713 | nlohmann::json::array(); |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 2714 | |
Shawn McCarney | 26f0389 | 2019-05-03 13:20:24 -0500 | [diff] [blame] | 2715 | // Get set of sensors in chassis |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 2716 | getChassis(sensorsAsyncResp, std::move(getChassisCb)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2717 | BMCWEB_LOG_DEBUG << "getChassisData exit"; |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 2718 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 2719 | |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2720 | /** |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2721 | * @brief Find the requested sensorName in the list of all sensors supplied by |
| 2722 | * the chassis node |
| 2723 | * |
| 2724 | * @param sensorName The sensor name supplied in the PATCH request |
| 2725 | * @param sensorsList The list of sensors managed by the chassis node |
| 2726 | * @param sensorsModified The list of sensors that were found as a result of |
| 2727 | * repeated calls to this function |
| 2728 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2729 | inline bool findSensorNameUsingSensorPath( |
Richard Marian Thomaiyar | 0a86feb | 2019-05-27 23:16:40 +0530 | [diff] [blame] | 2730 | std::string_view sensorName, |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2731 | boost::container::flat_set<std::string>& sensorsList, |
| 2732 | boost::container::flat_set<std::string>& sensorsModified) |
| 2733 | { |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 2734 | for (auto& chassisSensor : sensorsList) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2735 | { |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 2736 | sdbusplus::message::object_path path(chassisSensor); |
Ed Tanous | b00dcc2 | 2021-02-23 12:52:50 -0800 | [diff] [blame] | 2737 | std::string thisSensorName = path.filename(); |
George Liu | 28aa8de | 2021-02-01 15:13:30 +0800 | [diff] [blame] | 2738 | if (thisSensorName.empty()) |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2739 | { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2740 | continue; |
| 2741 | } |
| 2742 | if (thisSensorName == sensorName) |
| 2743 | { |
| 2744 | sensorsModified.emplace(chassisSensor); |
| 2745 | return true; |
| 2746 | } |
| 2747 | } |
| 2748 | return false; |
| 2749 | } |
| 2750 | |
| 2751 | /** |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2752 | * @brief Entry point for overriding sensor values of given sensor |
| 2753 | * |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2754 | * @param sensorAsyncResp response object |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 2755 | * @param allCollections Collections extract from sensors' request patch info |
jayaprakash Mutyala | 91e130a | 2020-03-04 22:26:38 +0000 | [diff] [blame] | 2756 | * @param chassisSubNode Chassis Node for which the query has to happen |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2757 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2758 | inline void setSensorsOverride( |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2759 | const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp, |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 2760 | std::unordered_map<std::string, std::vector<nlohmann::json>>& |
jayaprakash Mutyala | 397fd61 | 2020-02-06 23:33:34 +0000 | [diff] [blame] | 2761 | allCollections) |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2762 | { |
jayaprakash Mutyala | 70d1d0a | 2020-01-21 23:41:36 +0000 | [diff] [blame] | 2763 | BMCWEB_LOG_INFO << "setSensorsOverride for subNode" |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 2764 | << sensorAsyncResp->chassisSubNode << "\n"; |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2765 | |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 2766 | const char* propertyValueName = nullptr; |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2767 | std::unordered_map<std::string, std::pair<double, std::string>> overrideMap; |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2768 | std::string memberId; |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 2769 | double value = 0.0; |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2770 | for (auto& collectionItems : allCollections) |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2771 | { |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2772 | if (collectionItems.first == "Temperatures") |
| 2773 | { |
| 2774 | propertyValueName = "ReadingCelsius"; |
| 2775 | } |
| 2776 | else if (collectionItems.first == "Fans") |
| 2777 | { |
| 2778 | propertyValueName = "Reading"; |
| 2779 | } |
| 2780 | else |
| 2781 | { |
| 2782 | propertyValueName = "ReadingVolts"; |
| 2783 | } |
| 2784 | for (auto& item : collectionItems.second) |
| 2785 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2786 | if (!json_util::readJson(item, sensorAsyncResp->asyncResp->res, |
| 2787 | "MemberId", memberId, propertyValueName, |
| 2788 | value)) |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2789 | { |
| 2790 | return; |
| 2791 | } |
| 2792 | overrideMap.emplace(memberId, |
| 2793 | std::make_pair(value, collectionItems.first)); |
| 2794 | } |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2795 | } |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 2796 | |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2797 | auto getChassisSensorListCb = [sensorAsyncResp, overrideMap]( |
| 2798 | const std::shared_ptr< |
| 2799 | boost::container::flat_set< |
| 2800 | std::string>>& sensorsList) { |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2801 | // Match sensor names in the PATCH request to those managed by the |
| 2802 | // chassis node |
| 2803 | const std::shared_ptr<boost::container::flat_set<std::string>> |
| 2804 | sensorNames = |
| 2805 | std::make_shared<boost::container::flat_set<std::string>>(); |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2806 | for (const auto& item : overrideMap) |
| 2807 | { |
| 2808 | const auto& sensor = item.first; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 2809 | if (!findSensorNameUsingSensorPath(sensor, *sensorsList, |
| 2810 | *sensorNames)) |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2811 | { |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2812 | BMCWEB_LOG_INFO << "Unable to find memberId " << item.first; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2813 | messages::resourceNotFound(sensorAsyncResp->asyncResp->res, |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2814 | item.second.second, item.first); |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2815 | return; |
| 2816 | } |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2817 | } |
| 2818 | // Get the connection to which the memberId belongs |
Jayaprakash Mutyala | 4f277b5 | 2021-12-08 22:46:49 +0000 | [diff] [blame] | 2819 | auto getObjectsWithConnectionCb = [sensorAsyncResp, overrideMap]( |
| 2820 | const boost::container::flat_set< |
| 2821 | std::string>& /*connections*/, |
| 2822 | const std::set<std::pair< |
| 2823 | std::string, std::string>>& |
| 2824 | objectsWithConnection) { |
| 2825 | if (objectsWithConnection.size() != overrideMap.size()) |
| 2826 | { |
| 2827 | BMCWEB_LOG_INFO |
| 2828 | << "Unable to find all objects with proper connection " |
| 2829 | << objectsWithConnection.size() << " requested " |
| 2830 | << overrideMap.size() << "\n"; |
| 2831 | messages::resourceNotFound(sensorAsyncResp->asyncResp->res, |
| 2832 | sensorAsyncResp->chassisSubNode == |
| 2833 | sensors::node::thermal |
| 2834 | ? "Temperatures" |
| 2835 | : "Voltages", |
| 2836 | "Count"); |
| 2837 | return; |
| 2838 | } |
| 2839 | for (const auto& item : objectsWithConnection) |
| 2840 | { |
| 2841 | sdbusplus::message::object_path path(item.first); |
| 2842 | std::string sensorName = path.filename(); |
| 2843 | if (sensorName.empty()) |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2844 | { |
Jayaprakash Mutyala | 4f277b5 | 2021-12-08 22:46:49 +0000 | [diff] [blame] | 2845 | messages::internalError(sensorAsyncResp->asyncResp->res); |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2846 | return; |
| 2847 | } |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2848 | |
Jayaprakash Mutyala | 4f277b5 | 2021-12-08 22:46:49 +0000 | [diff] [blame] | 2849 | const auto& iterator = overrideMap.find(sensorName); |
| 2850 | if (iterator == overrideMap.end()) |
| 2851 | { |
| 2852 | BMCWEB_LOG_INFO << "Unable to find sensor object" |
| 2853 | << item.first << "\n"; |
| 2854 | messages::internalError(sensorAsyncResp->asyncResp->res); |
| 2855 | return; |
| 2856 | } |
| 2857 | crow::connections::systemBus->async_method_call( |
| 2858 | [sensorAsyncResp](const boost::system::error_code ec) { |
| 2859 | if (ec) |
| 2860 | { |
| 2861 | if (ec.value() == |
| 2862 | boost::system::errc::permission_denied) |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2863 | { |
Jayaprakash Mutyala | 4f277b5 | 2021-12-08 22:46:49 +0000 | [diff] [blame] | 2864 | BMCWEB_LOG_WARNING |
| 2865 | << "Manufacturing mode is not Enabled...can't " |
| 2866 | "Override the sensor value. "; |
| 2867 | |
| 2868 | messages::insufficientPrivilege( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2869 | sensorAsyncResp->asyncResp->res); |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2870 | return; |
| 2871 | } |
Jayaprakash Mutyala | 4f277b5 | 2021-12-08 22:46:49 +0000 | [diff] [blame] | 2872 | BMCWEB_LOG_DEBUG |
| 2873 | << "setOverrideValueStatus DBUS error: " << ec; |
| 2874 | messages::internalError( |
| 2875 | sensorAsyncResp->asyncResp->res); |
| 2876 | } |
| 2877 | }, |
| 2878 | item.second, item.first, "org.freedesktop.DBus.Properties", |
| 2879 | "Set", "xyz.openbmc_project.Sensor.Value", "Value", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 2880 | dbus::utility::DbusVariantType(iterator->second.first)); |
Jayaprakash Mutyala | 4f277b5 | 2021-12-08 22:46:49 +0000 | [diff] [blame] | 2881 | } |
| 2882 | }; |
Richard Marian Thomaiyar | f65af9e | 2019-02-13 23:35:05 +0530 | [diff] [blame] | 2883 | // Get object with connection for the given sensor name |
| 2884 | getObjectsWithConnection(sensorAsyncResp, sensorNames, |
| 2885 | std::move(getObjectsWithConnectionCb)); |
| 2886 | }; |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 2887 | // get full sensor list for the given chassisId and cross verify the sensor. |
| 2888 | getChassis(sensorAsyncResp, std::move(getChassisSensorListCb)); |
| 2889 | } |
| 2890 | |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2891 | /** |
| 2892 | * @brief Retrieves mapping of Redfish URIs to sensor value property to D-Bus |
| 2893 | * path of the sensor. |
| 2894 | * |
| 2895 | * Function builds valid Redfish response for sensor query of given chassis and |
| 2896 | * node. It then builds metadata about Redfish<->D-Bus correlations and provides |
| 2897 | * it to caller in a callback. |
| 2898 | * |
| 2899 | * @param chassis Chassis for which retrieval should be performed |
| 2900 | * @param node Node (group) of sensors. See sensors::node for supported values |
| 2901 | * @param mapComplete Callback to be called with retrieval result |
| 2902 | */ |
Krzysztof Grobelny | 021d32c | 2021-10-29 16:00:07 +0200 | [diff] [blame] | 2903 | inline void retrieveUriToDbusMap(const std::string& chassis, |
| 2904 | const std::string& node, |
| 2905 | SensorsAsyncResp::DataCompleteCb&& mapComplete) |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2906 | { |
Wludzik, Jozef | c2bf7f9 | 2021-03-08 14:35:54 +0000 | [diff] [blame] | 2907 | auto pathIt = sensors::dbus::paths.find(node); |
| 2908 | if (pathIt == sensors::dbus::paths.end()) |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2909 | { |
| 2910 | BMCWEB_LOG_ERROR << "Wrong node provided : " << node; |
| 2911 | mapComplete(boost::beast::http::status::bad_request, {}); |
| 2912 | return; |
| 2913 | } |
Krzysztof Grobelny | d51e072 | 2021-04-16 13:15:21 +0000 | [diff] [blame] | 2914 | |
Gunnar Mills | 9062d47 | 2021-11-16 11:37:47 -0600 | [diff] [blame] | 2915 | auto res = std::make_shared<crow::Response>(); |
| 2916 | auto asyncResp = std::make_shared<bmcweb::AsyncResp>(*res); |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2917 | auto callback = |
Gunnar Mills | 9062d47 | 2021-11-16 11:37:47 -0600 | [diff] [blame] | 2918 | [res, asyncResp, mapCompleteCb{std::move(mapComplete)}]( |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2919 | const boost::beast::http::status status, |
| 2920 | const boost::container::flat_map<std::string, std::string>& |
| 2921 | uriToDbus) { mapCompleteCb(status, uriToDbus); }; |
| 2922 | |
| 2923 | auto resp = std::make_shared<SensorsAsyncResp>( |
Krzysztof Grobelny | d51e072 | 2021-04-16 13:15:21 +0000 | [diff] [blame] | 2924 | asyncResp, chassis, pathIt->second, node, std::move(callback)); |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 2925 | getChassisData(resp); |
| 2926 | } |
| 2927 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2928 | inline void requestRoutesSensorCollection(App& app) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2929 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2930 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2931 | .privileges(redfish::privileges::getSensorCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2932 | .methods( |
| 2933 | boost::beast::http::verb::get)([](const crow::Request&, |
| 2934 | const std::shared_ptr< |
| 2935 | bmcweb::AsyncResp>& aResp, |
| 2936 | const std::string& chassisId) { |
| 2937 | BMCWEB_LOG_DEBUG << "SensorCollection doGet enter"; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2938 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2939 | std::shared_ptr<SensorsAsyncResp> asyncResp = |
| 2940 | std::make_shared<SensorsAsyncResp>( |
| 2941 | aResp, chassisId, |
| 2942 | sensors::dbus::paths.at(sensors::node::sensors), |
| 2943 | sensors::node::sensors); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 2944 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2945 | auto getChassisCb = |
| 2946 | [asyncResp]( |
| 2947 | const std::shared_ptr< |
| 2948 | boost::container::flat_set<std::string>>& sensorNames) { |
| 2949 | BMCWEB_LOG_DEBUG << "getChassisCb enter"; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2950 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2951 | nlohmann::json& entriesArray = |
| 2952 | asyncResp->asyncResp->res.jsonValue["Members"]; |
| 2953 | for (auto& sensor : *sensorNames) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2954 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2955 | BMCWEB_LOG_DEBUG << "Adding sensor: " << sensor; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2956 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2957 | sdbusplus::message::object_path path(sensor); |
| 2958 | std::string sensorName = path.filename(); |
| 2959 | if (sensorName.empty()) |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2960 | { |
| 2961 | BMCWEB_LOG_ERROR << "Invalid sensor path: " |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2962 | << sensor; |
| 2963 | messages::internalError(asyncResp->asyncResp->res); |
| 2964 | return; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2965 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2966 | entriesArray.push_back( |
| 2967 | {{"@odata.id", "/redfish/v1/Chassis/" + |
| 2968 | asyncResp->chassisId + "/" + |
| 2969 | asyncResp->chassisSubNode + "/" + |
| 2970 | sensorName}}); |
| 2971 | } |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2972 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2973 | asyncResp->asyncResp->res.jsonValue["Members@odata.count"] = |
| 2974 | entriesArray.size(); |
| 2975 | BMCWEB_LOG_DEBUG << "getChassisCb exit"; |
| 2976 | }; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2977 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2978 | // Get set of sensors in chassis |
| 2979 | getChassis(asyncResp, std::move(getChassisCb)); |
| 2980 | BMCWEB_LOG_DEBUG << "SensorCollection doGet exit"; |
| 2981 | }); |
| 2982 | } |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2983 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2984 | inline void requestRoutesSensor(App& app) |
| 2985 | { |
| 2986 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2987 | .privileges(redfish::privileges::getSensor) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2988 | .methods( |
| 2989 | boost::beast::http::verb::get)([](const crow::Request&, |
| 2990 | const std::shared_ptr< |
| 2991 | bmcweb::AsyncResp>& aResp, |
| 2992 | const std::string& chassisId, |
| 2993 | const std::string& sensorName) { |
| 2994 | BMCWEB_LOG_DEBUG << "Sensor doGet enter"; |
| 2995 | std::shared_ptr<SensorsAsyncResp> asyncResp = |
| 2996 | std::make_shared<SensorsAsyncResp>(aResp, chassisId, |
| 2997 | std::vector<const char*>(), |
| 2998 | sensors::node::sensors); |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 2999 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3000 | const std::array<const char*, 1> interfaces = { |
| 3001 | "xyz.openbmc_project.Sensor.Value"}; |
| 3002 | |
| 3003 | // Get a list of all of the sensors that implement Sensor.Value |
| 3004 | // and get the path and service name associated with the sensor |
| 3005 | crow::connections::systemBus->async_method_call( |
| 3006 | [asyncResp, sensorName](const boost::system::error_code ec, |
| 3007 | const GetSubTreeType& subtree) { |
| 3008 | BMCWEB_LOG_DEBUG << "respHandler1 enter"; |
| 3009 | if (ec) |
| 3010 | { |
| 3011 | messages::internalError(asyncResp->asyncResp->res); |
| 3012 | BMCWEB_LOG_ERROR |
| 3013 | << "Sensor getSensorPaths resp_handler: " |
| 3014 | << "Dbus error " << ec; |
| 3015 | return; |
| 3016 | } |
| 3017 | |
| 3018 | GetSubTreeType::const_iterator it = std::find_if( |
| 3019 | subtree.begin(), subtree.end(), |
| 3020 | [sensorName]( |
| 3021 | const std::pair< |
| 3022 | std::string, |
| 3023 | std::vector<std::pair< |
| 3024 | std::string, std::vector<std::string>>>>& |
| 3025 | object) { |
| 3026 | sdbusplus::message::object_path path(object.first); |
| 3027 | std::string name = path.filename(); |
| 3028 | if (name.empty()) |
| 3029 | { |
| 3030 | BMCWEB_LOG_ERROR << "Invalid sensor path: " |
| 3031 | << object.first; |
| 3032 | return false; |
| 3033 | } |
| 3034 | |
| 3035 | return name == sensorName; |
| 3036 | }); |
| 3037 | |
| 3038 | if (it == subtree.end()) |
| 3039 | { |
| 3040 | BMCWEB_LOG_ERROR << "Could not find path for sensor: " |
| 3041 | << sensorName; |
| 3042 | messages::resourceNotFound(asyncResp->asyncResp->res, |
| 3043 | "Sensor", sensorName); |
| 3044 | return; |
| 3045 | } |
| 3046 | std::string_view sensorPath = (*it).first; |
| 3047 | BMCWEB_LOG_DEBUG << "Found sensor path for sensor '" |
| 3048 | << sensorName << "': " << sensorPath; |
| 3049 | |
| 3050 | const std::shared_ptr< |
| 3051 | boost::container::flat_set<std::string>> |
| 3052 | sensorList = std::make_shared< |
| 3053 | boost::container::flat_set<std::string>>(); |
| 3054 | |
| 3055 | sensorList->emplace(sensorPath); |
| 3056 | processSensorList(asyncResp, sensorList); |
| 3057 | BMCWEB_LOG_DEBUG << "respHandler1 exit"; |
| 3058 | }, |
| 3059 | "xyz.openbmc_project.ObjectMapper", |
| 3060 | "/xyz/openbmc_project/object_mapper", |
| 3061 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 3062 | "/xyz/openbmc_project/sensors", 2, interfaces); |
| 3063 | }); |
| 3064 | } |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 3065 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 3066 | } // namespace redfish |