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