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