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