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