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