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