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