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