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