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