blob: 8506185e8d89554fb785d05ca9a6e43bed47213b [file] [log] [blame]
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01001/*
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 Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
19#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080020#include "dbus_utility.hpp"
Matt Simmeringaaf08ac2023-10-04 08:41:01 -070021#include "generated/enums/resource.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070022#include "generated/enums/sensor.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "query.hpp"
24#include "registries/privilege_registry.hpp"
Ed Tanous50ebd4a2023-01-19 19:03:17 -080025#include "str_utility.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080026#include "utils/dbus_utils.hpp"
27#include "utils/json_utils.hpp"
28#include "utils/query_param.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070029
George Liue99073f2022-12-09 11:06:16 +080030#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070031#include <boost/url/format.hpp>
Jonathan Doman1e1e5982021-06-11 09:36:17 -070032#include <sdbusplus/asio/property.hpp>
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +020033#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050034
George Liu7a1dbc42022-12-07 16:03:22 +080035#include <array>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050036#include <cmath>
Nan Zhoufe04d492022-06-22 17:10:41 +000037#include <iterator>
Ed Tanous283860f2022-08-29 14:08:50 -070038#include <limits>
Nan Zhoufe04d492022-06-22 17:10:41 +000039#include <map>
Ed Tanous3544d2a2023-08-06 18:12:20 -070040#include <ranges>
Nan Zhoufe04d492022-06-22 17:10:41 +000041#include <set>
Ed Tanous18f8f602023-07-18 10:07:23 -070042#include <string>
George Liu7a1dbc42022-12-07 16:03:22 +080043#include <string_view>
Ed Tanousb5a76932020-09-29 16:16:58 -070044#include <utility>
Ed Tanousabf2add2019-01-22 16:40:12 -080045#include <variant>
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010046
Ed Tanous1abe55e2018-09-05 08:30:59 -070047namespace redfish
48{
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010049
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020050namespace sensors
51{
52namespace node
53{
54static constexpr std::string_view power = "Power";
55static constexpr std::string_view sensors = "Sensors";
56static constexpr std::string_view thermal = "Thermal";
57} // namespace node
58
Ed Tanous02da7c52022-02-27 00:09:02 -080059// clang-format off
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020060namespace dbus
61{
Ed Tanouscf9e4172022-12-21 09:30:16 -080062constexpr auto powerPaths = std::to_array<std::string_view>({
Ed Tanous02da7c52022-02-27 00:09:02 -080063 "/xyz/openbmc_project/sensors/voltage",
64 "/xyz/openbmc_project/sensors/power"
65});
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +000066
Ed Tanouscf9e4172022-12-21 09:30:16 -080067constexpr auto sensorPaths = std::to_array<std::string_view>({
Ed Tanous02da7c52022-02-27 00:09:02 -080068 "/xyz/openbmc_project/sensors/power",
69 "/xyz/openbmc_project/sensors/current",
70 "/xyz/openbmc_project/sensors/airflow",
Ed Tanous4e777662022-08-06 09:39:13 -070071 "/xyz/openbmc_project/sensors/humidity",
George Liue8204932021-02-01 14:42:49 +080072#ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM
Ed Tanous02da7c52022-02-27 00:09:02 -080073 "/xyz/openbmc_project/sensors/voltage",
74 "/xyz/openbmc_project/sensors/fan_tach",
75 "/xyz/openbmc_project/sensors/temperature",
76 "/xyz/openbmc_project/sensors/fan_pwm",
77 "/xyz/openbmc_project/sensors/altitude",
78 "/xyz/openbmc_project/sensors/energy",
George Liue8204932021-02-01 14:42:49 +080079#endif
Ed Tanous02da7c52022-02-27 00:09:02 -080080 "/xyz/openbmc_project/sensors/utilization"
81});
82
Ed Tanouscf9e4172022-12-21 09:30:16 -080083constexpr auto thermalPaths = std::to_array<std::string_view>({
Ed Tanous02da7c52022-02-27 00:09:02 -080084 "/xyz/openbmc_project/sensors/fan_tach",
85 "/xyz/openbmc_project/sensors/temperature",
86 "/xyz/openbmc_project/sensors/fan_pwm"
87});
88
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +000089} // namespace dbus
Ed Tanous02da7c52022-02-27 00:09:02 -080090// clang-format on
91
Ed Tanouscf9e4172022-12-21 09:30:16 -080092using sensorPair =
93 std::pair<std::string_view, std::span<const std::string_view>>;
Ed Tanous02da7c52022-02-27 00:09:02 -080094static constexpr std::array<sensorPair, 3> paths = {
Ed Tanouscf9e4172022-12-21 09:30:16 -080095 {{node::power, dbus::powerPaths},
96 {node::sensors, dbus::sensorPaths},
97 {node::thermal, dbus::thermalPaths}}};
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +000098
Ed Tanous0ec8b832022-03-14 14:56:47 -070099inline sensor::ReadingType toReadingType(std::string_view sensorType)
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000100{
101 if (sensorType == "voltage")
102 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700103 return sensor::ReadingType::Voltage;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000104 }
105 if (sensorType == "power")
106 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700107 return sensor::ReadingType::Power;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000108 }
109 if (sensorType == "current")
110 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700111 return sensor::ReadingType::Current;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000112 }
113 if (sensorType == "fan_tach")
114 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700115 return sensor::ReadingType::Rotational;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000116 }
117 if (sensorType == "temperature")
118 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700119 return sensor::ReadingType::Temperature;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000120 }
121 if (sensorType == "fan_pwm" || sensorType == "utilization")
122 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700123 return sensor::ReadingType::Percent;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000124 }
Gunnar Mills5deabed2022-04-20 13:43:45 -0600125 if (sensorType == "humidity")
126 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700127 return sensor::ReadingType::Humidity;
Gunnar Mills5deabed2022-04-20 13:43:45 -0600128 }
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000129 if (sensorType == "altitude")
130 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700131 return sensor::ReadingType::Altitude;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000132 }
133 if (sensorType == "airflow")
134 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700135 return sensor::ReadingType::AirFlow;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000136 }
137 if (sensorType == "energy")
138 {
Ed Tanous0ec8b832022-03-14 14:56:47 -0700139 return sensor::ReadingType::EnergyJoules;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000140 }
Ed Tanous0ec8b832022-03-14 14:56:47 -0700141 return sensor::ReadingType::Invalid;
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000142}
143
Ed Tanous1d7c0052022-08-09 12:32:26 -0700144inline std::string_view toReadingUnits(std::string_view sensorType)
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000145{
146 if (sensorType == "voltage")
147 {
148 return "V";
149 }
150 if (sensorType == "power")
151 {
152 return "W";
153 }
154 if (sensorType == "current")
155 {
156 return "A";
157 }
158 if (sensorType == "fan_tach")
159 {
160 return "RPM";
161 }
162 if (sensorType == "temperature")
163 {
164 return "Cel";
165 }
Gunnar Mills5deabed2022-04-20 13:43:45 -0600166 if (sensorType == "fan_pwm" || sensorType == "utilization" ||
167 sensorType == "humidity")
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000168 {
169 return "%";
170 }
171 if (sensorType == "altitude")
172 {
173 return "m";
174 }
175 if (sensorType == "airflow")
176 {
177 return "cft_i/min";
178 }
179 if (sensorType == "energy")
180 {
181 return "J";
182 }
183 return "";
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200184}
185} // namespace sensors
186
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100187/**
Kowalski, Kamil588c3f02018-04-03 14:55:27 +0200188 * SensorsAsyncResp
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100189 * Gathers data needed for response processing after async calls are done
190 */
Ed Tanous1abe55e2018-09-05 08:30:59 -0700191class SensorsAsyncResp
192{
193 public:
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200194 using DataCompleteCb = std::function<void(
195 const boost::beast::http::status status,
Nan Zhoufe04d492022-06-22 17:10:41 +0000196 const std::map<std::string, std::string>& uriToDbus)>;
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200197
198 struct SensorData
199 {
200 const std::string name;
201 std::string uri;
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200202 const std::string dbusPath;
203 };
204
Ed Tanous8a592812022-06-04 09:06:59 -0700205 SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn,
zhanghch058d1b46d2021-04-01 11:18:24 +0800206 const std::string& chassisIdIn,
Ed Tanouscf9e4172022-12-21 09:30:16 -0800207 std::span<const std::string_view> typesIn,
Ed Tanous02da7c52022-02-27 00:09:02 -0800208 std::string_view subNode) :
Ed Tanous8a592812022-06-04 09:06:59 -0700209 asyncResp(asyncRespIn),
Nan Zhou928fefb2022-03-28 08:45:00 -0700210 chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode),
211 efficientExpand(false)
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500212 {}
Kowalski, Kamil588c3f02018-04-03 14:55:27 +0200213
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200214 // Store extra data about sensor mapping and return it in callback
Ed Tanous8a592812022-06-04 09:06:59 -0700215 SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn,
zhanghch058d1b46d2021-04-01 11:18:24 +0800216 const std::string& chassisIdIn,
Ed Tanouscf9e4172022-12-21 09:30:16 -0800217 std::span<const std::string_view> typesIn,
Ed Tanous02da7c52022-02-27 00:09:02 -0800218 std::string_view subNode,
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200219 DataCompleteCb&& creationComplete) :
Ed Tanous8a592812022-06-04 09:06:59 -0700220 asyncResp(asyncRespIn),
Nan Zhou928fefb2022-03-28 08:45:00 -0700221 chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode),
222 efficientExpand(false), metadata{std::vector<SensorData>()},
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200223 dataComplete{std::move(creationComplete)}
224 {}
225
Nan Zhou928fefb2022-03-28 08:45:00 -0700226 // sensor collections expand
Ed Tanous8a592812022-06-04 09:06:59 -0700227 SensorsAsyncResp(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn,
Nan Zhou928fefb2022-03-28 08:45:00 -0700228 const std::string& chassisIdIn,
Ed Tanouscf9e4172022-12-21 09:30:16 -0800229 std::span<const std::string_view> typesIn,
Ed Tanous8a592812022-06-04 09:06:59 -0700230 const std::string_view& subNode, bool efficientExpandIn) :
231 asyncResp(asyncRespIn),
Nan Zhou928fefb2022-03-28 08:45:00 -0700232 chassisId(chassisIdIn), types(typesIn), chassisSubNode(subNode),
Ed Tanous8a592812022-06-04 09:06:59 -0700233 efficientExpand(efficientExpandIn)
Nan Zhou928fefb2022-03-28 08:45:00 -0700234 {}
235
Ed Tanous1abe55e2018-09-05 08:30:59 -0700236 ~SensorsAsyncResp()
237 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800238 if (asyncResp->res.result() ==
239 boost::beast::http::status::internal_server_error)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700240 {
241 // Reset the json object to clear out any data that made it in
242 // before the error happened todo(ed) handle error condition with
243 // proper code
zhanghch058d1b46d2021-04-01 11:18:24 +0800244 asyncResp->res.jsonValue = nlohmann::json::object();
Ed Tanous1abe55e2018-09-05 08:30:59 -0700245 }
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200246
247 if (dataComplete && metadata)
248 {
Nan Zhoufe04d492022-06-22 17:10:41 +0000249 std::map<std::string, std::string> map;
zhanghch058d1b46d2021-04-01 11:18:24 +0800250 if (asyncResp->res.result() == boost::beast::http::status::ok)
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200251 {
252 for (auto& sensor : *metadata)
253 {
Ed Tanousc1d019a2022-08-06 09:36:06 -0700254 map.emplace(sensor.uri, sensor.dbusPath);
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200255 }
256 }
zhanghch058d1b46d2021-04-01 11:18:24 +0800257 dataComplete(asyncResp->res.result(), map);
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200258 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700259 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100260
Ed Tanousecd6a3a2022-01-07 09:18:40 -0800261 SensorsAsyncResp(const SensorsAsyncResp&) = delete;
262 SensorsAsyncResp(SensorsAsyncResp&&) = delete;
263 SensorsAsyncResp& operator=(const SensorsAsyncResp&) = delete;
264 SensorsAsyncResp& operator=(SensorsAsyncResp&&) = delete;
265
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200266 void addMetadata(const nlohmann::json& sensorObject,
Ed Tanousc1d019a2022-08-06 09:36:06 -0700267 const std::string& dbusPath)
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200268 {
269 if (metadata)
270 {
Ed Tanousc1d019a2022-08-06 09:36:06 -0700271 metadata->emplace_back(SensorData{
272 sensorObject["Name"], sensorObject["@odata.id"], dbusPath});
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200273 }
274 }
275
276 void updateUri(const std::string& name, const std::string& uri)
277 {
278 if (metadata)
279 {
280 for (auto& sensor : *metadata)
281 {
282 if (sensor.name == name)
283 {
284 sensor.uri = uri;
285 }
286 }
287 }
288 }
289
zhanghch058d1b46d2021-04-01 11:18:24 +0800290 const std::shared_ptr<bmcweb::AsyncResp> asyncResp;
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200291 const std::string chassisId;
Ed Tanouscf9e4172022-12-21 09:30:16 -0800292 const std::span<const std::string_view> types;
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200293 const std::string chassisSubNode;
Nan Zhou928fefb2022-03-28 08:45:00 -0700294 const bool efficientExpand;
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +0200295
296 private:
297 std::optional<std::vector<SensorData>> metadata;
298 DataCompleteCb dataComplete;
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100299};
300
301/**
Anthony Wilsond5005492019-07-31 16:34:17 -0500302 * Possible states for physical inventory leds
303 */
304enum class LedState
305{
306 OFF,
307 ON,
308 BLINK,
309 UNKNOWN
310};
311
312/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500313 * D-Bus inventory item associated with one or more sensors.
314 */
315class InventoryItem
316{
317 public:
Ed Tanous4e23a442022-06-06 09:57:26 -0700318 explicit InventoryItem(const std::string& objPath) : objectPath(objPath)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500319 {
320 // Set inventory item name to last node of object path
George Liu28aa8de2021-02-01 15:13:30 +0800321 sdbusplus::message::object_path path(objectPath);
322 name = path.filename();
323 if (name.empty())
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500324 {
Ed Tanous62598e32023-07-17 17:06:25 -0700325 BMCWEB_LOG_ERROR("Failed to find '/' in {}", objectPath);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500326 }
327 }
328
329 std::string objectPath;
330 std::string name;
Ed Tanouse05aec52022-01-25 10:28:56 -0800331 bool isPresent = true;
332 bool isFunctional = true;
333 bool isPowerSupply = false;
334 int powerSupplyEfficiencyPercent = -1;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500335 std::string manufacturer;
336 std::string model;
337 std::string partNumber;
338 std::string serialNumber;
339 std::set<std::string> sensors;
Anthony Wilsond5005492019-07-31 16:34:17 -0500340 std::string ledObjectPath;
Ed Tanouse05aec52022-01-25 10:28:56 -0800341 LedState ledState = LedState::UNKNOWN;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500342};
343
344/**
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530345 * @brief Get objects with connection necessary for sensors
Kowalski, Kamil588c3f02018-04-03 14:55:27 +0200346 * @param SensorsAsyncResp Pointer to object holding response data
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100347 * @param sensorNames Sensors retrieved from chassis
348 * @param callback Callback for processing gathered connections
349 */
350template <typename Callback>
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530351void getObjectsWithConnection(
Ed Tanous81ce6092020-12-17 16:54:55 +0000352 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Nan Zhoufe04d492022-06-22 17:10:41 +0000353 const std::shared_ptr<std::set<std::string>>& sensorNames,
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530354 Callback&& callback)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700355{
Ed Tanous62598e32023-07-17 17:06:25 -0700356 BMCWEB_LOG_DEBUG("getObjectsWithConnection enter");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700357 const std::string path = "/xyz/openbmc_project/sensors";
George Liue99073f2022-12-09 11:06:16 +0800358 constexpr std::array<std::string_view, 1> interfaces = {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700359 "xyz.openbmc_project.Sensor.Value"};
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100360
George Liue99073f2022-12-09 11:06:16 +0800361 // Make call to ObjectMapper to find all sensors objects
362 dbus::utility::getSubTree(
363 path, 2, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -0700364 [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
George Liue99073f2022-12-09 11:06:16 +0800365 sensorNames](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -0700366 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liue99073f2022-12-09 11:06:16 +0800367 // Response handler for parsing objects subtree
Ed Tanous62598e32023-07-17 17:06:25 -0700368 BMCWEB_LOG_DEBUG("getObjectsWithConnection resp_handler enter");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700369 if (ec)
370 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800371 messages::internalError(sensorsAsyncResp->asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -0700372 BMCWEB_LOG_ERROR(
373 "getObjectsWithConnection resp_handler: Dbus error {}", ec);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700374 return;
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100375 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100376
Ed Tanous62598e32023-07-17 17:06:25 -0700377 BMCWEB_LOG_DEBUG("Found {} subtrees", subtree.size());
Ed Tanous1abe55e2018-09-05 08:30:59 -0700378
379 // Make unique list of connections only for requested sensor types and
380 // found in the chassis
Nan Zhoufe04d492022-06-22 17:10:41 +0000381 std::set<std::string> connections;
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530382 std::set<std::pair<std::string, std::string>> objectsWithConnection;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700383
Ed Tanous62598e32023-07-17 17:06:25 -0700384 BMCWEB_LOG_DEBUG("sensorNames list count: {}", sensorNames->size());
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700385 for (const std::string& tsensor : *sensorNames)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700386 {
Ed Tanous62598e32023-07-17 17:06:25 -0700387 BMCWEB_LOG_DEBUG("Sensor to find: {}", tsensor);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700388 }
389
390 for (const std::pair<
391 std::string,
392 std::vector<std::pair<std::string, std::vector<std::string>>>>&
393 object : subtree)
394 {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700395 if (sensorNames->find(object.first) != sensorNames->end())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700396 {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700397 for (const std::pair<std::string, std::vector<std::string>>&
398 objData : object.second)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700399 {
Ed Tanous62598e32023-07-17 17:06:25 -0700400 BMCWEB_LOG_DEBUG("Adding connection: {}", objData.first);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700401 connections.insert(objData.first);
402 objectsWithConnection.insert(
403 std::make_pair(object.first, objData.first));
Ed Tanous1abe55e2018-09-05 08:30:59 -0700404 }
405 }
406 }
Ed Tanous62598e32023-07-17 17:06:25 -0700407 BMCWEB_LOG_DEBUG("Found {} connections", connections.size());
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530408 callback(std::move(connections), std::move(objectsWithConnection));
Ed Tanous62598e32023-07-17 17:06:25 -0700409 BMCWEB_LOG_DEBUG("getObjectsWithConnection resp_handler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -0500410 });
Ed Tanous62598e32023-07-17 17:06:25 -0700411 BMCWEB_LOG_DEBUG("getObjectsWithConnection exit");
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530412}
413
414/**
415 * @brief Create connections necessary for sensors
416 * @param SensorsAsyncResp Pointer to object holding response data
417 * @param sensorNames Sensors retrieved from chassis
418 * @param callback Callback for processing gathered connections
419 */
420template <typename Callback>
Nan Zhoufe04d492022-06-22 17:10:41 +0000421void getConnections(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
422 const std::shared_ptr<std::set<std::string>> sensorNames,
423 Callback&& callback)
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530424{
425 auto objectsWithConnectionCb =
Nan Zhoufe04d492022-06-22 17:10:41 +0000426 [callback](const std::set<std::string>& connections,
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530427 const std::set<std::pair<std::string, std::string>>&
Ed Tanous3174e4d2020-10-07 11:41:22 -0700428 /*objectsWithConnection*/) { callback(connections); };
Ed Tanous81ce6092020-12-17 16:54:55 +0000429 getObjectsWithConnection(sensorsAsyncResp, sensorNames,
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530430 std::move(objectsWithConnectionCb));
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100431}
432
433/**
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700434 * @brief Shrinks the list of sensors for processing
435 * @param SensorsAysncResp The class holding the Redfish response
436 * @param allSensors A list of all the sensors associated to the
437 * chassis element (i.e. baseboard, front panel, etc...)
438 * @param activeSensors A list that is a reduction of the incoming
439 * allSensors list. Eliminate Thermal sensors when a Power request is
440 * made, and eliminate Power sensors when a Thermal request is made.
441 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000442inline void reduceSensorList(
Ed Tanous7f1cc262022-08-09 13:33:57 -0700443 crow::Response& res, std::string_view chassisSubNode,
Ed Tanouscf9e4172022-12-21 09:30:16 -0800444 std::span<const std::string_view> sensorTypes,
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700445 const std::vector<std::string>* allSensors,
Nan Zhoufe04d492022-06-22 17:10:41 +0000446 const std::shared_ptr<std::set<std::string>>& activeSensors)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700447{
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700448 if ((allSensors == nullptr) || (activeSensors == nullptr))
449 {
Ed Tanous7f1cc262022-08-09 13:33:57 -0700450 messages::resourceNotFound(res, chassisSubNode,
451 chassisSubNode == sensors::node::thermal
452 ? "Temperatures"
453 : "Voltages");
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700454
455 return;
456 }
457 if (allSensors->empty())
458 {
459 // Nothing to do, the activeSensors object is also empty
460 return;
461 }
462
Ed Tanous7f1cc262022-08-09 13:33:57 -0700463 for (std::string_view type : sensorTypes)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700464 {
465 for (const std::string& sensor : *allSensors)
466 {
Ed Tanous11ba3972022-07-11 09:50:41 -0700467 if (sensor.starts_with(type))
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700468 {
469 activeSensors->emplace(sensor);
470 }
471 }
472 }
473}
474
Ed Tanous7f1cc262022-08-09 13:33:57 -0700475/*
476 *Populates the top level collection for a given subnode. Populates
477 *SensorCollection, Power, or Thermal schemas.
478 *
479 * */
480inline void populateChassisNode(nlohmann::json& jsonValue,
481 std::string_view chassisSubNode)
482{
483 if (chassisSubNode == sensors::node::power)
484 {
485 jsonValue["@odata.type"] = "#Power.v1_5_2.Power";
486 }
487 else if (chassisSubNode == sensors::node::thermal)
488 {
489 jsonValue["@odata.type"] = "#Thermal.v1_4_0.Thermal";
490 jsonValue["Fans"] = nlohmann::json::array();
491 jsonValue["Temperatures"] = nlohmann::json::array();
492 }
493 else if (chassisSubNode == sensors::node::sensors)
494 {
495 jsonValue["@odata.type"] = "#SensorCollection.SensorCollection";
496 jsonValue["Description"] = "Collection of Sensors for this Chassis";
497 jsonValue["Members"] = nlohmann::json::array();
498 jsonValue["Members@odata.count"] = 0;
499 }
500
501 if (chassisSubNode != sensors::node::sensors)
502 {
503 jsonValue["Id"] = chassisSubNode;
504 }
505 jsonValue["Name"] = chassisSubNode;
506}
507
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700508/**
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100509 * @brief Retrieves requested chassis sensors and redundancy data from DBus .
Kowalski, Kamil588c3f02018-04-03 14:55:27 +0200510 * @param SensorsAsyncResp Pointer to object holding response data
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100511 * @param callback Callback for next step in gathered sensor processing
512 */
513template <typename Callback>
Ed Tanous7f1cc262022-08-09 13:33:57 -0700514void getChassis(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
515 std::string_view chassisId, std::string_view chassisSubNode,
Ed Tanouscf9e4172022-12-21 09:30:16 -0800516 std::span<const std::string_view> sensorTypes,
517 Callback&& callback)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700518{
Ed Tanous62598e32023-07-17 17:06:25 -0700519 BMCWEB_LOG_DEBUG("getChassis enter");
George Liu7a1dbc42022-12-07 16:03:22 +0800520 constexpr std::array<std::string_view, 2> interfaces = {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700521 "xyz.openbmc_project.Inventory.Item.Board",
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500522 "xyz.openbmc_project.Inventory.Item.Chassis"};
George Liu7a1dbc42022-12-07 16:03:22 +0800523
524 // Get the Chassis Collection
525 dbus::utility::getSubTreePaths(
526 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous7f1cc262022-08-09 13:33:57 -0700527 [callback{std::forward<Callback>(callback)}, asyncResp,
528 chassisIdStr{std::string(chassisId)},
529 chassisSubNode{std::string(chassisSubNode)}, sensorTypes](
George Liu7a1dbc42022-12-07 16:03:22 +0800530 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -0700531 const dbus::utility::MapperGetSubTreePathsResponse& chassisPaths) {
Ed Tanous62598e32023-07-17 17:06:25 -0700532 BMCWEB_LOG_DEBUG("getChassis respHandler enter");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700533 if (ec)
534 {
Ed Tanous62598e32023-07-17 17:06:25 -0700535 BMCWEB_LOG_ERROR("getChassis respHandler DBUS error: {}", ec);
Ed Tanous7f1cc262022-08-09 13:33:57 -0700536 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700537 return;
538 }
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700539 const std::string* chassisPath = nullptr;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700540 for (const std::string& chassis : chassisPaths)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700541 {
George Liu28aa8de2021-02-01 15:13:30 +0800542 sdbusplus::message::object_path path(chassis);
Ed Tanousf8fe53e2022-06-30 15:55:45 -0700543 std::string chassisName = path.filename();
George Liu28aa8de2021-02-01 15:13:30 +0800544 if (chassisName.empty())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700545 {
Ed Tanous62598e32023-07-17 17:06:25 -0700546 BMCWEB_LOG_ERROR("Failed to find '/' in {}", chassis);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700547 continue;
548 }
Ed Tanous7f1cc262022-08-09 13:33:57 -0700549 if (chassisName == chassisIdStr)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700550 {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700551 chassisPath = &chassis;
552 break;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700553 }
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700554 }
555 if (chassisPath == nullptr)
556 {
Ed Tanous7f1cc262022-08-09 13:33:57 -0700557 messages::resourceNotFound(asyncResp->res, "Chassis", chassisIdStr);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700558 return;
559 }
Ed Tanous7f1cc262022-08-09 13:33:57 -0700560 populateChassisNode(asyncResp->res.jsonValue, chassisSubNode);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700561
Ed Tanousef4c65b2023-04-24 15:28:50 -0700562 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
563 "/redfish/v1/Chassis/{}/{}", chassisIdStr, chassisSubNode);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500564
Shawn McCarney8fb49dd2019-06-12 17:47:00 -0500565 // Get the list of all sensors for this Chassis element
566 std::string sensorPath = *chassisPath + "/all_sensors";
George Liu6c3e9452023-03-03 13:55:29 +0800567 dbus::utility::getAssociationEndPoints(
568 sensorPath,
Ed Tanous7f1cc262022-08-09 13:33:57 -0700569 [asyncResp, chassisSubNode, sensorTypes,
Ed Tanousf94c4ec2022-01-06 12:44:41 -0800570 callback{std::forward<const Callback>(callback)}](
Ed Tanous8b242752023-06-27 17:17:13 -0700571 const boost::system::error_code& ec2,
George Liu6c3e9452023-03-03 13:55:29 +0800572 const dbus::utility::MapperEndPoints& nodeSensorList) {
Ed Tanous8b242752023-06-27 17:17:13 -0700573 if (ec2)
Ed Tanous002d39b2022-05-31 08:59:27 -0700574 {
Ed Tanous8b242752023-06-27 17:17:13 -0700575 if (ec2.value() != EBADR)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700576 {
Ed Tanous7f1cc262022-08-09 13:33:57 -0700577 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700578 return;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700579 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700580 }
Nan Zhoufe04d492022-06-22 17:10:41 +0000581 const std::shared_ptr<std::set<std::string>> culledSensorList =
582 std::make_shared<std::set<std::string>>();
Ed Tanous7f1cc262022-08-09 13:33:57 -0700583 reduceSensorList(asyncResp->res, chassisSubNode, sensorTypes,
584 &nodeSensorList, culledSensorList);
Ed Tanous62598e32023-07-17 17:06:25 -0700585 BMCWEB_LOG_DEBUG("Finishing with {}", culledSensorList->size());
Ed Tanous002d39b2022-05-31 08:59:27 -0700586 callback(culledSensorList);
George Liu7a1dbc42022-12-07 16:03:22 +0800587 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500588 });
Ed Tanous62598e32023-07-17 17:06:25 -0700589 BMCWEB_LOG_DEBUG("getChassis exit");
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100590}
591
592/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500593 * @brief Returns the Redfish State value for the specified inventory item.
594 * @param inventoryItem D-Bus inventory item associated with a sensor.
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700595 * @param sensorAvailable Boolean representing if D-Bus sensor is marked as
596 * available.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500597 * @return State value for inventory item.
James Feist34dd1792019-05-17 14:10:54 -0700598 */
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700599inline resource::State getState(const InventoryItem* inventoryItem,
600 const bool sensorAvailable)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500601{
602 if ((inventoryItem != nullptr) && !(inventoryItem->isPresent))
603 {
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700604 return resource::State::Absent;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500605 }
James Feist34dd1792019-05-17 14:10:54 -0700606
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700607 if (!sensorAvailable)
608 {
609 return resource::State::UnavailableOffline;
610 }
611
612 return resource::State::Enabled;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500613}
614
615/**
616 * @brief Returns the Redfish Health value for the specified sensor.
617 * @param sensorJson Sensor JSON object.
Ed Tanous1d7c0052022-08-09 12:32:26 -0700618 * @param valuesDict Map of all sensor DBus values.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500619 * @param inventoryItem D-Bus inventory item associated with the sensor. Will
620 * be nullptr if no associated inventory item was found.
621 * @return Health value for sensor.
622 */
Ed Tanous1d7c0052022-08-09 12:32:26 -0700623inline std::string getHealth(nlohmann::json& sensorJson,
624 const dbus::utility::DBusPropertiesMap& valuesDict,
625 const InventoryItem* inventoryItem)
James Feist34dd1792019-05-17 14:10:54 -0700626{
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500627 // Get current health value (if any) in the sensor JSON object. Some JSON
628 // objects contain multiple sensors (such as PowerSupplies). We want to set
629 // the overall health to be the most severe of any of the sensors.
630 std::string currentHealth;
631 auto statusIt = sensorJson.find("Status");
632 if (statusIt != sensorJson.end())
633 {
634 auto healthIt = statusIt->find("Health");
635 if (healthIt != statusIt->end())
636 {
637 std::string* health = healthIt->get_ptr<std::string*>();
638 if (health != nullptr)
639 {
640 currentHealth = *health;
641 }
642 }
643 }
644
645 // If current health in JSON object is already Critical, return that. This
646 // should override the sensor health, which might be less severe.
647 if (currentHealth == "Critical")
648 {
649 return "Critical";
650 }
651
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200652 const bool* criticalAlarmHigh = nullptr;
653 const bool* criticalAlarmLow = nullptr;
654 const bool* warningAlarmHigh = nullptr;
655 const bool* warningAlarmLow = nullptr;
Ed Tanous711ac7a2021-12-20 09:34:41 -0800656
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200657 const bool success = sdbusplus::unpackPropertiesNoThrow(
658 dbus_utils::UnpackErrorPrinter(), valuesDict, "CriticalAlarmHigh",
659 criticalAlarmHigh, "CriticalAlarmLow", criticalAlarmLow,
660 "WarningAlarmHigh", warningAlarmHigh, "WarningAlarmLow",
661 warningAlarmLow);
662
663 if (success)
James Feist34dd1792019-05-17 14:10:54 -0700664 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200665 // Check if sensor has critical threshold alarm
666 if ((criticalAlarmHigh != nullptr && *criticalAlarmHigh) ||
667 (criticalAlarmLow != nullptr && *criticalAlarmLow))
James Feist34dd1792019-05-17 14:10:54 -0700668 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200669 return "Critical";
James Feist34dd1792019-05-17 14:10:54 -0700670 }
671 }
672
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500673 // Check if associated inventory item is not functional
674 if ((inventoryItem != nullptr) && !(inventoryItem->isFunctional))
675 {
676 return "Critical";
677 }
678
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200679 // If current health in JSON object is already Warning, return that. This
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500680 // should override the sensor status, which might be less severe.
681 if (currentHealth == "Warning")
682 {
683 return "Warning";
684 }
685
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200686 if (success)
James Feist34dd1792019-05-17 14:10:54 -0700687 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200688 // Check if sensor has warning threshold alarm
689 if ((warningAlarmHigh != nullptr && *warningAlarmHigh) ||
690 (warningAlarmLow != nullptr && *warningAlarmLow))
James Feist34dd1792019-05-17 14:10:54 -0700691 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200692 return "Warning";
James Feist34dd1792019-05-17 14:10:54 -0700693 }
694 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500695
James Feist34dd1792019-05-17 14:10:54 -0700696 return "OK";
697}
698
Ed Tanous23a21a12020-07-25 04:45:05 +0000699inline void setLedState(nlohmann::json& sensorJson,
Anthony Wilsond5005492019-07-31 16:34:17 -0500700 const InventoryItem* inventoryItem)
701{
702 if (inventoryItem != nullptr && !inventoryItem->ledObjectPath.empty())
703 {
704 switch (inventoryItem->ledState)
705 {
706 case LedState::OFF:
707 sensorJson["IndicatorLED"] = "Off";
708 break;
709 case LedState::ON:
710 sensorJson["IndicatorLED"] = "Lit";
711 break;
712 case LedState::BLINK:
713 sensorJson["IndicatorLED"] = "Blinking";
714 break;
Ed Tanous4da04902024-03-19 11:32:44 -0700715 default:
Anthony Wilsond5005492019-07-31 16:34:17 -0500716 break;
717 }
718 }
719}
720
James Feist34dd1792019-05-17 14:10:54 -0700721/**
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100722 * @brief Builds a json sensor representation of a sensor.
723 * @param sensorName The name of the sensor to be built
Gunnar Mills274fad52018-06-13 15:45:36 -0500724 * @param sensorType The type (temperature, fan_tach, etc) of the sensor to
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100725 * build
Ed Tanous8ece0e42024-01-02 13:16:50 -0800726 * @param chassisSubNode The subnode (thermal, sensor, etc) of the sensor
Ed Tanous1d7c0052022-08-09 12:32:26 -0700727 * @param propertiesDict A dictionary of the properties to build the sensor
728 * from.
729 * @param sensorJson The json object to fill
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500730 * @param inventoryItem D-Bus inventory item associated with the sensor. Will
731 * be nullptr if no associated inventory item was found.
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100732 */
Ed Tanous1d7c0052022-08-09 12:32:26 -0700733inline void objectPropertiesToJson(
734 std::string_view sensorName, std::string_view sensorType,
735 std::string_view chassisSubNode,
736 const dbus::utility::DBusPropertiesMap& propertiesDict,
Ed Tanous81ce6092020-12-17 16:54:55 +0000737 nlohmann::json& sensorJson, InventoryItem* inventoryItem)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700738{
Ed Tanous1d7c0052022-08-09 12:32:26 -0700739 if (chassisSubNode == sensors::node::sensors)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500740 {
Ed Tanousc71d6122022-11-29 14:10:32 -0800741 std::string subNodeEscaped(sensorType);
Ed Tanous3544d2a2023-08-06 18:12:20 -0700742 auto remove = std::ranges::remove(subNodeEscaped, '_');
743 subNodeEscaped.erase(std::ranges::begin(remove), subNodeEscaped.end());
Ed Tanousc1d019a2022-08-06 09:36:06 -0700744
745 // For sensors in SensorCollection we set Id instead of MemberId,
746 // including power sensors.
747 subNodeEscaped += '_';
748 subNodeEscaped += sensorName;
749 sensorJson["Id"] = std::move(subNodeEscaped);
750
Ed Tanous1d7c0052022-08-09 12:32:26 -0700751 std::string sensorNameEs(sensorName);
752 std::replace(sensorNameEs.begin(), sensorNameEs.end(), '_', ' ');
753 sensorJson["Name"] = std::move(sensorNameEs);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500754 }
755 else if (sensorType != "power")
756 {
757 // Set MemberId and Name for non-power sensors. For PowerSupplies and
758 // PowerControl, those properties have more general values because
759 // multiple sensors can be stored in the same JSON object.
Ed Tanous1d7c0052022-08-09 12:32:26 -0700760 std::string sensorNameEs(sensorName);
761 std::replace(sensorNameEs.begin(), sensorNameEs.end(), '_', ' ');
762 sensorJson["Name"] = std::move(sensorNameEs);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500763 }
Ed Tanouse742b6c2019-05-03 15:06:53 -0700764
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700765 const bool* checkAvailable = nullptr;
766 bool available = true;
767 const bool success = sdbusplus::unpackPropertiesNoThrow(
768 dbus_utils::UnpackErrorPrinter(), propertiesDict, "Available",
769 checkAvailable);
770 if (!success)
771 {
772 messages::internalError();
773 }
774 if (checkAvailable != nullptr)
775 {
776 available = *checkAvailable;
777 }
778
779 sensorJson["Status"]["State"] = getState(inventoryItem, available);
Patrick Williams89492a12023-05-10 07:51:34 -0500780 sensorJson["Status"]["Health"] = getHealth(sensorJson, propertiesDict,
781 inventoryItem);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700782
783 // Parameter to set to override the type we get from dbus, and force it to
784 // int, regardless of what is available. This is used for schemas like fan,
785 // that require integers, not floats.
786 bool forceToInt = false;
787
Anthony Wilson3929aca2019-07-19 15:42:33 -0500788 nlohmann::json::json_pointer unit("/Reading");
Ed Tanous1d7c0052022-08-09 12:32:26 -0700789 if (chassisSubNode == sensors::node::sensors)
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500790 {
Shounak Mitra2a4ba192022-06-01 23:34:12 +0000791 sensorJson["@odata.type"] = "#Sensor.v1_2_0.Sensor";
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000792
Ed Tanous0ec8b832022-03-14 14:56:47 -0700793 sensor::ReadingType readingType = sensors::toReadingType(sensorType);
794 if (readingType == sensor::ReadingType::Invalid)
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500795 {
Ed Tanous62598e32023-07-17 17:06:25 -0700796 BMCWEB_LOG_ERROR("Redfish cannot map reading type for {}",
797 sensorType);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500798 }
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000799 else
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500800 {
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000801 sensorJson["ReadingType"] = readingType;
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500802 }
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000803
Ed Tanous1d7c0052022-08-09 12:32:26 -0700804 std::string_view readingUnits = sensors::toReadingUnits(sensorType);
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000805 if (readingUnits.empty())
Adrian Ambrożewiczf8ede152020-06-02 13:26:33 +0200806 {
Ed Tanous62598e32023-07-17 17:06:25 -0700807 BMCWEB_LOG_ERROR("Redfish cannot map reading unit for {}",
808 sensorType);
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000809 }
810 else
811 {
812 sensorJson["ReadingUnits"] = readingUnits;
Adrian Ambrożewiczf8ede152020-06-02 13:26:33 +0200813 }
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500814 }
815 else if (sensorType == "temperature")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700816 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500817 unit = "/ReadingCelsius"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000818 sensorJson["@odata.type"] = "#Thermal.v1_3_0.Temperature";
Ed Tanous1abe55e2018-09-05 08:30:59 -0700819 // TODO(ed) Documentation says that path should be type fan_tach,
820 // implementation seems to implement fan
821 }
822 else if (sensorType == "fan" || sensorType == "fan_tach")
823 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500824 unit = "/Reading"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000825 sensorJson["ReadingUnits"] = "RPM";
826 sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan";
827 setLedState(sensorJson, inventoryItem);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700828 forceToInt = true;
829 }
Ed Tanous6f6d0d32018-10-12 11:16:43 -0700830 else if (sensorType == "fan_pwm")
831 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500832 unit = "/Reading"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000833 sensorJson["ReadingUnits"] = "Percent";
834 sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan";
835 setLedState(sensorJson, inventoryItem);
Ed Tanous6f6d0d32018-10-12 11:16:43 -0700836 forceToInt = true;
837 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700838 else if (sensorType == "voltage")
839 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500840 unit = "/ReadingVolts"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000841 sensorJson["@odata.type"] = "#Power.v1_0_0.Voltage";
Ed Tanous1abe55e2018-09-05 08:30:59 -0700842 }
Ed Tanous2474adf2018-09-05 16:31:16 -0700843 else if (sensorType == "power")
844 {
Ed Tanous18f8f602023-07-18 10:07:23 -0700845 std::string lower;
846 std::ranges::transform(sensorName, std::back_inserter(lower),
847 bmcweb::asciiToLower);
848 if (lower == "total_power")
Eddie James028f7eb2019-05-17 21:24:36 +0000849 {
Ed Tanous81ce6092020-12-17 16:54:55 +0000850 sensorJson["@odata.type"] = "#Power.v1_0_0.PowerControl";
Gunnar Mills7ab06f42019-07-02 13:07:16 -0500851 // Put multiple "sensors" into a single PowerControl, so have
852 // generic names for MemberId and Name. Follows Redfish mockup.
Ed Tanous81ce6092020-12-17 16:54:55 +0000853 sensorJson["MemberId"] = "0";
854 sensorJson["Name"] = "Chassis Power Control";
Anthony Wilson3929aca2019-07-19 15:42:33 -0500855 unit = "/PowerConsumedWatts"_json_pointer;
Eddie James028f7eb2019-05-17 21:24:36 +0000856 }
Ed Tanous18f8f602023-07-18 10:07:23 -0700857 else if (lower.find("input") != std::string::npos)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700858 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500859 unit = "/PowerInputWatts"_json_pointer;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700860 }
861 else
862 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500863 unit = "/PowerOutputWatts"_json_pointer;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700864 }
Ed Tanous2474adf2018-09-05 16:31:16 -0700865 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700866 else
867 {
Ed Tanous62598e32023-07-17 17:06:25 -0700868 BMCWEB_LOG_ERROR("Redfish cannot map object type for {}", sensorName);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700869 return;
870 }
871 // Map of dbus interface name, dbus property name and redfish property_name
Anthony Wilson3929aca2019-07-19 15:42:33 -0500872 std::vector<
873 std::tuple<const char*, const char*, nlohmann::json::json_pointer>>
874 properties;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700875 properties.reserve(7);
876
877 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "Value", unit);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600878
Ed Tanous1d7c0052022-08-09 12:32:26 -0700879 if (chassisSubNode == sensors::node::sensors)
Anthony Wilson3929aca2019-07-19 15:42:33 -0500880 {
881 properties.emplace_back(
882 "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningHigh",
883 "/Thresholds/UpperCaution/Reading"_json_pointer);
884 properties.emplace_back(
885 "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningLow",
886 "/Thresholds/LowerCaution/Reading"_json_pointer);
887 properties.emplace_back(
888 "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalHigh",
889 "/Thresholds/UpperCritical/Reading"_json_pointer);
890 properties.emplace_back(
891 "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalLow",
892 "/Thresholds/LowerCritical/Reading"_json_pointer);
893 }
894 else if (sensorType != "power")
Shawn McCarneyde629b62019-03-08 10:42:51 -0600895 {
896 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500897 "WarningHigh",
898 "/UpperThresholdNonCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600899 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500900 "WarningLow",
901 "/LowerThresholdNonCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600902 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500903 "CriticalHigh",
904 "/UpperThresholdCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600905 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500906 "CriticalLow",
907 "/LowerThresholdCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600908 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700909
Ed Tanous2474adf2018-09-05 16:31:16 -0700910 // TODO Need to get UpperThresholdFatal and LowerThresholdFatal
911
Ed Tanous1d7c0052022-08-09 12:32:26 -0700912 if (chassisSubNode == sensors::node::sensors)
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500913 {
914 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500915 "/ReadingRangeMin"_json_pointer);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500916 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500917 "/ReadingRangeMax"_json_pointer);
George Liu51c35a82022-10-13 20:22:14 +0800918 properties.emplace_back("xyz.openbmc_project.Sensor.Accuracy",
919 "Accuracy", "/Accuracy"_json_pointer);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500920 }
921 else if (sensorType == "temperature")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700922 {
923 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500924 "/MinReadingRangeTemp"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700925 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500926 "/MaxReadingRangeTemp"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700927 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500928 else if (sensorType != "power")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700929 {
930 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500931 "/MinReadingRange"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700932 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500933 "/MaxReadingRange"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700934 }
935
Anthony Wilson3929aca2019-07-19 15:42:33 -0500936 for (const std::tuple<const char*, const char*,
937 nlohmann::json::json_pointer>& p : properties)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700938 {
Ed Tanous1d7c0052022-08-09 12:32:26 -0700939 for (const auto& [valueName, valueVariant] : propertiesDict)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700940 {
Ed Tanous1d7c0052022-08-09 12:32:26 -0700941 if (valueName != std::get<1>(p))
Ed Tanous1abe55e2018-09-05 08:30:59 -0700942 {
Ed Tanous711ac7a2021-12-20 09:34:41 -0800943 continue;
944 }
Ed Tanous1d7c0052022-08-09 12:32:26 -0700945
946 // The property we want to set may be nested json, so use
947 // a json_pointer for easy indexing into the json structure.
948 const nlohmann::json::json_pointer& key = std::get<2>(p);
949
Ed Tanous1d7c0052022-08-09 12:32:26 -0700950 const double* doubleValue = std::get_if<double>(&valueVariant);
Ed Tanous40e4f382022-08-09 18:42:51 -0700951 if (doubleValue == nullptr)
Ed Tanous711ac7a2021-12-20 09:34:41 -0800952 {
Ed Tanous62598e32023-07-17 17:06:25 -0700953 BMCWEB_LOG_ERROR("Got value interface that wasn't double");
Ed Tanous1d7c0052022-08-09 12:32:26 -0700954 continue;
955 }
Ed Tanous283860f2022-08-29 14:08:50 -0700956 if (!std::isfinite(*doubleValue))
957 {
958 if (valueName == "Value")
959 {
960 // Readings are allowed to be NAN for unavailable; coerce
961 // them to null in the json response.
962 sensorJson[key] = nullptr;
963 continue;
964 }
Ed Tanous62598e32023-07-17 17:06:25 -0700965 BMCWEB_LOG_WARNING("Sensor value for {} was unexpectedly {}",
966 valueName, *doubleValue);
Ed Tanous283860f2022-08-29 14:08:50 -0700967 continue;
968 }
Ed Tanous1d7c0052022-08-09 12:32:26 -0700969 if (forceToInt)
970 {
Ed Tanous40e4f382022-08-09 18:42:51 -0700971 sensorJson[key] = static_cast<int64_t>(*doubleValue);
Ed Tanous1d7c0052022-08-09 12:32:26 -0700972 }
973 else
974 {
Ed Tanous40e4f382022-08-09 18:42:51 -0700975 sensorJson[key] = *doubleValue;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700976 }
977 }
978 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100979}
980
Ed Tanous1d7c0052022-08-09 12:32:26 -0700981/**
982 * @brief Builds a json sensor representation of a sensor.
983 * @param sensorName The name of the sensor to be built
984 * @param sensorType The type (temperature, fan_tach, etc) of the sensor to
985 * build
Ed Tanous8ece0e42024-01-02 13:16:50 -0800986 * @param chassisSubNode The subnode (thermal, sensor, etc) of the sensor
Ed Tanous1d7c0052022-08-09 12:32:26 -0700987 * @param interfacesDict A dictionary of the interfaces and properties of said
988 * interfaces to be built from
989 * @param sensorJson The json object to fill
990 * @param inventoryItem D-Bus inventory item associated with the sensor. Will
991 * be nullptr if no associated inventory item was found.
992 */
993inline void objectInterfacesToJson(
994 const std::string& sensorName, const std::string& sensorType,
995 const std::string& chassisSubNode,
Michael Shen80f79a42023-08-24 13:41:53 +0000996 const dbus::utility::DBusInterfacesMap& interfacesDict,
Ed Tanous1d7c0052022-08-09 12:32:26 -0700997 nlohmann::json& sensorJson, InventoryItem* inventoryItem)
998{
Ed Tanous1d7c0052022-08-09 12:32:26 -0700999 for (const auto& [interface, valuesDict] : interfacesDict)
1000 {
1001 objectPropertiesToJson(sensorName, sensorType, chassisSubNode,
1002 valuesDict, sensorJson, inventoryItem);
1003 }
Ed Tanous62598e32023-07-17 17:06:25 -07001004 BMCWEB_LOG_DEBUG("Added sensor {}", sensorName);
Ed Tanous1d7c0052022-08-09 12:32:26 -07001005}
1006
Ed Tanousb5a76932020-09-29 16:16:58 -07001007inline void populateFanRedundancy(
1008 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
James Feist8bd25cc2019-03-15 15:14:00 -07001009{
George Liue99073f2022-12-09 11:06:16 +08001010 constexpr std::array<std::string_view, 1> interfaces = {
1011 "xyz.openbmc_project.Control.FanRedundancy"};
1012 dbus::utility::getSubTree(
1013 "/xyz/openbmc_project/control", 2, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001014 [sensorsAsyncResp](
George Liue99073f2022-12-09 11:06:16 +08001015 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001016 const dbus::utility::MapperGetSubTreeResponse& resp) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001017 if (ec)
1018 {
1019 return; // don't have to have this interface
1020 }
George Liu6c3e9452023-03-03 13:55:29 +08001021 for (const std::pair<std::string, dbus::utility::MapperServiceMap>&
Ed Tanous002d39b2022-05-31 08:59:27 -07001022 pathPair : resp)
1023 {
1024 const std::string& path = pathPair.first;
George Liu6c3e9452023-03-03 13:55:29 +08001025 const dbus::utility::MapperServiceMap& objDict = pathPair.second;
Ed Tanous002d39b2022-05-31 08:59:27 -07001026 if (objDict.empty())
James Feist8bd25cc2019-03-15 15:14:00 -07001027 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001028 continue; // this should be impossible
James Feist8bd25cc2019-03-15 15:14:00 -07001029 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001030
1031 const std::string& owner = objDict.begin()->first;
George Liu6c3e9452023-03-03 13:55:29 +08001032 dbus::utility::getAssociationEndPoints(
1033 path + "/chassis",
1034 [path, owner, sensorsAsyncResp](
Ed Tanous8b242752023-06-27 17:17:13 -07001035 const boost::system::error_code& ec2,
George Liu6c3e9452023-03-03 13:55:29 +08001036 const dbus::utility::MapperEndPoints& endpoints) {
Ed Tanous8b242752023-06-27 17:17:13 -07001037 if (ec2)
James Feist8bd25cc2019-03-15 15:14:00 -07001038 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001039 return; // if they don't have an association we
1040 // can't tell what chassis is
James Feist8bd25cc2019-03-15 15:14:00 -07001041 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001042 auto found = std::ranges::find_if(
1043 endpoints, [sensorsAsyncResp](const std::string& entry) {
Patrick Williams5a39f772023-10-20 11:20:21 -05001044 return entry.find(sensorsAsyncResp->chassisId) !=
1045 std::string::npos;
1046 });
James Feist8bd25cc2019-03-15 15:14:00 -07001047
Ed Tanous002d39b2022-05-31 08:59:27 -07001048 if (found == endpoints.end())
1049 {
1050 return;
1051 }
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +02001052 sdbusplus::asio::getAllProperties(
1053 *crow::connections::systemBus, owner, path,
1054 "xyz.openbmc_project.Control.FanRedundancy",
Ed Tanous002d39b2022-05-31 08:59:27 -07001055 [path, sensorsAsyncResp](
Ed Tanous8b242752023-06-27 17:17:13 -07001056 const boost::system::error_code& ec3,
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +02001057 const dbus::utility::DBusPropertiesMap& ret) {
Ed Tanous8b242752023-06-27 17:17:13 -07001058 if (ec3)
Ed Tanous002d39b2022-05-31 08:59:27 -07001059 {
1060 return; // don't have to have this
1061 // interface
1062 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001063
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +02001064 const uint8_t* allowedFailures = nullptr;
1065 const std::vector<std::string>* collection = nullptr;
1066 const std::string* status = nullptr;
1067
1068 const bool success = sdbusplus::unpackPropertiesNoThrow(
1069 dbus_utils::UnpackErrorPrinter(), ret,
1070 "AllowedFailures", allowedFailures, "Collection",
1071 collection, "Status", status);
1072
1073 if (!success)
1074 {
1075 messages::internalError(
1076 sensorsAsyncResp->asyncResp->res);
1077 return;
1078 }
1079
1080 if (allowedFailures == nullptr || collection == nullptr ||
1081 status == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -07001082 {
Ed Tanous62598e32023-07-17 17:06:25 -07001083 BMCWEB_LOG_ERROR("Invalid redundancy interface");
Ed Tanous002d39b2022-05-31 08:59:27 -07001084 messages::internalError(
1085 sensorsAsyncResp->asyncResp->res);
1086 return;
1087 }
1088
Ed Tanous002d39b2022-05-31 08:59:27 -07001089 sdbusplus::message::object_path objectPath(path);
1090 std::string name = objectPath.filename();
1091 if (name.empty())
1092 {
1093 // this should be impossible
1094 messages::internalError(
1095 sensorsAsyncResp->asyncResp->res);
1096 return;
1097 }
Ed Tanous18f8f602023-07-18 10:07:23 -07001098 std::ranges::replace(name, '_', ' ');
Ed Tanous002d39b2022-05-31 08:59:27 -07001099
1100 std::string health;
1101
Ed Tanous11ba3972022-07-11 09:50:41 -07001102 if (status->ends_with("Full"))
Ed Tanous002d39b2022-05-31 08:59:27 -07001103 {
1104 health = "OK";
1105 }
Ed Tanous11ba3972022-07-11 09:50:41 -07001106 else if (status->ends_with("Degraded"))
Ed Tanous002d39b2022-05-31 08:59:27 -07001107 {
1108 health = "Warning";
1109 }
1110 else
1111 {
1112 health = "Critical";
1113 }
1114 nlohmann::json::array_t redfishCollection;
1115 const auto& fanRedfish =
1116 sensorsAsyncResp->asyncResp->res.jsonValue["Fans"];
1117 for (const std::string& item : *collection)
1118 {
Ed Tanous8a592812022-06-04 09:06:59 -07001119 sdbusplus::message::object_path itemPath(item);
1120 std::string itemName = itemPath.filename();
Ed Tanous002d39b2022-05-31 08:59:27 -07001121 if (itemName.empty())
James Feist8bd25cc2019-03-15 15:14:00 -07001122 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001123 continue;
James Feist8bd25cc2019-03-15 15:14:00 -07001124 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001125 /*
1126 todo(ed): merge patch that fixes the names
1127 std::replace(itemName.begin(),
1128 itemName.end(), '_', ' ');*/
Ed Tanous3544d2a2023-08-06 18:12:20 -07001129 auto schemaItem = std::ranges::find_if(
1130 fanRedfish, [itemName](const nlohmann::json& fan) {
Patrick Williams5a39f772023-10-20 11:20:21 -05001131 return fan["Name"] == itemName;
1132 });
Ed Tanous002d39b2022-05-31 08:59:27 -07001133 if (schemaItem != fanRedfish.end())
James Feist8bd25cc2019-03-15 15:14:00 -07001134 {
Ed Tanous8a592812022-06-04 09:06:59 -07001135 nlohmann::json::object_t collectionId;
1136 collectionId["@odata.id"] =
Ed Tanous002d39b2022-05-31 08:59:27 -07001137 (*schemaItem)["@odata.id"];
1138 redfishCollection.emplace_back(
Ed Tanous8a592812022-06-04 09:06:59 -07001139 std::move(collectionId));
Ed Tanous002d39b2022-05-31 08:59:27 -07001140 }
1141 else
1142 {
Ed Tanous62598e32023-07-17 17:06:25 -07001143 BMCWEB_LOG_ERROR("failed to find fan in schema");
Ed Tanous002d39b2022-05-31 08:59:27 -07001144 messages::internalError(
1145 sensorsAsyncResp->asyncResp->res);
James Feist8bd25cc2019-03-15 15:14:00 -07001146 return;
1147 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001148 }
James Feist8bd25cc2019-03-15 15:14:00 -07001149
Patrick Williams89492a12023-05-10 07:51:34 -05001150 size_t minNumNeeded = collection->empty()
1151 ? 0
1152 : collection->size() -
1153 *allowedFailures;
Ed Tanous002d39b2022-05-31 08:59:27 -07001154 nlohmann::json& jResp = sensorsAsyncResp->asyncResp->res
1155 .jsonValue["Redundancy"];
James Feist8bd25cc2019-03-15 15:14:00 -07001156
Ed Tanous002d39b2022-05-31 08:59:27 -07001157 nlohmann::json::object_t redundancy;
Ed Tanousef4c65b2023-04-24 15:28:50 -07001158 boost::urls::url url =
1159 boost::urls::format("/redfish/v1/Chassis/{}/{}",
1160 sensorsAsyncResp->chassisId,
1161 sensorsAsyncResp->chassisSubNode);
Willy Tueddfc432022-09-26 16:46:38 +00001162 url.set_fragment(("/Redundancy"_json_pointer / jResp.size())
1163 .to_string());
1164 redundancy["@odata.id"] = std::move(url);
Ed Tanous002d39b2022-05-31 08:59:27 -07001165 redundancy["@odata.type"] = "#Redundancy.v1_3_2.Redundancy";
1166 redundancy["MinNumNeeded"] = minNumNeeded;
Ed Tanous002d39b2022-05-31 08:59:27 -07001167 redundancy["Mode"] = "N+m";
1168 redundancy["Name"] = name;
1169 redundancy["RedundancySet"] = redfishCollection;
1170 redundancy["Status"]["Health"] = health;
1171 redundancy["Status"]["State"] = "Enabled";
James Feist8bd25cc2019-03-15 15:14:00 -07001172
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001173 jResp.emplace_back(std::move(redundancy));
Ed Tanous002d39b2022-05-31 08:59:27 -07001174 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001175 });
Ed Tanous002d39b2022-05-31 08:59:27 -07001176 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001177 });
James Feist8bd25cc2019-03-15 15:14:00 -07001178}
1179
Ed Tanousb5a76932020-09-29 16:16:58 -07001180inline void
Ed Tanous81ce6092020-12-17 16:54:55 +00001181 sortJSONResponse(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001182{
zhanghch058d1b46d2021-04-01 11:18:24 +08001183 nlohmann::json& response = sensorsAsyncResp->asyncResp->res.jsonValue;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001184 std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"};
Ed Tanous81ce6092020-12-17 16:54:55 +00001185 if (sensorsAsyncResp->chassisSubNode == sensors::node::power)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001186 {
1187 sensorHeaders = {"Voltages", "PowerSupplies"};
1188 }
1189 for (const std::string& sensorGroup : sensorHeaders)
1190 {
1191 nlohmann::json::iterator entry = response.find(sensorGroup);
1192 if (entry != response.end())
1193 {
1194 std::sort(entry->begin(), entry->end(),
Ed Tanous02cad962022-06-30 16:50:15 -07001195 [](const nlohmann::json& c1, const nlohmann::json& c2) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001196 return c1["Name"] < c2["Name"];
1197 });
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001198
1199 // add the index counts to the end of each entry
1200 size_t count = 0;
1201 for (nlohmann::json& sensorJson : *entry)
1202 {
1203 nlohmann::json::iterator odata = sensorJson.find("@odata.id");
1204 if (odata == sensorJson.end())
1205 {
1206 continue;
1207 }
1208 std::string* value = odata->get_ptr<std::string*>();
1209 if (value != nullptr)
1210 {
Willy Tueddfc432022-09-26 16:46:38 +00001211 *value += "/" + std::to_string(count);
George Liu3e35c762023-03-08 16:56:38 +08001212 sensorJson["MemberId"] = std::to_string(count);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001213 count++;
Ed Tanous81ce6092020-12-17 16:54:55 +00001214 sensorsAsyncResp->updateUri(sensorJson["Name"], *value);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001215 }
1216 }
1217 }
1218 }
1219}
1220
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01001221/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001222 * @brief Finds the inventory item with the specified object path.
1223 * @param inventoryItems D-Bus inventory items associated with sensors.
1224 * @param invItemObjPath D-Bus object path of inventory item.
1225 * @return Inventory item within vector, or nullptr if no match found.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001226 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001227inline InventoryItem* findInventoryItem(
Ed Tanousb5a76932020-09-29 16:16:58 -07001228 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001229 const std::string& invItemObjPath)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001230{
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001231 for (InventoryItem& inventoryItem : *inventoryItems)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001232 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001233 if (inventoryItem.objectPath == invItemObjPath)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001234 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001235 return &inventoryItem;
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001236 }
1237 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001238 return nullptr;
1239}
1240
1241/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001242 * @brief Finds the inventory item associated with the specified sensor.
1243 * @param inventoryItems D-Bus inventory items associated with sensors.
1244 * @param sensorObjPath D-Bus object path of sensor.
1245 * @return Inventory item within vector, or nullptr if no match found.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001246 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001247inline InventoryItem* findInventoryItemForSensor(
Ed Tanousb5a76932020-09-29 16:16:58 -07001248 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001249 const std::string& sensorObjPath)
1250{
1251 for (InventoryItem& inventoryItem : *inventoryItems)
1252 {
Ed Tanousdb0d36e2023-06-30 10:37:05 -07001253 if (inventoryItem.sensors.contains(sensorObjPath))
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001254 {
1255 return &inventoryItem;
1256 }
1257 }
1258 return nullptr;
1259}
1260
1261/**
Anthony Wilsond5005492019-07-31 16:34:17 -05001262 * @brief Finds the inventory item associated with the specified led path.
1263 * @param inventoryItems D-Bus inventory items associated with sensors.
1264 * @param ledObjPath D-Bus object path of led.
1265 * @return Inventory item within vector, or nullptr if no match found.
1266 */
1267inline InventoryItem*
1268 findInventoryItemForLed(std::vector<InventoryItem>& inventoryItems,
1269 const std::string& ledObjPath)
1270{
1271 for (InventoryItem& inventoryItem : inventoryItems)
1272 {
1273 if (inventoryItem.ledObjectPath == ledObjPath)
1274 {
1275 return &inventoryItem;
1276 }
1277 }
1278 return nullptr;
1279}
1280
1281/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001282 * @brief Adds inventory item and associated sensor to specified vector.
1283 *
1284 * Adds a new InventoryItem to the vector if necessary. Searches for an
1285 * existing InventoryItem with the specified object path. If not found, one is
1286 * added to the vector.
1287 *
1288 * Next, the specified sensor is added to the set of sensors associated with the
1289 * InventoryItem.
1290 *
1291 * @param inventoryItems D-Bus inventory items associated with sensors.
1292 * @param invItemObjPath D-Bus object path of inventory item.
1293 * @param sensorObjPath D-Bus object path of sensor
1294 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001295inline void addInventoryItem(
1296 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
1297 const std::string& invItemObjPath, const std::string& sensorObjPath)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001298{
1299 // Look for inventory item in vector
Patrick Williams89492a12023-05-10 07:51:34 -05001300 InventoryItem* inventoryItem = findInventoryItem(inventoryItems,
1301 invItemObjPath);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001302
1303 // If inventory item doesn't exist in vector, add it
1304 if (inventoryItem == nullptr)
1305 {
1306 inventoryItems->emplace_back(invItemObjPath);
1307 inventoryItem = &(inventoryItems->back());
1308 }
1309
1310 // Add sensor to set of sensors associated with inventory item
1311 inventoryItem->sensors.emplace(sensorObjPath);
1312}
1313
1314/**
1315 * @brief Stores D-Bus data in the specified inventory item.
1316 *
1317 * Finds D-Bus data in the specified map of interfaces. Stores the data in the
1318 * specified InventoryItem.
1319 *
1320 * This data is later used to provide sensor property values in the JSON
1321 * response.
1322 *
1323 * @param inventoryItem Inventory item where data will be stored.
1324 * @param interfacesDict Map containing D-Bus interfaces and their properties
1325 * for the specified inventory item.
1326 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001327inline void storeInventoryItemData(
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001328 InventoryItem& inventoryItem,
Michael Shen80f79a42023-08-24 13:41:53 +00001329 const dbus::utility::DBusInterfacesMap& interfacesDict)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001330{
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001331 // Get properties from Inventory.Item interface
Ed Tanous711ac7a2021-12-20 09:34:41 -08001332
Ed Tanous9eb808c2022-01-25 10:19:23 -08001333 for (const auto& [interface, values] : interfacesDict)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001334 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001335 if (interface == "xyz.openbmc_project.Inventory.Item")
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001336 {
Ed Tanous9eb808c2022-01-25 10:19:23 -08001337 for (const auto& [name, dbusValue] : values)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001338 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001339 if (name == "Present")
1340 {
1341 const bool* value = std::get_if<bool>(&dbusValue);
1342 if (value != nullptr)
1343 {
1344 inventoryItem.isPresent = *value;
1345 }
1346 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001347 }
1348 }
Ed Tanous711ac7a2021-12-20 09:34:41 -08001349 // Check if Inventory.Item.PowerSupply interface is present
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001350
Ed Tanous711ac7a2021-12-20 09:34:41 -08001351 if (interface == "xyz.openbmc_project.Inventory.Item.PowerSupply")
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001352 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001353 inventoryItem.isPowerSupply = true;
1354 }
1355
1356 // Get properties from Inventory.Decorator.Asset interface
1357 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
1358 {
Ed Tanous9eb808c2022-01-25 10:19:23 -08001359 for (const auto& [name, dbusValue] : values)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001360 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001361 if (name == "Manufacturer")
1362 {
1363 const std::string* value =
1364 std::get_if<std::string>(&dbusValue);
1365 if (value != nullptr)
1366 {
1367 inventoryItem.manufacturer = *value;
1368 }
1369 }
1370 if (name == "Model")
1371 {
1372 const std::string* value =
1373 std::get_if<std::string>(&dbusValue);
1374 if (value != nullptr)
1375 {
1376 inventoryItem.model = *value;
1377 }
1378 }
1379 if (name == "SerialNumber")
1380 {
1381 const std::string* value =
1382 std::get_if<std::string>(&dbusValue);
1383 if (value != nullptr)
1384 {
1385 inventoryItem.serialNumber = *value;
1386 }
1387 }
1388 if (name == "PartNumber")
1389 {
1390 const std::string* value =
1391 std::get_if<std::string>(&dbusValue);
1392 if (value != nullptr)
1393 {
1394 inventoryItem.partNumber = *value;
1395 }
1396 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001397 }
1398 }
1399
Ed Tanous711ac7a2021-12-20 09:34:41 -08001400 if (interface ==
1401 "xyz.openbmc_project.State.Decorator.OperationalStatus")
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001402 {
Ed Tanous9eb808c2022-01-25 10:19:23 -08001403 for (const auto& [name, dbusValue] : values)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001404 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001405 if (name == "Functional")
1406 {
1407 const bool* value = std::get_if<bool>(&dbusValue);
1408 if (value != nullptr)
1409 {
1410 inventoryItem.isFunctional = *value;
1411 }
1412 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001413 }
1414 }
1415 }
1416}
1417
1418/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001419 * @brief Gets D-Bus data for inventory items associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001420 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001421 * Uses the specified connections (services) to obtain D-Bus data for inventory
1422 * items associated with sensors. Stores the resulting data in the
1423 * inventoryItems vector.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001424 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001425 * This data is later used to provide sensor property values in the JSON
1426 * response.
1427 *
1428 * Finds the inventory item data asynchronously. Invokes callback when data has
1429 * been obtained.
1430 *
1431 * The callback must have the following signature:
1432 * @code
Anthony Wilsond5005492019-07-31 16:34:17 -05001433 * callback(void)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001434 * @endcode
1435 *
1436 * This function is called recursively, obtaining data asynchronously from one
1437 * connection in each call. This ensures the callback is not invoked until the
1438 * last asynchronous function has completed.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001439 *
1440 * @param sensorsAsyncResp Pointer to object holding response data.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001441 * @param inventoryItems D-Bus inventory items associated with sensors.
1442 * @param invConnections Connections that provide data for the inventory items.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001443 * implements ObjectManager.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001444 * @param callback Callback to invoke when inventory data has been obtained.
1445 * @param invConnectionsIndex Current index in invConnections. Only specified
1446 * in recursive calls to this function.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001447 */
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001448template <typename Callback>
1449static void getInventoryItemsData(
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001450 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001451 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
Ed Tanousd0090732022-10-04 17:22:56 -07001452 std::shared_ptr<std::set<std::string>> invConnections, Callback&& callback,
1453 size_t invConnectionsIndex = 0)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001454{
Ed Tanous62598e32023-07-17 17:06:25 -07001455 BMCWEB_LOG_DEBUG("getInventoryItemsData enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001456
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001457 // If no more connections left, call callback
1458 if (invConnectionsIndex >= invConnections->size())
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001459 {
Anthony Wilsond5005492019-07-31 16:34:17 -05001460 callback();
Ed Tanous62598e32023-07-17 17:06:25 -07001461 BMCWEB_LOG_DEBUG("getInventoryItemsData exit");
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001462 return;
1463 }
1464
1465 // Get inventory item data from current connection
Nan Zhoufe04d492022-06-22 17:10:41 +00001466 auto it = invConnections->begin();
1467 std::advance(it, invConnectionsIndex);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001468 if (it != invConnections->end())
1469 {
1470 const std::string& invConnection = *it;
1471
George Liu5eb468d2023-06-20 17:03:24 +08001472 // Get all object paths and their interfaces for current connection
1473 sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
1474 dbus::utility::getManagedObjects(
1475 invConnection, path,
1476 [sensorsAsyncResp, inventoryItems, invConnections,
1477 callback{std::forward<Callback>(callback)}, invConnectionsIndex](
1478 const boost::system::error_code& ec,
1479 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous62598e32023-07-17 17:06:25 -07001480 BMCWEB_LOG_DEBUG("getInventoryItemsData respHandler enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001481 if (ec)
1482 {
Ed Tanous62598e32023-07-17 17:06:25 -07001483 BMCWEB_LOG_ERROR(
1484 "getInventoryItemsData respHandler DBus error {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08001485 messages::internalError(sensorsAsyncResp->asyncResp->res);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001486 return;
1487 }
1488
1489 // Loop through returned object paths
1490 for (const auto& objDictEntry : resp)
1491 {
1492 const std::string& objPath =
1493 static_cast<const std::string&>(objDictEntry.first);
1494
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001495 // If this object path is one of the specified inventory items
Patrick Williams89492a12023-05-10 07:51:34 -05001496 InventoryItem* inventoryItem = findInventoryItem(inventoryItems,
1497 objPath);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001498 if (inventoryItem != nullptr)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001499 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001500 // Store inventory data in InventoryItem
1501 storeInventoryItemData(*inventoryItem, objDictEntry.second);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001502 }
1503 }
1504
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001505 // Recurse to get inventory item data from next connection
1506 getInventoryItemsData(sensorsAsyncResp, inventoryItems,
Ed Tanousd0090732022-10-04 17:22:56 -07001507 invConnections, std::move(callback),
1508 invConnectionsIndex + 1);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001509
Ed Tanous62598e32023-07-17 17:06:25 -07001510 BMCWEB_LOG_DEBUG("getInventoryItemsData respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001511 });
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001512 }
1513
Ed Tanous62598e32023-07-17 17:06:25 -07001514 BMCWEB_LOG_DEBUG("getInventoryItemsData exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001515}
1516
1517/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001518 * @brief Gets connections that provide D-Bus data for inventory items.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001519 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001520 * Gets the D-Bus connections (services) that provide data for the inventory
1521 * items that are associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001522 *
1523 * Finds the connections asynchronously. Invokes callback when information has
1524 * been obtained.
1525 *
1526 * The callback must have the following signature:
1527 * @code
Nan Zhoufe04d492022-06-22 17:10:41 +00001528 * callback(std::shared_ptr<std::set<std::string>> invConnections)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001529 * @endcode
1530 *
1531 * @param sensorsAsyncResp Pointer to object holding response data.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001532 * @param inventoryItems D-Bus inventory items associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001533 * @param callback Callback to invoke when connections have been obtained.
1534 */
1535template <typename Callback>
1536static void getInventoryItemsConnections(
Ed Tanousb5a76932020-09-29 16:16:58 -07001537 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
1538 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001539 Callback&& callback)
1540{
Ed Tanous62598e32023-07-17 17:06:25 -07001541 BMCWEB_LOG_DEBUG("getInventoryItemsConnections enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001542
1543 const std::string path = "/xyz/openbmc_project/inventory";
George Liue99073f2022-12-09 11:06:16 +08001544 constexpr std::array<std::string_view, 4> interfaces = {
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001545 "xyz.openbmc_project.Inventory.Item",
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001546 "xyz.openbmc_project.Inventory.Item.PowerSupply",
1547 "xyz.openbmc_project.Inventory.Decorator.Asset",
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001548 "xyz.openbmc_project.State.Decorator.OperationalStatus"};
1549
George Liue99073f2022-12-09 11:06:16 +08001550 // Make call to ObjectMapper to find all inventory items
1551 dbus::utility::getSubTree(
1552 path, 0, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -07001553 [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
1554 inventoryItems](
George Liue99073f2022-12-09 11:06:16 +08001555 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001556 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liue99073f2022-12-09 11:06:16 +08001557 // Response handler for parsing output from GetSubTree
Ed Tanous62598e32023-07-17 17:06:25 -07001558 BMCWEB_LOG_DEBUG("getInventoryItemsConnections respHandler enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001559 if (ec)
1560 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001561 messages::internalError(sensorsAsyncResp->asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07001562 BMCWEB_LOG_ERROR(
1563 "getInventoryItemsConnections respHandler DBus error {}", ec);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001564 return;
1565 }
1566
1567 // Make unique list of connections for desired inventory items
Nan Zhoufe04d492022-06-22 17:10:41 +00001568 std::shared_ptr<std::set<std::string>> invConnections =
1569 std::make_shared<std::set<std::string>>();
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001570
1571 // Loop through objects from GetSubTree
1572 for (const std::pair<
1573 std::string,
1574 std::vector<std::pair<std::string, std::vector<std::string>>>>&
1575 object : subtree)
1576 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001577 // Check if object path is one of the specified inventory items
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001578 const std::string& objPath = object.first;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001579 if (findInventoryItem(inventoryItems, objPath) != nullptr)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001580 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001581 // Store all connections to inventory item
1582 for (const std::pair<std::string, std::vector<std::string>>&
1583 objData : object.second)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001584 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001585 const std::string& invConnection = objData.first;
1586 invConnections->insert(invConnection);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001587 }
1588 }
1589 }
Anthony Wilsond5005492019-07-31 16:34:17 -05001590
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001591 callback(invConnections);
Ed Tanous62598e32023-07-17 17:06:25 -07001592 BMCWEB_LOG_DEBUG("getInventoryItemsConnections respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001593 });
Ed Tanous62598e32023-07-17 17:06:25 -07001594 BMCWEB_LOG_DEBUG("getInventoryItemsConnections exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001595}
1596
1597/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001598 * @brief Gets associations from sensors to inventory items.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001599 *
1600 * Looks for ObjectMapper associations from the specified sensors to related
Anthony Wilsond5005492019-07-31 16:34:17 -05001601 * inventory items. Then finds the associations from those inventory items to
1602 * their LEDs, if any.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001603 *
1604 * Finds the inventory items asynchronously. Invokes callback when information
1605 * has been obtained.
1606 *
1607 * The callback must have the following signature:
1608 * @code
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001609 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001610 * @endcode
1611 *
1612 * @param sensorsAsyncResp Pointer to object holding response data.
1613 * @param sensorNames All sensors within the current chassis.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001614 * implements ObjectManager.
1615 * @param callback Callback to invoke when inventory items have been obtained.
1616 */
1617template <typename Callback>
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001618static void getInventoryItemAssociations(
Ed Tanousb5a76932020-09-29 16:16:58 -07001619 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Nan Zhoufe04d492022-06-22 17:10:41 +00001620 const std::shared_ptr<std::set<std::string>>& sensorNames,
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001621 Callback&& callback)
1622{
Ed Tanous62598e32023-07-17 17:06:25 -07001623 BMCWEB_LOG_DEBUG("getInventoryItemAssociations enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001624
George Liu5eb468d2023-06-20 17:03:24 +08001625 // Call GetManagedObjects on the ObjectMapper to get all associations
1626 sdbusplus::message::object_path path("/");
1627 dbus::utility::getManagedObjects(
1628 "xyz.openbmc_project.ObjectMapper", path,
Ed Tanous02cad962022-06-30 16:50:15 -07001629 [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001630 sensorNames](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -07001631 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous62598e32023-07-17 17:06:25 -07001632 BMCWEB_LOG_DEBUG("getInventoryItemAssociations respHandler enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001633 if (ec)
1634 {
Ed Tanous62598e32023-07-17 17:06:25 -07001635 BMCWEB_LOG_ERROR(
1636 "getInventoryItemAssociations respHandler DBus error {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08001637 messages::internalError(sensorsAsyncResp->asyncResp->res);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001638 return;
1639 }
1640
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001641 // Create vector to hold list of inventory items
1642 std::shared_ptr<std::vector<InventoryItem>> inventoryItems =
1643 std::make_shared<std::vector<InventoryItem>>();
1644
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001645 // Loop through returned object paths
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001646 std::string sensorAssocPath;
1647 sensorAssocPath.reserve(128); // avoid memory allocations
1648 for (const auto& objDictEntry : resp)
1649 {
1650 const std::string& objPath =
1651 static_cast<const std::string&>(objDictEntry.first);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001652
1653 // If path is inventory association for one of the specified sensors
1654 for (const std::string& sensorName : *sensorNames)
1655 {
1656 sensorAssocPath = sensorName;
1657 sensorAssocPath += "/inventory";
1658 if (objPath == sensorAssocPath)
1659 {
1660 // Get Association interface for object path
Ed Tanous711ac7a2021-12-20 09:34:41 -08001661 for (const auto& [interface, values] : objDictEntry.second)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001662 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001663 if (interface == "xyz.openbmc_project.Association")
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001664 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001665 for (const auto& [valueName, value] : values)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001666 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001667 if (valueName == "endpoints")
1668 {
1669 const std::vector<std::string>* endpoints =
1670 std::get_if<std::vector<std::string>>(
1671 &value);
1672 if ((endpoints != nullptr) &&
1673 !endpoints->empty())
1674 {
1675 // Add inventory item to vector
1676 const std::string& invItemPath =
1677 endpoints->front();
1678 addInventoryItem(inventoryItems,
1679 invItemPath,
1680 sensorName);
1681 }
1682 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001683 }
1684 }
1685 }
1686 break;
1687 }
1688 }
1689 }
1690
Anthony Wilsond5005492019-07-31 16:34:17 -05001691 // Now loop through the returned object paths again, this time to
1692 // find the leds associated with the inventory items we just found
1693 std::string inventoryAssocPath;
1694 inventoryAssocPath.reserve(128); // avoid memory allocations
1695 for (const auto& objDictEntry : resp)
1696 {
1697 const std::string& objPath =
1698 static_cast<const std::string&>(objDictEntry.first);
Anthony Wilsond5005492019-07-31 16:34:17 -05001699
1700 for (InventoryItem& inventoryItem : *inventoryItems)
1701 {
1702 inventoryAssocPath = inventoryItem.objectPath;
1703 inventoryAssocPath += "/leds";
1704 if (objPath == inventoryAssocPath)
1705 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001706 for (const auto& [interface, values] : objDictEntry.second)
Anthony Wilsond5005492019-07-31 16:34:17 -05001707 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001708 if (interface == "xyz.openbmc_project.Association")
Anthony Wilsond5005492019-07-31 16:34:17 -05001709 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001710 for (const auto& [valueName, value] : values)
Anthony Wilsond5005492019-07-31 16:34:17 -05001711 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001712 if (valueName == "endpoints")
1713 {
1714 const std::vector<std::string>* endpoints =
1715 std::get_if<std::vector<std::string>>(
1716 &value);
1717 if ((endpoints != nullptr) &&
1718 !endpoints->empty())
1719 {
1720 // Add inventory item to vector
1721 // Store LED path in inventory item
1722 const std::string& ledPath =
1723 endpoints->front();
1724 inventoryItem.ledObjectPath = ledPath;
1725 }
1726 }
Anthony Wilsond5005492019-07-31 16:34:17 -05001727 }
1728 }
1729 }
Ed Tanous711ac7a2021-12-20 09:34:41 -08001730
Anthony Wilsond5005492019-07-31 16:34:17 -05001731 break;
1732 }
1733 }
1734 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001735 callback(inventoryItems);
Ed Tanous62598e32023-07-17 17:06:25 -07001736 BMCWEB_LOG_DEBUG("getInventoryItemAssociations respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001737 });
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001738
Ed Tanous62598e32023-07-17 17:06:25 -07001739 BMCWEB_LOG_DEBUG("getInventoryItemAssociations exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001740}
1741
1742/**
Anthony Wilsond5005492019-07-31 16:34:17 -05001743 * @brief Gets D-Bus data for inventory item leds associated with sensors.
1744 *
1745 * Uses the specified connections (services) to obtain D-Bus data for inventory
1746 * item leds associated with sensors. Stores the resulting data in the
1747 * inventoryItems vector.
1748 *
1749 * This data is later used to provide sensor property values in the JSON
1750 * response.
1751 *
1752 * Finds the inventory item led data asynchronously. Invokes callback when data
1753 * has been obtained.
1754 *
1755 * The callback must have the following signature:
1756 * @code
Gunnar Mills42cbe532019-08-15 15:26:54 -05001757 * callback()
Anthony Wilsond5005492019-07-31 16:34:17 -05001758 * @endcode
1759 *
1760 * This function is called recursively, obtaining data asynchronously from one
1761 * connection in each call. This ensures the callback is not invoked until the
1762 * last asynchronous function has completed.
1763 *
1764 * @param sensorsAsyncResp Pointer to object holding response data.
1765 * @param inventoryItems D-Bus inventory items associated with sensors.
1766 * @param ledConnections Connections that provide data for the inventory leds.
1767 * @param callback Callback to invoke when inventory data has been obtained.
1768 * @param ledConnectionsIndex Current index in ledConnections. Only specified
1769 * in recursive calls to this function.
1770 */
1771template <typename Callback>
1772void getInventoryLedData(
1773 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1774 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
Nan Zhoufe04d492022-06-22 17:10:41 +00001775 std::shared_ptr<std::map<std::string, std::string>> ledConnections,
Anthony Wilsond5005492019-07-31 16:34:17 -05001776 Callback&& callback, size_t ledConnectionsIndex = 0)
1777{
Ed Tanous62598e32023-07-17 17:06:25 -07001778 BMCWEB_LOG_DEBUG("getInventoryLedData enter");
Anthony Wilsond5005492019-07-31 16:34:17 -05001779
1780 // If no more connections left, call callback
1781 if (ledConnectionsIndex >= ledConnections->size())
1782 {
Gunnar Mills42cbe532019-08-15 15:26:54 -05001783 callback();
Ed Tanous62598e32023-07-17 17:06:25 -07001784 BMCWEB_LOG_DEBUG("getInventoryLedData exit");
Anthony Wilsond5005492019-07-31 16:34:17 -05001785 return;
1786 }
1787
1788 // Get inventory item data from current connection
Nan Zhoufe04d492022-06-22 17:10:41 +00001789 auto it = ledConnections->begin();
1790 std::advance(it, ledConnectionsIndex);
Anthony Wilsond5005492019-07-31 16:34:17 -05001791 if (it != ledConnections->end())
1792 {
1793 const std::string& ledPath = (*it).first;
1794 const std::string& ledConnection = (*it).second;
1795 // Response handler for Get State property
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001796 auto respHandler =
1797 [sensorsAsyncResp, inventoryItems, ledConnections, ledPath,
Ed Tanousf94c4ec2022-01-06 12:44:41 -08001798 callback{std::forward<Callback>(callback)}, ledConnectionsIndex](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001799 const boost::system::error_code& ec, const std::string& state) {
Ed Tanous62598e32023-07-17 17:06:25 -07001800 BMCWEB_LOG_DEBUG("getInventoryLedData respHandler enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07001801 if (ec)
1802 {
Ed Tanous62598e32023-07-17 17:06:25 -07001803 BMCWEB_LOG_ERROR(
1804 "getInventoryLedData respHandler DBus error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001805 messages::internalError(sensorsAsyncResp->asyncResp->res);
1806 return;
1807 }
1808
Ed Tanous62598e32023-07-17 17:06:25 -07001809 BMCWEB_LOG_DEBUG("Led state: {}", state);
Ed Tanous002d39b2022-05-31 08:59:27 -07001810 // Find inventory item with this LED object path
1811 InventoryItem* inventoryItem =
1812 findInventoryItemForLed(*inventoryItems, ledPath);
1813 if (inventoryItem != nullptr)
1814 {
1815 // Store LED state in InventoryItem
Ed Tanous11ba3972022-07-11 09:50:41 -07001816 if (state.ends_with("On"))
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001817 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001818 inventoryItem->ledState = LedState::ON;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001819 }
Ed Tanous11ba3972022-07-11 09:50:41 -07001820 else if (state.ends_with("Blink"))
Anthony Wilsond5005492019-07-31 16:34:17 -05001821 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001822 inventoryItem->ledState = LedState::BLINK;
Anthony Wilsond5005492019-07-31 16:34:17 -05001823 }
Ed Tanous11ba3972022-07-11 09:50:41 -07001824 else if (state.ends_with("Off"))
Ed Tanous002d39b2022-05-31 08:59:27 -07001825 {
1826 inventoryItem->ledState = LedState::OFF;
1827 }
1828 else
1829 {
1830 inventoryItem->ledState = LedState::UNKNOWN;
1831 }
1832 }
Anthony Wilsond5005492019-07-31 16:34:17 -05001833
Ed Tanous002d39b2022-05-31 08:59:27 -07001834 // Recurse to get LED data from next connection
1835 getInventoryLedData(sensorsAsyncResp, inventoryItems,
1836 ledConnections, std::move(callback),
1837 ledConnectionsIndex + 1);
Anthony Wilsond5005492019-07-31 16:34:17 -05001838
Ed Tanous62598e32023-07-17 17:06:25 -07001839 BMCWEB_LOG_DEBUG("getInventoryLedData respHandler exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07001840 };
Anthony Wilsond5005492019-07-31 16:34:17 -05001841
1842 // Get the State property for the current LED
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001843 sdbusplus::asio::getProperty<std::string>(
1844 *crow::connections::systemBus, ledConnection, ledPath,
1845 "xyz.openbmc_project.Led.Physical", "State",
1846 std::move(respHandler));
Anthony Wilsond5005492019-07-31 16:34:17 -05001847 }
1848
Ed Tanous62598e32023-07-17 17:06:25 -07001849 BMCWEB_LOG_DEBUG("getInventoryLedData exit");
Anthony Wilsond5005492019-07-31 16:34:17 -05001850}
1851
1852/**
1853 * @brief Gets LED data for LEDs associated with given inventory items.
1854 *
1855 * Gets the D-Bus connections (services) that provide LED data for the LEDs
1856 * associated with the specified inventory items. Then gets the LED data from
1857 * each connection and stores it in the inventory item.
1858 *
1859 * This data is later used to provide sensor property values in the JSON
1860 * response.
1861 *
1862 * Finds the LED data asynchronously. Invokes callback when information has
1863 * been obtained.
1864 *
1865 * The callback must have the following signature:
1866 * @code
Gunnar Mills42cbe532019-08-15 15:26:54 -05001867 * callback()
Anthony Wilsond5005492019-07-31 16:34:17 -05001868 * @endcode
1869 *
1870 * @param sensorsAsyncResp Pointer to object holding response data.
1871 * @param inventoryItems D-Bus inventory items associated with sensors.
1872 * @param callback Callback to invoke when inventory items have been obtained.
1873 */
1874template <typename Callback>
1875void getInventoryLeds(
1876 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1877 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
1878 Callback&& callback)
1879{
Ed Tanous62598e32023-07-17 17:06:25 -07001880 BMCWEB_LOG_DEBUG("getInventoryLeds enter");
Anthony Wilsond5005492019-07-31 16:34:17 -05001881
1882 const std::string path = "/xyz/openbmc_project";
George Liue99073f2022-12-09 11:06:16 +08001883 constexpr std::array<std::string_view, 1> interfaces = {
Anthony Wilsond5005492019-07-31 16:34:17 -05001884 "xyz.openbmc_project.Led.Physical"};
1885
George Liue99073f2022-12-09 11:06:16 +08001886 // Make call to ObjectMapper to find all inventory items
1887 dbus::utility::getSubTree(
1888 path, 0, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -07001889 [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
1890 inventoryItems](
George Liue99073f2022-12-09 11:06:16 +08001891 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001892 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liue99073f2022-12-09 11:06:16 +08001893 // Response handler for parsing output from GetSubTree
Ed Tanous62598e32023-07-17 17:06:25 -07001894 BMCWEB_LOG_DEBUG("getInventoryLeds respHandler enter");
Anthony Wilsond5005492019-07-31 16:34:17 -05001895 if (ec)
1896 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001897 messages::internalError(sensorsAsyncResp->asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07001898 BMCWEB_LOG_ERROR("getInventoryLeds respHandler DBus error {}", ec);
Anthony Wilsond5005492019-07-31 16:34:17 -05001899 return;
1900 }
1901
1902 // Build map of LED object paths to connections
Nan Zhoufe04d492022-06-22 17:10:41 +00001903 std::shared_ptr<std::map<std::string, std::string>> ledConnections =
1904 std::make_shared<std::map<std::string, std::string>>();
Anthony Wilsond5005492019-07-31 16:34:17 -05001905
1906 // Loop through objects from GetSubTree
1907 for (const std::pair<
1908 std::string,
1909 std::vector<std::pair<std::string, std::vector<std::string>>>>&
1910 object : subtree)
1911 {
1912 // Check if object path is LED for one of the specified inventory
1913 // items
1914 const std::string& ledPath = object.first;
1915 if (findInventoryItemForLed(*inventoryItems, ledPath) != nullptr)
1916 {
1917 // Add mapping from ledPath to connection
1918 const std::string& connection = object.second.begin()->first;
1919 (*ledConnections)[ledPath] = connection;
Ed Tanous62598e32023-07-17 17:06:25 -07001920 BMCWEB_LOG_DEBUG("Added mapping {} -> {}", ledPath, connection);
Anthony Wilsond5005492019-07-31 16:34:17 -05001921 }
1922 }
1923
1924 getInventoryLedData(sensorsAsyncResp, inventoryItems, ledConnections,
1925 std::move(callback));
Ed Tanous62598e32023-07-17 17:06:25 -07001926 BMCWEB_LOG_DEBUG("getInventoryLeds respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001927 });
Ed Tanous62598e32023-07-17 17:06:25 -07001928 BMCWEB_LOG_DEBUG("getInventoryLeds exit");
Anthony Wilsond5005492019-07-31 16:34:17 -05001929}
1930
1931/**
Gunnar Mills42cbe532019-08-15 15:26:54 -05001932 * @brief Gets D-Bus data for Power Supply Attributes such as EfficiencyPercent
1933 *
1934 * Uses the specified connections (services) (currently assumes just one) to
1935 * obtain D-Bus data for Power Supply Attributes. Stores the resulting data in
1936 * the inventoryItems vector. Only stores data in Power Supply inventoryItems.
1937 *
1938 * This data is later used to provide sensor property values in the JSON
1939 * response.
1940 *
1941 * Finds the Power Supply Attributes data asynchronously. Invokes callback
1942 * when data has been obtained.
1943 *
1944 * The callback must have the following signature:
1945 * @code
1946 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
1947 * @endcode
1948 *
1949 * @param sensorsAsyncResp Pointer to object holding response data.
1950 * @param inventoryItems D-Bus inventory items associated with sensors.
1951 * @param psAttributesConnections Connections that provide data for the Power
1952 * Supply Attributes
1953 * @param callback Callback to invoke when data has been obtained.
1954 */
1955template <typename Callback>
1956void getPowerSupplyAttributesData(
Ed Tanousb5a76932020-09-29 16:16:58 -07001957 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Gunnar Mills42cbe532019-08-15 15:26:54 -05001958 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
Nan Zhoufe04d492022-06-22 17:10:41 +00001959 const std::map<std::string, std::string>& psAttributesConnections,
Gunnar Mills42cbe532019-08-15 15:26:54 -05001960 Callback&& callback)
1961{
Ed Tanous62598e32023-07-17 17:06:25 -07001962 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05001963
1964 if (psAttributesConnections.empty())
1965 {
Ed Tanous62598e32023-07-17 17:06:25 -07001966 BMCWEB_LOG_DEBUG("Can't find PowerSupplyAttributes, no connections!");
Gunnar Mills42cbe532019-08-15 15:26:54 -05001967 callback(inventoryItems);
1968 return;
1969 }
1970
1971 // Assuming just one connection (service) for now
Nan Zhoufe04d492022-06-22 17:10:41 +00001972 auto it = psAttributesConnections.begin();
Gunnar Mills42cbe532019-08-15 15:26:54 -05001973
1974 const std::string& psAttributesPath = (*it).first;
1975 const std::string& psAttributesConnection = (*it).second;
1976
1977 // Response handler for Get DeratingFactor property
Patrick Williams5a39f772023-10-20 11:20:21 -05001978 auto respHandler = [sensorsAsyncResp, inventoryItems,
1979 callback{std::forward<Callback>(callback)}](
1980 const boost::system::error_code& ec,
1981 const uint32_t value) {
Ed Tanous62598e32023-07-17 17:06:25 -07001982 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData respHandler enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05001983 if (ec)
1984 {
Ed Tanous62598e32023-07-17 17:06:25 -07001985 BMCWEB_LOG_ERROR(
1986 "getPowerSupplyAttributesData respHandler DBus error {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08001987 messages::internalError(sensorsAsyncResp->asyncResp->res);
Gunnar Mills42cbe532019-08-15 15:26:54 -05001988 return;
1989 }
1990
Ed Tanous62598e32023-07-17 17:06:25 -07001991 BMCWEB_LOG_DEBUG("PS EfficiencyPercent value: {}", value);
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001992 // Store value in Power Supply Inventory Items
1993 for (InventoryItem& inventoryItem : *inventoryItems)
Gunnar Mills42cbe532019-08-15 15:26:54 -05001994 {
Ed Tanous55f79e62022-01-25 11:26:16 -08001995 if (inventoryItem.isPowerSupply)
Gunnar Mills42cbe532019-08-15 15:26:54 -05001996 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001997 inventoryItem.powerSupplyEfficiencyPercent =
1998 static_cast<int>(value);
Gunnar Mills42cbe532019-08-15 15:26:54 -05001999 }
2000 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002001
Ed Tanous62598e32023-07-17 17:06:25 -07002002 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData respHandler exit");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002003 callback(inventoryItems);
2004 };
2005
2006 // Get the DeratingFactor property for the PowerSupplyAttributes
2007 // Currently only property on the interface/only one we care about
Jonathan Doman1e1e5982021-06-11 09:36:17 -07002008 sdbusplus::asio::getProperty<uint32_t>(
2009 *crow::connections::systemBus, psAttributesConnection, psAttributesPath,
2010 "xyz.openbmc_project.Control.PowerSupplyAttributes", "DeratingFactor",
2011 std::move(respHandler));
Gunnar Mills42cbe532019-08-15 15:26:54 -05002012
Ed Tanous62598e32023-07-17 17:06:25 -07002013 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData exit");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002014}
2015
2016/**
2017 * @brief Gets the Power Supply Attributes such as EfficiencyPercent
2018 *
2019 * Gets the D-Bus connection (service) that provides Power Supply Attributes
2020 * data. Then gets the Power Supply Attributes data from the connection
2021 * (currently just assumes 1 connection) and stores the data in the inventory
2022 * item.
2023 *
2024 * This data is later used to provide sensor property values in the JSON
2025 * response. DeratingFactor on D-Bus is mapped to EfficiencyPercent on Redfish.
2026 *
2027 * Finds the Power Supply Attributes data asynchronously. Invokes callback
2028 * when information has been obtained.
2029 *
2030 * The callback must have the following signature:
2031 * @code
2032 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
2033 * @endcode
2034 *
2035 * @param sensorsAsyncResp Pointer to object holding response data.
2036 * @param inventoryItems D-Bus inventory items associated with sensors.
2037 * @param callback Callback to invoke when data has been obtained.
2038 */
2039template <typename Callback>
2040void getPowerSupplyAttributes(
2041 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
2042 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
2043 Callback&& callback)
2044{
Ed Tanous62598e32023-07-17 17:06:25 -07002045 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002046
2047 // Only need the power supply attributes when the Power Schema
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002048 if (sensorsAsyncResp->chassisSubNode != sensors::node::power)
Gunnar Mills42cbe532019-08-15 15:26:54 -05002049 {
Ed Tanous62598e32023-07-17 17:06:25 -07002050 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes exit since not Power");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002051 callback(inventoryItems);
2052 return;
2053 }
2054
George Liue99073f2022-12-09 11:06:16 +08002055 constexpr std::array<std::string_view, 1> interfaces = {
Gunnar Mills42cbe532019-08-15 15:26:54 -05002056 "xyz.openbmc_project.Control.PowerSupplyAttributes"};
2057
George Liue99073f2022-12-09 11:06:16 +08002058 // Make call to ObjectMapper to find the PowerSupplyAttributes service
2059 dbus::utility::getSubTree(
2060 "/xyz/openbmc_project", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002061 [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
2062 inventoryItems](
George Liue99073f2022-12-09 11:06:16 +08002063 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002064 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liue99073f2022-12-09 11:06:16 +08002065 // Response handler for parsing output from GetSubTree
Ed Tanous62598e32023-07-17 17:06:25 -07002066 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes respHandler enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002067 if (ec)
2068 {
2069 messages::internalError(sensorsAsyncResp->asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07002070 BMCWEB_LOG_ERROR(
2071 "getPowerSupplyAttributes respHandler DBus error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07002072 return;
2073 }
2074 if (subtree.empty())
2075 {
Ed Tanous62598e32023-07-17 17:06:25 -07002076 BMCWEB_LOG_DEBUG("Can't find Power Supply Attributes!");
Ed Tanous002d39b2022-05-31 08:59:27 -07002077 callback(inventoryItems);
2078 return;
2079 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002080
Ed Tanous002d39b2022-05-31 08:59:27 -07002081 // Currently we only support 1 power supply attribute, use this for
2082 // all the power supplies. Build map of object path to connection.
2083 // Assume just 1 connection and 1 path for now.
Nan Zhoufe04d492022-06-22 17:10:41 +00002084 std::map<std::string, std::string> psAttributesConnections;
Gunnar Mills42cbe532019-08-15 15:26:54 -05002085
Ed Tanous002d39b2022-05-31 08:59:27 -07002086 if (subtree[0].first.empty() || subtree[0].second.empty())
2087 {
Ed Tanous62598e32023-07-17 17:06:25 -07002088 BMCWEB_LOG_DEBUG("Power Supply Attributes mapper error!");
Ed Tanous002d39b2022-05-31 08:59:27 -07002089 callback(inventoryItems);
2090 return;
2091 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002092
Ed Tanous002d39b2022-05-31 08:59:27 -07002093 const std::string& psAttributesPath = subtree[0].first;
2094 const std::string& connection = subtree[0].second.begin()->first;
Gunnar Mills42cbe532019-08-15 15:26:54 -05002095
Ed Tanous002d39b2022-05-31 08:59:27 -07002096 if (connection.empty())
2097 {
Ed Tanous62598e32023-07-17 17:06:25 -07002098 BMCWEB_LOG_DEBUG("Power Supply Attributes mapper error!");
Ed Tanous002d39b2022-05-31 08:59:27 -07002099 callback(inventoryItems);
2100 return;
2101 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002102
Ed Tanous002d39b2022-05-31 08:59:27 -07002103 psAttributesConnections[psAttributesPath] = connection;
Ed Tanous62598e32023-07-17 17:06:25 -07002104 BMCWEB_LOG_DEBUG("Added mapping {} -> {}", psAttributesPath,
2105 connection);
Gunnar Mills42cbe532019-08-15 15:26:54 -05002106
Ed Tanous002d39b2022-05-31 08:59:27 -07002107 getPowerSupplyAttributesData(sensorsAsyncResp, inventoryItems,
2108 psAttributesConnections,
2109 std::move(callback));
Ed Tanous62598e32023-07-17 17:06:25 -07002110 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05002111 });
Ed Tanous62598e32023-07-17 17:06:25 -07002112 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes exit");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002113}
2114
2115/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002116 * @brief Gets inventory items associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002117 *
2118 * Finds the inventory items that are associated with the specified sensors.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002119 * Then gets D-Bus data for the inventory items, such as presence and VPD.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002120 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002121 * This data is later used to provide sensor property values in the JSON
2122 * response.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002123 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002124 * Finds the inventory items asynchronously. Invokes callback when the
2125 * inventory items have been obtained.
2126 *
2127 * The callback must have the following signature:
2128 * @code
2129 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
2130 * @endcode
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002131 *
2132 * @param sensorsAsyncResp Pointer to object holding response data.
2133 * @param sensorNames All sensors within the current chassis.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002134 * implements ObjectManager.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002135 * @param callback Callback to invoke when inventory items have been obtained.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002136 */
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002137template <typename Callback>
Ed Tanousd0090732022-10-04 17:22:56 -07002138static void
2139 getInventoryItems(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
2140 const std::shared_ptr<std::set<std::string>> sensorNames,
2141 Callback&& callback)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002142{
Ed Tanous62598e32023-07-17 17:06:25 -07002143 BMCWEB_LOG_DEBUG("getInventoryItems enter");
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002144 auto getInventoryItemAssociationsCb =
Ed Tanousd0090732022-10-04 17:22:56 -07002145 [sensorsAsyncResp, callback{std::forward<Callback>(callback)}](
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002146 std::shared_ptr<std::vector<InventoryItem>> inventoryItems) {
Ed Tanous62598e32023-07-17 17:06:25 -07002147 BMCWEB_LOG_DEBUG("getInventoryItemAssociationsCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002148 auto getInventoryItemsConnectionsCb =
Ed Tanousd0090732022-10-04 17:22:56 -07002149 [sensorsAsyncResp, inventoryItems,
Ed Tanous002d39b2022-05-31 08:59:27 -07002150 callback{std::forward<const Callback>(callback)}](
Nan Zhoufe04d492022-06-22 17:10:41 +00002151 std::shared_ptr<std::set<std::string>> invConnections) {
Ed Tanous62598e32023-07-17 17:06:25 -07002152 BMCWEB_LOG_DEBUG("getInventoryItemsConnectionsCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002153 auto getInventoryItemsDataCb = [sensorsAsyncResp, inventoryItems,
2154 callback{std::move(callback)}]() {
Ed Tanous62598e32023-07-17 17:06:25 -07002155 BMCWEB_LOG_DEBUG("getInventoryItemsDataCb enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002156
Ed Tanous002d39b2022-05-31 08:59:27 -07002157 auto getInventoryLedsCb = [sensorsAsyncResp, inventoryItems,
2158 callback{std::move(callback)}]() {
Ed Tanous62598e32023-07-17 17:06:25 -07002159 BMCWEB_LOG_DEBUG("getInventoryLedsCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002160 // Find Power Supply Attributes and get the data
2161 getPowerSupplyAttributes(sensorsAsyncResp, inventoryItems,
2162 std::move(callback));
Ed Tanous62598e32023-07-17 17:06:25 -07002163 BMCWEB_LOG_DEBUG("getInventoryLedsCb exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002164 };
2165
Ed Tanous002d39b2022-05-31 08:59:27 -07002166 // Find led connections and get the data
2167 getInventoryLeds(sensorsAsyncResp, inventoryItems,
2168 std::move(getInventoryLedsCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002169 BMCWEB_LOG_DEBUG("getInventoryItemsDataCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002170 };
2171
2172 // Get inventory item data from connections
2173 getInventoryItemsData(sensorsAsyncResp, inventoryItems,
Ed Tanousd0090732022-10-04 17:22:56 -07002174 invConnections,
Ed Tanous002d39b2022-05-31 08:59:27 -07002175 std::move(getInventoryItemsDataCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002176 BMCWEB_LOG_DEBUG("getInventoryItemsConnectionsCb exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002177 };
2178
Ed Tanous002d39b2022-05-31 08:59:27 -07002179 // Get connections that provide inventory item data
2180 getInventoryItemsConnections(sensorsAsyncResp, inventoryItems,
2181 std::move(getInventoryItemsConnectionsCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002182 BMCWEB_LOG_DEBUG("getInventoryItemAssociationsCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002183 };
2184
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002185 // Get associations from sensors to inventory items
Ed Tanousd0090732022-10-04 17:22:56 -07002186 getInventoryItemAssociations(sensorsAsyncResp, sensorNames,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002187 std::move(getInventoryItemAssociationsCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002188 BMCWEB_LOG_DEBUG("getInventoryItems exit");
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002189}
2190
2191/**
2192 * @brief Returns JSON PowerSupply object for the specified inventory item.
2193 *
2194 * Searches for a JSON PowerSupply object that matches the specified inventory
2195 * item. If one is not found, a new PowerSupply object is added to the JSON
2196 * array.
2197 *
2198 * Multiple sensors are often associated with one power supply inventory item.
2199 * As a result, multiple sensor values are stored in one JSON PowerSupply
2200 * object.
2201 *
2202 * @param powerSupplyArray JSON array containing Redfish PowerSupply objects.
2203 * @param inventoryItem Inventory item for the power supply.
2204 * @param chassisId Chassis that contains the power supply.
2205 * @return JSON PowerSupply object for the specified inventory item.
2206 */
Ed Tanous23a21a12020-07-25 04:45:05 +00002207inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002208 const InventoryItem& inventoryItem,
2209 const std::string& chassisId)
2210{
Ed Tanous18f8f602023-07-18 10:07:23 -07002211 std::string nameS;
Alexander Hansen6f4bd292024-03-08 17:04:54 +01002212 nameS.resize(inventoryItem.name.size());
Ed Tanous18f8f602023-07-18 10:07:23 -07002213 std::ranges::replace_copy(inventoryItem.name, nameS.begin(), '_', ' ');
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002214 // Check if matching PowerSupply object already exists in JSON array
2215 for (nlohmann::json& powerSupply : powerSupplyArray)
2216 {
Ed Tanous18f8f602023-07-18 10:07:23 -07002217 nlohmann::json::iterator nameIt = powerSupply.find("Name");
2218 if (nameIt == powerSupply.end())
2219 {
2220 continue;
2221 }
2222 const std::string* name = nameIt->get_ptr<std::string*>();
2223 if (name == nullptr)
2224 {
2225 continue;
2226 }
2227 if (nameS == *name)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002228 {
2229 return powerSupply;
2230 }
2231 }
2232
2233 // Add new PowerSupply object to JSON array
2234 powerSupplyArray.push_back({});
2235 nlohmann::json& powerSupply = powerSupplyArray.back();
Ed Tanousef4c65b2023-04-24 15:28:50 -07002236 boost::urls::url url = boost::urls::format("/redfish/v1/Chassis/{}/Power",
2237 chassisId);
Willy Tueddfc432022-09-26 16:46:38 +00002238 url.set_fragment(("/PowerSupplies"_json_pointer).to_string());
2239 powerSupply["@odata.id"] = std::move(url);
Ed Tanous18f8f602023-07-18 10:07:23 -07002240 std::string escaped;
Alexander Hansen6f4bd292024-03-08 17:04:54 +01002241 escaped.resize(inventoryItem.name.size());
Ed Tanous18f8f602023-07-18 10:07:23 -07002242 std::ranges::replace_copy(inventoryItem.name, escaped.begin(), '_', ' ');
2243 powerSupply["Name"] = std::move(escaped);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002244 powerSupply["Manufacturer"] = inventoryItem.manufacturer;
2245 powerSupply["Model"] = inventoryItem.model;
2246 powerSupply["PartNumber"] = inventoryItem.partNumber;
2247 powerSupply["SerialNumber"] = inventoryItem.serialNumber;
Anthony Wilsond5005492019-07-31 16:34:17 -05002248 setLedState(powerSupply, &inventoryItem);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002249
Gunnar Mills42cbe532019-08-15 15:26:54 -05002250 if (inventoryItem.powerSupplyEfficiencyPercent >= 0)
2251 {
2252 powerSupply["EfficiencyPercent"] =
2253 inventoryItem.powerSupplyEfficiencyPercent;
2254 }
2255
Matt Simmeringaaf08ac2023-10-04 08:41:01 -07002256 powerSupply["Status"]["State"] = getState(&inventoryItem, true);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002257 const char* health = inventoryItem.isFunctional ? "OK" : "Critical";
2258 powerSupply["Status"]["Health"] = health;
2259
2260 return powerSupply;
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002261}
2262
2263/**
Shawn McCarneyde629b62019-03-08 10:42:51 -06002264 * @brief Gets the values of the specified sensors.
2265 *
2266 * Stores the results as JSON in the SensorsAsyncResp.
2267 *
2268 * Gets the sensor values asynchronously. Stores the results later when the
2269 * information has been obtained.
2270 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002271 * The sensorNames set contains all requested sensors for the current chassis.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002272 *
2273 * To minimize the number of DBus calls, the DBus method
2274 * org.freedesktop.DBus.ObjectManager.GetManagedObjects() is used to get the
2275 * values of all sensors provided by a connection (service).
2276 *
2277 * The connections set contains all the connections that provide sensor values.
2278 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002279 * The InventoryItem vector contains D-Bus inventory items associated with the
2280 * sensors. Inventory item data is needed for some Redfish sensor properties.
2281 *
Shawn McCarneyde629b62019-03-08 10:42:51 -06002282 * @param SensorsAsyncResp Pointer to object holding response data.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002283 * @param sensorNames All requested sensors within the current chassis.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002284 * @param connections Connections that provide sensor values.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002285 * implements ObjectManager.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002286 * @param inventoryItems Inventory items associated with the sensors.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002287 */
Ed Tanous23a21a12020-07-25 04:45:05 +00002288inline void getSensorData(
Ed Tanous81ce6092020-12-17 16:54:55 +00002289 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Nan Zhoufe04d492022-06-22 17:10:41 +00002290 const std::shared_ptr<std::set<std::string>>& sensorNames,
2291 const std::set<std::string>& connections,
Ed Tanousb5a76932020-09-29 16:16:58 -07002292 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems)
Shawn McCarneyde629b62019-03-08 10:42:51 -06002293{
Ed Tanous62598e32023-07-17 17:06:25 -07002294 BMCWEB_LOG_DEBUG("getSensorData enter");
Shawn McCarneyde629b62019-03-08 10:42:51 -06002295 // Get managed objects from all services exposing sensors
2296 for (const std::string& connection : connections)
2297 {
George Liu5eb468d2023-06-20 17:03:24 +08002298 sdbusplus::message::object_path sensorPath(
2299 "/xyz/openbmc_project/sensors");
2300 dbus::utility::getManagedObjects(
2301 connection, sensorPath,
Ed Tanous002d39b2022-05-31 08:59:27 -07002302 [sensorsAsyncResp, sensorNames,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002303 inventoryItems](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -07002304 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous62598e32023-07-17 17:06:25 -07002305 BMCWEB_LOG_DEBUG("getManagedObjectsCb enter");
Shawn McCarneyde629b62019-03-08 10:42:51 -06002306 if (ec)
2307 {
Ed Tanous62598e32023-07-17 17:06:25 -07002308 BMCWEB_LOG_ERROR("getManagedObjectsCb DBUS error: {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08002309 messages::internalError(sensorsAsyncResp->asyncResp->res);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002310 return;
2311 }
2312 // Go through all objects and update response with sensor data
2313 for (const auto& objDictEntry : resp)
2314 {
2315 const std::string& objPath =
2316 static_cast<const std::string&>(objDictEntry.first);
Ed Tanous62598e32023-07-17 17:06:25 -07002317 BMCWEB_LOG_DEBUG("getManagedObjectsCb parsing object {}",
2318 objPath);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002319
Shawn McCarneyde629b62019-03-08 10:42:51 -06002320 std::vector<std::string> split;
2321 // Reserve space for
2322 // /xyz/openbmc_project/sensors/<name>/<subname>
2323 split.reserve(6);
Ed Tanous50ebd4a2023-01-19 19:03:17 -08002324 // NOLINTNEXTLINE
2325 bmcweb::split(split, objPath, '/');
Shawn McCarneyde629b62019-03-08 10:42:51 -06002326 if (split.size() < 6)
2327 {
Ed Tanous62598e32023-07-17 17:06:25 -07002328 BMCWEB_LOG_ERROR("Got path that isn't long enough {}",
2329 objPath);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002330 continue;
2331 }
Ed Tanous50ebd4a2023-01-19 19:03:17 -08002332 // These indexes aren't intuitive, as split puts an empty
Shawn McCarneyde629b62019-03-08 10:42:51 -06002333 // string at the beginning
2334 const std::string& sensorType = split[4];
2335 const std::string& sensorName = split[5];
Ed Tanous62598e32023-07-17 17:06:25 -07002336 BMCWEB_LOG_DEBUG("sensorName {} sensorType {}", sensorName,
2337 sensorType);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002338 if (sensorNames->find(objPath) == sensorNames->end())
Shawn McCarneyde629b62019-03-08 10:42:51 -06002339 {
Ed Tanous62598e32023-07-17 17:06:25 -07002340 BMCWEB_LOG_DEBUG("{} not in sensor list ", sensorName);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002341 continue;
2342 }
2343
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002344 // Find inventory item (if any) associated with sensor
2345 InventoryItem* inventoryItem =
2346 findInventoryItemForSensor(inventoryItems, objPath);
2347
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002348 const std::string& sensorSchema =
Ed Tanous81ce6092020-12-17 16:54:55 +00002349 sensorsAsyncResp->chassisSubNode;
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002350
2351 nlohmann::json* sensorJson = nullptr;
2352
Nan Zhou928fefb2022-03-28 08:45:00 -07002353 if (sensorSchema == sensors::node::sensors &&
2354 !sensorsAsyncResp->efficientExpand)
Shawn McCarneyde629b62019-03-08 10:42:51 -06002355 {
Ed Tanousc1d019a2022-08-06 09:36:06 -07002356 std::string sensorTypeEscaped(sensorType);
Ed Tanous3544d2a2023-08-06 18:12:20 -07002357 auto remove = std::ranges::remove(sensorTypeEscaped, '_');
2358
2359 sensorTypeEscaped.erase(std::ranges::begin(remove),
2360 sensorTypeEscaped.end());
Ed Tanousc1d019a2022-08-06 09:36:06 -07002361 std::string sensorId(sensorTypeEscaped);
2362 sensorId += "_";
2363 sensorId += sensorName;
2364
zhanghch058d1b46d2021-04-01 11:18:24 +08002365 sensorsAsyncResp->asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -07002366 boost::urls::format("/redfish/v1/Chassis/{}/{}/{}",
2367 sensorsAsyncResp->chassisId,
2368 sensorsAsyncResp->chassisSubNode,
2369 sensorId);
zhanghch058d1b46d2021-04-01 11:18:24 +08002370 sensorJson = &(sensorsAsyncResp->asyncResp->res.jsonValue);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002371 }
2372 else
2373 {
Ed Tanous271584a2019-07-09 16:24:22 -07002374 std::string fieldName;
Nan Zhou928fefb2022-03-28 08:45:00 -07002375 if (sensorsAsyncResp->efficientExpand)
2376 {
2377 fieldName = "Members";
2378 }
2379 else if (sensorType == "temperature")
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002380 {
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002381 fieldName = "Temperatures";
2382 }
2383 else if (sensorType == "fan" || sensorType == "fan_tach" ||
2384 sensorType == "fan_pwm")
2385 {
2386 fieldName = "Fans";
2387 }
2388 else if (sensorType == "voltage")
2389 {
2390 fieldName = "Voltages";
2391 }
2392 else if (sensorType == "power")
2393 {
Ed Tanous55f79e62022-01-25 11:26:16 -08002394 if (sensorName == "total_power")
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002395 {
2396 fieldName = "PowerControl";
2397 }
2398 else if ((inventoryItem != nullptr) &&
2399 (inventoryItem->isPowerSupply))
2400 {
2401 fieldName = "PowerSupplies";
2402 }
2403 else
2404 {
2405 // Other power sensors are in SensorCollection
2406 continue;
2407 }
2408 }
2409 else
2410 {
Ed Tanous62598e32023-07-17 17:06:25 -07002411 BMCWEB_LOG_ERROR("Unsure how to handle sensorType {}",
2412 sensorType);
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002413 continue;
2414 }
2415
2416 nlohmann::json& tempArray =
zhanghch058d1b46d2021-04-01 11:18:24 +08002417 sensorsAsyncResp->asyncResp->res.jsonValue[fieldName];
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002418 if (fieldName == "PowerControl")
2419 {
2420 if (tempArray.empty())
2421 {
2422 // Put multiple "sensors" into a single
2423 // PowerControl. Follows MemberId naming and
2424 // naming in power.hpp.
Ed Tanous14766872022-03-15 10:44:42 -07002425 nlohmann::json::object_t power;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002426 boost::urls::url url = boost::urls::format(
2427 "/redfish/v1/Chassis/{}/{}",
Willy Tueddfc432022-09-26 16:46:38 +00002428 sensorsAsyncResp->chassisId,
2429 sensorsAsyncResp->chassisSubNode);
2430 url.set_fragment((""_json_pointer / fieldName / "0")
2431 .to_string());
2432 power["@odata.id"] = std::move(url);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002433 tempArray.emplace_back(std::move(power));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002434 }
2435 sensorJson = &(tempArray.back());
2436 }
2437 else if (fieldName == "PowerSupplies")
2438 {
2439 if (inventoryItem != nullptr)
2440 {
2441 sensorJson =
2442 &(getPowerSupply(tempArray, *inventoryItem,
Ed Tanous81ce6092020-12-17 16:54:55 +00002443 sensorsAsyncResp->chassisId));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002444 }
2445 }
Nan Zhou928fefb2022-03-28 08:45:00 -07002446 else if (fieldName == "Members")
2447 {
Ed Tanous677bb752022-09-15 10:52:19 -07002448 std::string sensorTypeEscaped(sensorType);
Ed Tanous3544d2a2023-08-06 18:12:20 -07002449 auto remove = std::ranges::remove(sensorTypeEscaped,
2450 '_');
2451 sensorTypeEscaped.erase(std::ranges::begin(remove),
2452 sensorTypeEscaped.end());
Ed Tanous677bb752022-09-15 10:52:19 -07002453 std::string sensorId(sensorTypeEscaped);
2454 sensorId += "_";
2455 sensorId += sensorName;
2456
Ed Tanous14766872022-03-15 10:44:42 -07002457 nlohmann::json::object_t member;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002458 member["@odata.id"] = boost::urls::format(
2459 "/redfish/v1/Chassis/{}/{}/{}",
Ed Tanous677bb752022-09-15 10:52:19 -07002460 sensorsAsyncResp->chassisId,
2461 sensorsAsyncResp->chassisSubNode, sensorId);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002462 tempArray.emplace_back(std::move(member));
Nan Zhou928fefb2022-03-28 08:45:00 -07002463 sensorJson = &(tempArray.back());
2464 }
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002465 else
2466 {
Ed Tanous14766872022-03-15 10:44:42 -07002467 nlohmann::json::object_t member;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002468 boost::urls::url url = boost::urls::format(
2469 "/redfish/v1/Chassis/{}/{}",
Willy Tueddfc432022-09-26 16:46:38 +00002470 sensorsAsyncResp->chassisId,
2471 sensorsAsyncResp->chassisSubNode);
2472 url.set_fragment(
2473 (""_json_pointer / fieldName).to_string());
2474 member["@odata.id"] = std::move(url);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002475 tempArray.emplace_back(std::move(member));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002476 sensorJson = &(tempArray.back());
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002477 }
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002478 }
Shawn McCarneyde629b62019-03-08 10:42:51 -06002479
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002480 if (sensorJson != nullptr)
2481 {
Ed Tanous1d7c0052022-08-09 12:32:26 -07002482 objectInterfacesToJson(sensorName, sensorType,
2483 sensorsAsyncResp->chassisSubNode,
2484 objDictEntry.second, *sensorJson,
2485 inventoryItem);
2486
2487 std::string path = "/xyz/openbmc_project/sensors/";
2488 path += sensorType;
2489 path += "/";
2490 path += sensorName;
Ed Tanousc1d019a2022-08-06 09:36:06 -07002491 sensorsAsyncResp->addMetadata(*sensorJson, path);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002492 }
Shawn McCarneyde629b62019-03-08 10:42:51 -06002493 }
Ed Tanous81ce6092020-12-17 16:54:55 +00002494 if (sensorsAsyncResp.use_count() == 1)
James Feist8bd25cc2019-03-15 15:14:00 -07002495 {
Ed Tanous81ce6092020-12-17 16:54:55 +00002496 sortJSONResponse(sensorsAsyncResp);
Nan Zhou928fefb2022-03-28 08:45:00 -07002497 if (sensorsAsyncResp->chassisSubNode ==
2498 sensors::node::sensors &&
2499 sensorsAsyncResp->efficientExpand)
2500 {
2501 sensorsAsyncResp->asyncResp->res
2502 .jsonValue["Members@odata.count"] =
2503 sensorsAsyncResp->asyncResp->res.jsonValue["Members"]
2504 .size();
2505 }
2506 else if (sensorsAsyncResp->chassisSubNode ==
2507 sensors::node::thermal)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002508 {
Ed Tanous81ce6092020-12-17 16:54:55 +00002509 populateFanRedundancy(sensorsAsyncResp);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002510 }
James Feist8bd25cc2019-03-15 15:14:00 -07002511 }
Ed Tanous62598e32023-07-17 17:06:25 -07002512 BMCWEB_LOG_DEBUG("getManagedObjectsCb exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05002513 });
Ed Tanous23a21a12020-07-25 04:45:05 +00002514 }
Ed Tanous62598e32023-07-17 17:06:25 -07002515 BMCWEB_LOG_DEBUG("getSensorData exit");
Shawn McCarneyde629b62019-03-08 10:42:51 -06002516}
2517
Nan Zhoufe04d492022-06-22 17:10:41 +00002518inline void
2519 processSensorList(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
2520 const std::shared_ptr<std::set<std::string>>& sensorNames)
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002521{
Nan Zhoufe04d492022-06-22 17:10:41 +00002522 auto getConnectionCb = [sensorsAsyncResp, sensorNames](
2523 const std::set<std::string>& connections) {
Ed Tanous62598e32023-07-17 17:06:25 -07002524 BMCWEB_LOG_DEBUG("getConnectionCb enter");
Ed Tanousd0090732022-10-04 17:22:56 -07002525 auto getInventoryItemsCb =
2526 [sensorsAsyncResp, sensorNames,
2527 connections](const std::shared_ptr<std::vector<InventoryItem>>&
2528 inventoryItems) {
Ed Tanous62598e32023-07-17 17:06:25 -07002529 BMCWEB_LOG_DEBUG("getInventoryItemsCb enter");
Ed Tanousd0090732022-10-04 17:22:56 -07002530 // Get sensor data and store results in JSON
2531 getSensorData(sensorsAsyncResp, sensorNames, connections,
2532 inventoryItems);
Ed Tanous62598e32023-07-17 17:06:25 -07002533 BMCWEB_LOG_DEBUG("getInventoryItemsCb exit");
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002534 };
2535
Ed Tanousd0090732022-10-04 17:22:56 -07002536 // Get inventory items associated with sensors
2537 getInventoryItems(sensorsAsyncResp, sensorNames,
2538 std::move(getInventoryItemsCb));
2539
Ed Tanous62598e32023-07-17 17:06:25 -07002540 BMCWEB_LOG_DEBUG("getConnectionCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002541 };
2542
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002543 // Get set of connections that provide sensor values
Ed Tanous81ce6092020-12-17 16:54:55 +00002544 getConnections(sensorsAsyncResp, sensorNames, std::move(getConnectionCb));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002545}
2546
Shawn McCarneyde629b62019-03-08 10:42:51 -06002547/**
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01002548 * @brief Entry point for retrieving sensors data related to requested
2549 * chassis.
Kowalski, Kamil588c3f02018-04-03 14:55:27 +02002550 * @param SensorsAsyncResp Pointer to object holding response data
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01002551 */
Ed Tanousb5a76932020-09-29 16:16:58 -07002552inline void
Ed Tanous81ce6092020-12-17 16:54:55 +00002553 getChassisData(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07002554{
Ed Tanous62598e32023-07-17 17:06:25 -07002555 BMCWEB_LOG_DEBUG("getChassisData enter");
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002556 auto getChassisCb =
Ed Tanous81ce6092020-12-17 16:54:55 +00002557 [sensorsAsyncResp](
Nan Zhoufe04d492022-06-22 17:10:41 +00002558 const std::shared_ptr<std::set<std::string>>& sensorNames) {
Ed Tanous62598e32023-07-17 17:06:25 -07002559 BMCWEB_LOG_DEBUG("getChassisCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002560 processSensorList(sensorsAsyncResp, sensorNames);
Ed Tanous62598e32023-07-17 17:06:25 -07002561 BMCWEB_LOG_DEBUG("getChassisCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002562 };
Nan Zhou928fefb2022-03-28 08:45:00 -07002563 // SensorCollection doesn't contain the Redundancy property
2564 if (sensorsAsyncResp->chassisSubNode != sensors::node::sensors)
2565 {
2566 sensorsAsyncResp->asyncResp->res.jsonValue["Redundancy"] =
2567 nlohmann::json::array();
2568 }
Shawn McCarney26f03892019-05-03 13:20:24 -05002569 // Get set of sensors in chassis
Ed Tanous7f1cc262022-08-09 13:33:57 -07002570 getChassis(sensorsAsyncResp->asyncResp, sensorsAsyncResp->chassisId,
2571 sensorsAsyncResp->chassisSubNode, sensorsAsyncResp->types,
2572 std::move(getChassisCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002573 BMCWEB_LOG_DEBUG("getChassisData exit");
Ed Tanous271584a2019-07-09 16:24:22 -07002574}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01002575
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302576/**
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002577 * @brief Find the requested sensorName in the list of all sensors supplied by
2578 * the chassis node
2579 *
2580 * @param sensorName The sensor name supplied in the PATCH request
2581 * @param sensorsList The list of sensors managed by the chassis node
2582 * @param sensorsModified The list of sensors that were found as a result of
2583 * repeated calls to this function
2584 */
Nan Zhoufe04d492022-06-22 17:10:41 +00002585inline bool
2586 findSensorNameUsingSensorPath(std::string_view sensorName,
Ed Tanous02cad962022-06-30 16:50:15 -07002587 const std::set<std::string>& sensorsList,
Nan Zhoufe04d492022-06-22 17:10:41 +00002588 std::set<std::string>& sensorsModified)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002589{
Nan Zhoufe04d492022-06-22 17:10:41 +00002590 for (const auto& chassisSensor : sensorsList)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002591 {
George Liu28aa8de2021-02-01 15:13:30 +08002592 sdbusplus::message::object_path path(chassisSensor);
Ed Tanousb00dcc22021-02-23 12:52:50 -08002593 std::string thisSensorName = path.filename();
George Liu28aa8de2021-02-01 15:13:30 +08002594 if (thisSensorName.empty())
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002595 {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002596 continue;
2597 }
2598 if (thisSensorName == sensorName)
2599 {
2600 sensorsModified.emplace(chassisSensor);
2601 return true;
2602 }
2603 }
2604 return false;
2605}
2606
Ed Tanousc71d6122022-11-29 14:10:32 -08002607inline std::pair<std::string, std::string>
2608 splitSensorNameAndType(std::string_view sensorId)
2609{
2610 size_t index = sensorId.find('_');
2611 if (index == std::string::npos)
2612 {
2613 return std::make_pair<std::string, std::string>("", "");
2614 }
2615 std::string sensorType{sensorId.substr(0, index)};
2616 std::string sensorName{sensorId.substr(index + 1)};
2617 // fan_pwm and fan_tach need special handling
2618 if (sensorType == "fantach" || sensorType == "fanpwm")
2619 {
2620 sensorType.insert(3, 1, '_');
2621 }
2622 return std::make_pair(sensorType, sensorName);
2623}
2624
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002625/**
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302626 * @brief Entry point for overriding sensor values of given sensor
2627 *
zhanghch058d1b46d2021-04-01 11:18:24 +08002628 * @param sensorAsyncResp response object
Carol Wang4bb3dc32019-10-17 18:15:02 +08002629 * @param allCollections Collections extract from sensors' request patch info
jayaprakash Mutyala91e130a2020-03-04 22:26:38 +00002630 * @param chassisSubNode Chassis Node for which the query has to happen
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302631 */
Ed Tanous23a21a12020-07-25 04:45:05 +00002632inline void setSensorsOverride(
Ed Tanousb5a76932020-09-29 16:16:58 -07002633 const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp,
Ed Tanous08850572024-03-06 15:09:17 -08002634 std::unordered_map<std::string, std::vector<nlohmann::json::object_t>>&
jayaprakash Mutyala397fd612020-02-06 23:33:34 +00002635 allCollections)
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302636{
Ed Tanous62598e32023-07-17 17:06:25 -07002637 BMCWEB_LOG_INFO("setSensorsOverride for subNode{}",
2638 sensorAsyncResp->chassisSubNode);
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302639
Ed Tanousd02aad32024-02-13 14:43:34 -08002640 std::string_view propertyValueName;
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302641 std::unordered_map<std::string, std::pair<double, std::string>> overrideMap;
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302642 std::string memberId;
Ed Tanous543f4402022-01-06 13:12:53 -08002643 double value = 0.0;
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302644 for (auto& collectionItems : allCollections)
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302645 {
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302646 if (collectionItems.first == "Temperatures")
2647 {
2648 propertyValueName = "ReadingCelsius";
2649 }
2650 else if (collectionItems.first == "Fans")
2651 {
2652 propertyValueName = "Reading";
2653 }
2654 else
2655 {
2656 propertyValueName = "ReadingVolts";
2657 }
2658 for (auto& item : collectionItems.second)
2659 {
Ed Tanous08850572024-03-06 15:09:17 -08002660 if (!json_util::readJsonObject(
2661 item, sensorAsyncResp->asyncResp->res, "MemberId", memberId,
2662 propertyValueName, value))
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302663 {
2664 return;
2665 }
2666 overrideMap.emplace(memberId,
2667 std::make_pair(value, collectionItems.first));
2668 }
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302669 }
Carol Wang4bb3dc32019-10-17 18:15:02 +08002670
Ed Tanous002d39b2022-05-31 08:59:27 -07002671 auto getChassisSensorListCb =
Ed Tanousd02aad32024-02-13 14:43:34 -08002672 [sensorAsyncResp, overrideMap,
2673 propertyValueNameStr = std::string(propertyValueName)](
Nan Zhoufe04d492022-06-22 17:10:41 +00002674 const std::shared_ptr<std::set<std::string>>& sensorsList) {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002675 // Match sensor names in the PATCH request to those managed by the
2676 // chassis node
Nan Zhoufe04d492022-06-22 17:10:41 +00002677 const std::shared_ptr<std::set<std::string>> sensorNames =
2678 std::make_shared<std::set<std::string>>();
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302679 for (const auto& item : overrideMap)
2680 {
2681 const auto& sensor = item.first;
Ed Tanousc71d6122022-11-29 14:10:32 -08002682 std::pair<std::string, std::string> sensorNameType =
2683 splitSensorNameAndType(sensor);
2684 if (!findSensorNameUsingSensorPath(sensorNameType.second,
2685 *sensorsList, *sensorNames))
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302686 {
Ed Tanous62598e32023-07-17 17:06:25 -07002687 BMCWEB_LOG_INFO("Unable to find memberId {}", item.first);
zhanghch058d1b46d2021-04-01 11:18:24 +08002688 messages::resourceNotFound(sensorAsyncResp->asyncResp->res,
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302689 item.second.second, item.first);
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302690 return;
2691 }
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302692 }
2693 // Get the connection to which the memberId belongs
Ed Tanous002d39b2022-05-31 08:59:27 -07002694 auto getObjectsWithConnectionCb =
Ed Tanousd02aad32024-02-13 14:43:34 -08002695 [sensorAsyncResp, overrideMap, propertyValueNameStr](
2696 const std::set<std::string>& /*connections*/,
2697 const std::set<std::pair<std::string, std::string>>&
2698 objectsWithConnection) {
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002699 if (objectsWithConnection.size() != overrideMap.size())
2700 {
Ed Tanous62598e32023-07-17 17:06:25 -07002701 BMCWEB_LOG_INFO(
2702 "Unable to find all objects with proper connection {} requested {}",
2703 objectsWithConnection.size(), overrideMap.size());
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002704 messages::resourceNotFound(sensorAsyncResp->asyncResp->res,
2705 sensorAsyncResp->chassisSubNode ==
2706 sensors::node::thermal
2707 ? "Temperatures"
2708 : "Voltages",
2709 "Count");
2710 return;
2711 }
2712 for (const auto& item : objectsWithConnection)
2713 {
2714 sdbusplus::message::object_path path(item.first);
2715 std::string sensorName = path.filename();
2716 if (sensorName.empty())
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302717 {
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002718 messages::internalError(sensorAsyncResp->asyncResp->res);
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302719 return;
2720 }
Ban Feng3f5eb752023-06-29 09:19:20 +08002721 std::string id = path.parent_path().filename();
Ed Tanous3544d2a2023-08-06 18:12:20 -07002722 auto remove = std::ranges::remove(id, '_');
2723 id.erase(std::ranges::begin(remove), id.end());
Ban Feng3f5eb752023-06-29 09:19:20 +08002724 id += "_";
2725 id += sensorName;
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302726
Ban Feng3f5eb752023-06-29 09:19:20 +08002727 const auto& iterator = overrideMap.find(id);
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002728 if (iterator == overrideMap.end())
2729 {
Ed Tanous62598e32023-07-17 17:06:25 -07002730 BMCWEB_LOG_INFO("Unable to find sensor object{}",
2731 item.first);
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002732 messages::internalError(sensorAsyncResp->asyncResp->res);
2733 return;
2734 }
Ed Tanousd02aad32024-02-13 14:43:34 -08002735 setDbusProperty(sensorAsyncResp->asyncResp, item.second,
2736 item.first, "xyz.openbmc_project.Sensor.Value",
2737 "Value", propertyValueNameStr,
2738 iterator->second.first);
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002739 }
2740 };
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302741 // Get object with connection for the given sensor name
2742 getObjectsWithConnection(sensorAsyncResp, sensorNames,
2743 std::move(getObjectsWithConnectionCb));
2744 };
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302745 // get full sensor list for the given chassisId and cross verify the sensor.
Ed Tanous7f1cc262022-08-09 13:33:57 -07002746 getChassis(sensorAsyncResp->asyncResp, sensorAsyncResp->chassisId,
2747 sensorAsyncResp->chassisSubNode, sensorAsyncResp->types,
2748 std::move(getChassisSensorListCb));
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302749}
2750
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002751/**
2752 * @brief Retrieves mapping of Redfish URIs to sensor value property to D-Bus
2753 * path of the sensor.
2754 *
2755 * Function builds valid Redfish response for sensor query of given chassis and
2756 * node. It then builds metadata about Redfish<->D-Bus correlations and provides
2757 * it to caller in a callback.
2758 *
2759 * @param chassis Chassis for which retrieval should be performed
2760 * @param node Node (group) of sensors. See sensors::node for supported values
2761 * @param mapComplete Callback to be called with retrieval result
2762 */
Ed Tanous931edc72023-11-01 12:09:07 -07002763template <typename Callback>
Krzysztof Grobelny021d32c2021-10-29 16:00:07 +02002764inline void retrieveUriToDbusMap(const std::string& chassis,
2765 const std::string& node,
Ed Tanous931edc72023-11-01 12:09:07 -07002766 Callback&& mapComplete)
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002767{
Ed Tanous02da7c52022-02-27 00:09:02 -08002768 decltype(sensors::paths)::const_iterator pathIt =
2769 std::find_if(sensors::paths.cbegin(), sensors::paths.cend(),
2770 [&node](auto&& val) { return val.first == node; });
2771 if (pathIt == sensors::paths.cend())
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002772 {
Ed Tanous62598e32023-07-17 17:06:25 -07002773 BMCWEB_LOG_ERROR("Wrong node provided : {}", node);
Ed Tanous6804b5c2023-10-31 14:50:03 -07002774 std::map<std::string, std::string> noop;
2775 mapComplete(boost::beast::http::status::bad_request, noop);
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002776 return;
2777 }
Krzysztof Grobelnyd51e0722021-04-16 13:15:21 +00002778
Nan Zhou72374eb2022-01-27 17:06:51 -08002779 auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
Ed Tanous931edc72023-11-01 12:09:07 -07002780 auto callback = [asyncResp,
2781 mapCompleteCb{std::forward<Callback>(mapComplete)}](
Nan Zhoufe04d492022-06-22 17:10:41 +00002782 const boost::beast::http::status status,
2783 const std::map<std::string, std::string>& uriToDbus) {
2784 mapCompleteCb(status, uriToDbus);
2785 };
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002786
2787 auto resp = std::make_shared<SensorsAsyncResp>(
Krzysztof Grobelnyd51e0722021-04-16 13:15:21 +00002788 asyncResp, chassis, pathIt->second, node, std::move(callback));
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002789 getChassisData(resp);
2790}
2791
Nan Zhoubacb2162022-04-06 11:28:32 -07002792namespace sensors
2793{
Nan Zhou928fefb2022-03-28 08:45:00 -07002794
Nan Zhoubacb2162022-04-06 11:28:32 -07002795inline void getChassisCallback(
Ed Tanousc1d019a2022-08-06 09:36:06 -07002796 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2797 std::string_view chassisId, std::string_view chassisSubNode,
Nan Zhoufe04d492022-06-22 17:10:41 +00002798 const std::shared_ptr<std::set<std::string>>& sensorNames)
Nan Zhoubacb2162022-04-06 11:28:32 -07002799{
Ed Tanous62598e32023-07-17 17:06:25 -07002800 BMCWEB_LOG_DEBUG("getChassisCallback enter ");
Nan Zhoubacb2162022-04-06 11:28:32 -07002801
Ed Tanousc1d019a2022-08-06 09:36:06 -07002802 nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
2803 for (const std::string& sensor : *sensorNames)
Nan Zhoubacb2162022-04-06 11:28:32 -07002804 {
Ed Tanous62598e32023-07-17 17:06:25 -07002805 BMCWEB_LOG_DEBUG("Adding sensor: {}", sensor);
Nan Zhoubacb2162022-04-06 11:28:32 -07002806
2807 sdbusplus::message::object_path path(sensor);
2808 std::string sensorName = path.filename();
2809 if (sensorName.empty())
2810 {
Ed Tanous62598e32023-07-17 17:06:25 -07002811 BMCWEB_LOG_ERROR("Invalid sensor path: {}", sensor);
Ed Tanousc1d019a2022-08-06 09:36:06 -07002812 messages::internalError(asyncResp->res);
Nan Zhoubacb2162022-04-06 11:28:32 -07002813 return;
2814 }
Ed Tanousc1d019a2022-08-06 09:36:06 -07002815 std::string type = path.parent_path().filename();
2816 // fan_tach has an underscore in it, so remove it to "normalize" the
2817 // type in the URI
Ed Tanous3544d2a2023-08-06 18:12:20 -07002818 auto remove = std::ranges::remove(type, '_');
2819 type.erase(std::ranges::begin(remove), type.end());
Ed Tanousc1d019a2022-08-06 09:36:06 -07002820
Ed Tanous14766872022-03-15 10:44:42 -07002821 nlohmann::json::object_t member;
Ed Tanousc1d019a2022-08-06 09:36:06 -07002822 std::string id = type;
2823 id += "_";
2824 id += sensorName;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002825 member["@odata.id"] = boost::urls::format(
2826 "/redfish/v1/Chassis/{}/{}/{}", chassisId, chassisSubNode, id);
Ed Tanousc1d019a2022-08-06 09:36:06 -07002827
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002828 entriesArray.emplace_back(std::move(member));
Nan Zhoubacb2162022-04-06 11:28:32 -07002829 }
2830
Ed Tanousc1d019a2022-08-06 09:36:06 -07002831 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
Ed Tanous62598e32023-07-17 17:06:25 -07002832 BMCWEB_LOG_DEBUG("getChassisCallback exit");
Nan Zhoubacb2162022-04-06 11:28:32 -07002833}
Nan Zhoue6bd8462022-06-01 04:35:35 +00002834
Ed Tanousac106bf2023-06-07 09:24:59 -07002835inline void handleSensorCollectionGet(
2836 App& app, const crow::Request& req,
2837 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2838 const std::string& chassisId)
Nan Zhoude167a62022-06-01 04:47:45 +00002839{
2840 query_param::QueryCapabilities capabilities = {
2841 .canDelegateExpandLevel = 1,
2842 };
2843 query_param::Query delegatedQuery;
Ed Tanousac106bf2023-06-07 09:24:59 -07002844 if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
Nan Zhoude167a62022-06-01 04:47:45 +00002845 delegatedQuery, capabilities))
2846 {
2847 return;
2848 }
2849
2850 if (delegatedQuery.expandType != query_param::ExpandType::None)
2851 {
2852 // we perform efficient expand.
Ed Tanousac106bf2023-06-07 09:24:59 -07002853 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
2854 asyncResp, chassisId, sensors::dbus::sensorPaths,
Nan Zhoude167a62022-06-01 04:47:45 +00002855 sensors::node::sensors,
2856 /*efficientExpand=*/true);
Ed Tanousac106bf2023-06-07 09:24:59 -07002857 getChassisData(sensorsAsyncResp);
Nan Zhoude167a62022-06-01 04:47:45 +00002858
Ed Tanous62598e32023-07-17 17:06:25 -07002859 BMCWEB_LOG_DEBUG(
2860 "SensorCollection doGet exit via efficient expand handler");
Nan Zhoude167a62022-06-01 04:47:45 +00002861 return;
Ed Tanous0bad3202022-06-02 13:53:59 -07002862 }
Nan Zhoude167a62022-06-01 04:47:45 +00002863
Nan Zhoude167a62022-06-01 04:47:45 +00002864 // We get all sensors as hyperlinkes in the chassis (this
2865 // implies we reply on the default query parameters handler)
Ed Tanousac106bf2023-06-07 09:24:59 -07002866 getChassis(asyncResp, chassisId, sensors::node::sensors, dbus::sensorPaths,
2867 std::bind_front(sensors::getChassisCallback, asyncResp,
2868 chassisId, sensors::node::sensors));
Ed Tanousc1d019a2022-08-06 09:36:06 -07002869}
Ed Tanous7f1cc262022-08-09 13:33:57 -07002870
Ed Tanousc1d019a2022-08-06 09:36:06 -07002871inline void
2872 getSensorFromDbus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2873 const std::string& sensorPath,
2874 const ::dbus::utility::MapperGetObject& mapperResponse)
2875{
2876 if (mapperResponse.size() != 1)
2877 {
2878 messages::internalError(asyncResp->res);
2879 return;
2880 }
2881 const auto& valueIface = *mapperResponse.begin();
2882 const std::string& connectionName = valueIface.first;
Ed Tanous62598e32023-07-17 17:06:25 -07002883 BMCWEB_LOG_DEBUG("Looking up {}", connectionName);
2884 BMCWEB_LOG_DEBUG("Path {}", sensorPath);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +02002885
2886 sdbusplus::asio::getAllProperties(
2887 *crow::connections::systemBus, connectionName, sensorPath, "",
Ed Tanousc1d019a2022-08-06 09:36:06 -07002888 [asyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002889 sensorPath](const boost::system::error_code& ec,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002890 const ::dbus::utility::DBusPropertiesMap& valuesDict) {
2891 if (ec)
2892 {
2893 messages::internalError(asyncResp->res);
2894 return;
2895 }
2896 sdbusplus::message::object_path path(sensorPath);
2897 std::string name = path.filename();
2898 path = path.parent_path();
2899 std::string type = path.filename();
2900 objectPropertiesToJson(name, type, sensors::node::sensors, valuesDict,
2901 asyncResp->res.jsonValue, nullptr);
Patrick Williams5a39f772023-10-20 11:20:21 -05002902 });
Nan Zhoude167a62022-06-01 04:47:45 +00002903}
2904
Nan Zhoue6bd8462022-06-01 04:35:35 +00002905inline void handleSensorGet(App& app, const crow::Request& req,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002906 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous677bb752022-09-15 10:52:19 -07002907 const std::string& chassisId,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002908 const std::string& sensorId)
Nan Zhoue6bd8462022-06-01 04:35:35 +00002909{
Ed Tanousc1d019a2022-08-06 09:36:06 -07002910 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nan Zhoue6bd8462022-06-01 04:35:35 +00002911 {
2912 return;
2913 }
Ed Tanousc71d6122022-11-29 14:10:32 -08002914 std::pair<std::string, std::string> nameType =
2915 splitSensorNameAndType(sensorId);
2916 if (nameType.first.empty() || nameType.second.empty())
Ed Tanousc1d019a2022-08-06 09:36:06 -07002917 {
2918 messages::resourceNotFound(asyncResp->res, sensorId, "Sensor");
2919 return;
2920 }
Ed Tanousc71d6122022-11-29 14:10:32 -08002921
Ed Tanousef4c65b2023-04-24 15:28:50 -07002922 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2923 "/redfish/v1/Chassis/{}/Sensors/{}", chassisId, sensorId);
Ed Tanousc1d019a2022-08-06 09:36:06 -07002924
Ed Tanous62598e32023-07-17 17:06:25 -07002925 BMCWEB_LOG_DEBUG("Sensor doGet enter");
Nan Zhoue6bd8462022-06-01 04:35:35 +00002926
George Liu2b731192023-01-11 16:27:13 +08002927 constexpr std::array<std::string_view, 1> interfaces = {
Nan Zhoue6bd8462022-06-01 04:35:35 +00002928 "xyz.openbmc_project.Sensor.Value"};
Ed Tanousc71d6122022-11-29 14:10:32 -08002929 std::string sensorPath = "/xyz/openbmc_project/sensors/" + nameType.first +
2930 '/' + nameType.second;
Nan Zhoue6bd8462022-06-01 04:35:35 +00002931 // Get a list of all of the sensors that implement Sensor.Value
2932 // and get the path and service name associated with the sensor
George Liu2b731192023-01-11 16:27:13 +08002933 ::dbus::utility::getDbusObject(
2934 sensorPath, interfaces,
Myung Baeaec0ec32023-05-31 15:10:01 -05002935 [asyncResp, sensorId,
George Liu2b731192023-01-11 16:27:13 +08002936 sensorPath](const boost::system::error_code& ec,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002937 const ::dbus::utility::MapperGetObject& subtree) {
Ed Tanous62598e32023-07-17 17:06:25 -07002938 BMCWEB_LOG_DEBUG("respHandler1 enter");
Myung Baeaec0ec32023-05-31 15:10:01 -05002939 if (ec == boost::system::errc::io_error)
2940 {
Ed Tanous62598e32023-07-17 17:06:25 -07002941 BMCWEB_LOG_WARNING("Sensor not found from getSensorPaths");
Myung Baeaec0ec32023-05-31 15:10:01 -05002942 messages::resourceNotFound(asyncResp->res, sensorId, "Sensor");
2943 return;
2944 }
Nan Zhoue6bd8462022-06-01 04:35:35 +00002945 if (ec)
2946 {
Ed Tanousc1d019a2022-08-06 09:36:06 -07002947 messages::internalError(asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07002948 BMCWEB_LOG_ERROR(
2949 "Sensor getSensorPaths resp_handler: Dbus error {}", ec);
Nan Zhoue6bd8462022-06-01 04:35:35 +00002950 return;
2951 }
Ed Tanousc1d019a2022-08-06 09:36:06 -07002952 getSensorFromDbus(asyncResp, sensorPath, subtree);
Ed Tanous62598e32023-07-17 17:06:25 -07002953 BMCWEB_LOG_DEBUG("respHandler1 exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05002954 });
Nan Zhoue6bd8462022-06-01 04:35:35 +00002955}
2956
Nan Zhoubacb2162022-04-06 11:28:32 -07002957} // namespace sensors
2958
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002959inline void requestRoutesSensorCollection(App& app)
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002960{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002961 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/")
Ed Tanoused398212021-06-09 17:05:54 -07002962 .privileges(redfish::privileges::getSensorCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07002963 .methods(boost::beast::http::verb::get)(
Nan Zhoude167a62022-06-01 04:47:45 +00002964 std::bind_front(sensors::handleSensorCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002965}
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002966
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002967inline void requestRoutesSensor(App& app)
2968{
2969 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002970 .privileges(redfish::privileges::getSensor)
Ed Tanous002d39b2022-05-31 08:59:27 -07002971 .methods(boost::beast::http::verb::get)(
Nan Zhoue6bd8462022-06-01 04:35:35 +00002972 std::bind_front(sensors::handleSensorGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002973}
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002974
Ed Tanous1abe55e2018-09-05 08:30:59 -07002975} // namespace redfish