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