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