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