blob: 75eaa7cde1f379b509515412868cc563402fac20 [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 Tanous8cb2c022024-03-27 16:31:46 -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 =
Ed Tanous8cb2c022024-03-27 16:31:46 -0700426 [callback = std::forward<Callback>(callback)](
427 const std::set<std::string>& connections,
428 const std::set<std::pair<std::string, std::string>>&
429 /*objectsWithConnection*/) { callback(connections); };
Ed Tanous81ce6092020-12-17 16:54:55 +0000430 getObjectsWithConnection(sensorsAsyncResp, sensorNames,
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530431 std::move(objectsWithConnectionCb));
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100432}
433
434/**
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700435 * @brief Shrinks the list of sensors for processing
436 * @param SensorsAysncResp The class holding the Redfish response
437 * @param allSensors A list of all the sensors associated to the
438 * chassis element (i.e. baseboard, front panel, etc...)
439 * @param activeSensors A list that is a reduction of the incoming
440 * allSensors list. Eliminate Thermal sensors when a Power request is
441 * made, and eliminate Power sensors when a Thermal request is made.
442 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000443inline void reduceSensorList(
Ed Tanous7f1cc262022-08-09 13:33:57 -0700444 crow::Response& res, std::string_view chassisSubNode,
Ed Tanouscf9e4172022-12-21 09:30:16 -0800445 std::span<const std::string_view> sensorTypes,
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700446 const std::vector<std::string>* allSensors,
Nan Zhoufe04d492022-06-22 17:10:41 +0000447 const std::shared_ptr<std::set<std::string>>& activeSensors)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700448{
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700449 if ((allSensors == nullptr) || (activeSensors == nullptr))
450 {
Ed Tanous7f1cc262022-08-09 13:33:57 -0700451 messages::resourceNotFound(res, chassisSubNode,
452 chassisSubNode == sensors::node::thermal
453 ? "Temperatures"
454 : "Voltages");
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700455
456 return;
457 }
458 if (allSensors->empty())
459 {
460 // Nothing to do, the activeSensors object is also empty
461 return;
462 }
463
Ed Tanous7f1cc262022-08-09 13:33:57 -0700464 for (std::string_view type : sensorTypes)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700465 {
466 for (const std::string& sensor : *allSensors)
467 {
Ed Tanous11ba3972022-07-11 09:50:41 -0700468 if (sensor.starts_with(type))
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700469 {
470 activeSensors->emplace(sensor);
471 }
472 }
473 }
474}
475
Ed Tanous7f1cc262022-08-09 13:33:57 -0700476/*
477 *Populates the top level collection for a given subnode. Populates
478 *SensorCollection, Power, or Thermal schemas.
479 *
480 * */
481inline void populateChassisNode(nlohmann::json& jsonValue,
482 std::string_view chassisSubNode)
483{
484 if (chassisSubNode == sensors::node::power)
485 {
486 jsonValue["@odata.type"] = "#Power.v1_5_2.Power";
487 }
488 else if (chassisSubNode == sensors::node::thermal)
489 {
490 jsonValue["@odata.type"] = "#Thermal.v1_4_0.Thermal";
491 jsonValue["Fans"] = nlohmann::json::array();
492 jsonValue["Temperatures"] = nlohmann::json::array();
493 }
494 else if (chassisSubNode == sensors::node::sensors)
495 {
496 jsonValue["@odata.type"] = "#SensorCollection.SensorCollection";
497 jsonValue["Description"] = "Collection of Sensors for this Chassis";
498 jsonValue["Members"] = nlohmann::json::array();
499 jsonValue["Members@odata.count"] = 0;
500 }
501
502 if (chassisSubNode != sensors::node::sensors)
503 {
504 jsonValue["Id"] = chassisSubNode;
505 }
506 jsonValue["Name"] = chassisSubNode;
507}
508
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700509/**
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100510 * @brief Retrieves requested chassis sensors and redundancy data from DBus .
Kowalski, Kamil588c3f02018-04-03 14:55:27 +0200511 * @param SensorsAsyncResp Pointer to object holding response data
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100512 * @param callback Callback for next step in gathered sensor processing
513 */
514template <typename Callback>
Ed Tanous7f1cc262022-08-09 13:33:57 -0700515void getChassis(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
516 std::string_view chassisId, std::string_view chassisSubNode,
Ed Tanouscf9e4172022-12-21 09:30:16 -0800517 std::span<const std::string_view> sensorTypes,
518 Callback&& callback)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700519{
Ed Tanous62598e32023-07-17 17:06:25 -0700520 BMCWEB_LOG_DEBUG("getChassis enter");
George Liu7a1dbc42022-12-07 16:03:22 +0800521 constexpr std::array<std::string_view, 2> interfaces = {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700522 "xyz.openbmc_project.Inventory.Item.Board",
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500523 "xyz.openbmc_project.Inventory.Item.Chassis"};
George Liu7a1dbc42022-12-07 16:03:22 +0800524
525 // Get the Chassis Collection
526 dbus::utility::getSubTreePaths(
527 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous8cb2c022024-03-27 16:31:46 -0700528 [callback = std::forward<Callback>(callback), asyncResp,
Ed Tanous7f1cc262022-08-09 13:33:57 -0700529 chassisIdStr{std::string(chassisId)},
530 chassisSubNode{std::string(chassisSubNode)}, sensorTypes](
George Liu7a1dbc42022-12-07 16:03:22 +0800531 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -0700532 const dbus::utility::MapperGetSubTreePathsResponse& chassisPaths) {
Ed Tanous62598e32023-07-17 17:06:25 -0700533 BMCWEB_LOG_DEBUG("getChassis respHandler enter");
Ed Tanous1abe55e2018-09-05 08:30:59 -0700534 if (ec)
535 {
Ed Tanous62598e32023-07-17 17:06:25 -0700536 BMCWEB_LOG_ERROR("getChassis respHandler DBUS error: {}", ec);
Ed Tanous7f1cc262022-08-09 13:33:57 -0700537 messages::internalError(asyncResp->res);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700538 return;
539 }
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700540 const std::string* chassisPath = nullptr;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700541 for (const std::string& chassis : chassisPaths)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700542 {
George Liu28aa8de2021-02-01 15:13:30 +0800543 sdbusplus::message::object_path path(chassis);
Ed Tanousf8fe53e2022-06-30 15:55:45 -0700544 std::string chassisName = path.filename();
George Liu28aa8de2021-02-01 15:13:30 +0800545 if (chassisName.empty())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700546 {
Ed Tanous62598e32023-07-17 17:06:25 -0700547 BMCWEB_LOG_ERROR("Failed to find '/' in {}", chassis);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700548 continue;
549 }
Ed Tanous7f1cc262022-08-09 13:33:57 -0700550 if (chassisName == chassisIdStr)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700551 {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700552 chassisPath = &chassis;
553 break;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700554 }
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700555 }
556 if (chassisPath == nullptr)
557 {
Ed Tanous7f1cc262022-08-09 13:33:57 -0700558 messages::resourceNotFound(asyncResp->res, "Chassis", chassisIdStr);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700559 return;
560 }
Ed Tanous7f1cc262022-08-09 13:33:57 -0700561 populateChassisNode(asyncResp->res.jsonValue, chassisSubNode);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700562
Ed Tanousef4c65b2023-04-24 15:28:50 -0700563 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
564 "/redfish/v1/Chassis/{}/{}", chassisIdStr, chassisSubNode);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500565
Shawn McCarney8fb49dd2019-06-12 17:47:00 -0500566 // Get the list of all sensors for this Chassis element
567 std::string sensorPath = *chassisPath + "/all_sensors";
George Liu6c3e9452023-03-03 13:55:29 +0800568 dbus::utility::getAssociationEndPoints(
569 sensorPath,
Ed Tanous7f1cc262022-08-09 13:33:57 -0700570 [asyncResp, chassisSubNode, sensorTypes,
Ed Tanous8cb2c022024-03-27 16:31:46 -0700571 callback = std::forward<const Callback>(callback)](
Ed Tanous8b242752023-06-27 17:17:13 -0700572 const boost::system::error_code& ec2,
George Liu6c3e9452023-03-03 13:55:29 +0800573 const dbus::utility::MapperEndPoints& nodeSensorList) {
Ed Tanous8b242752023-06-27 17:17:13 -0700574 if (ec2)
Ed Tanous002d39b2022-05-31 08:59:27 -0700575 {
Ed Tanous8b242752023-06-27 17:17:13 -0700576 if (ec2.value() != EBADR)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700577 {
Ed Tanous7f1cc262022-08-09 13:33:57 -0700578 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700579 return;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700580 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700581 }
Nan Zhoufe04d492022-06-22 17:10:41 +0000582 const std::shared_ptr<std::set<std::string>> culledSensorList =
583 std::make_shared<std::set<std::string>>();
Ed Tanous7f1cc262022-08-09 13:33:57 -0700584 reduceSensorList(asyncResp->res, chassisSubNode, sensorTypes,
585 &nodeSensorList, culledSensorList);
Ed Tanous62598e32023-07-17 17:06:25 -0700586 BMCWEB_LOG_DEBUG("Finishing with {}", culledSensorList->size());
Ed Tanous002d39b2022-05-31 08:59:27 -0700587 callback(culledSensorList);
George Liu7a1dbc42022-12-07 16:03:22 +0800588 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500589 });
Ed Tanous62598e32023-07-17 17:06:25 -0700590 BMCWEB_LOG_DEBUG("getChassis exit");
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100591}
592
593/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500594 * @brief Returns the Redfish State value for the specified inventory item.
595 * @param inventoryItem D-Bus inventory item associated with a sensor.
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700596 * @param sensorAvailable Boolean representing if D-Bus sensor is marked as
597 * available.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500598 * @return State value for inventory item.
James Feist34dd1792019-05-17 14:10:54 -0700599 */
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700600inline resource::State getState(const InventoryItem* inventoryItem,
601 const bool sensorAvailable)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500602{
603 if ((inventoryItem != nullptr) && !(inventoryItem->isPresent))
604 {
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700605 return resource::State::Absent;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500606 }
James Feist34dd1792019-05-17 14:10:54 -0700607
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700608 if (!sensorAvailable)
609 {
610 return resource::State::UnavailableOffline;
611 }
612
613 return resource::State::Enabled;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500614}
615
616/**
617 * @brief Returns the Redfish Health value for the specified sensor.
618 * @param sensorJson Sensor JSON object.
Ed Tanous1d7c0052022-08-09 12:32:26 -0700619 * @param valuesDict Map of all sensor DBus values.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500620 * @param inventoryItem D-Bus inventory item associated with the sensor. Will
621 * be nullptr if no associated inventory item was found.
622 * @return Health value for sensor.
623 */
Ed Tanous1d7c0052022-08-09 12:32:26 -0700624inline std::string getHealth(nlohmann::json& sensorJson,
625 const dbus::utility::DBusPropertiesMap& valuesDict,
626 const InventoryItem* inventoryItem)
James Feist34dd1792019-05-17 14:10:54 -0700627{
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500628 // Get current health value (if any) in the sensor JSON object. Some JSON
629 // objects contain multiple sensors (such as PowerSupplies). We want to set
630 // the overall health to be the most severe of any of the sensors.
631 std::string currentHealth;
632 auto statusIt = sensorJson.find("Status");
633 if (statusIt != sensorJson.end())
634 {
635 auto healthIt = statusIt->find("Health");
636 if (healthIt != statusIt->end())
637 {
638 std::string* health = healthIt->get_ptr<std::string*>();
639 if (health != nullptr)
640 {
641 currentHealth = *health;
642 }
643 }
644 }
645
646 // If current health in JSON object is already Critical, return that. This
647 // should override the sensor health, which might be less severe.
648 if (currentHealth == "Critical")
649 {
650 return "Critical";
651 }
652
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200653 const bool* criticalAlarmHigh = nullptr;
654 const bool* criticalAlarmLow = nullptr;
655 const bool* warningAlarmHigh = nullptr;
656 const bool* warningAlarmLow = nullptr;
Ed Tanous711ac7a2021-12-20 09:34:41 -0800657
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200658 const bool success = sdbusplus::unpackPropertiesNoThrow(
659 dbus_utils::UnpackErrorPrinter(), valuesDict, "CriticalAlarmHigh",
660 criticalAlarmHigh, "CriticalAlarmLow", criticalAlarmLow,
661 "WarningAlarmHigh", warningAlarmHigh, "WarningAlarmLow",
662 warningAlarmLow);
663
664 if (success)
James Feist34dd1792019-05-17 14:10:54 -0700665 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200666 // Check if sensor has critical threshold alarm
667 if ((criticalAlarmHigh != nullptr && *criticalAlarmHigh) ||
668 (criticalAlarmLow != nullptr && *criticalAlarmLow))
James Feist34dd1792019-05-17 14:10:54 -0700669 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200670 return "Critical";
James Feist34dd1792019-05-17 14:10:54 -0700671 }
672 }
673
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500674 // Check if associated inventory item is not functional
675 if ((inventoryItem != nullptr) && !(inventoryItem->isFunctional))
676 {
677 return "Critical";
678 }
679
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200680 // If current health in JSON object is already Warning, return that. This
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500681 // should override the sensor status, which might be less severe.
682 if (currentHealth == "Warning")
683 {
684 return "Warning";
685 }
686
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200687 if (success)
James Feist34dd1792019-05-17 14:10:54 -0700688 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200689 // Check if sensor has warning threshold alarm
690 if ((warningAlarmHigh != nullptr && *warningAlarmHigh) ||
691 (warningAlarmLow != nullptr && *warningAlarmLow))
James Feist34dd1792019-05-17 14:10:54 -0700692 {
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +0200693 return "Warning";
James Feist34dd1792019-05-17 14:10:54 -0700694 }
695 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500696
James Feist34dd1792019-05-17 14:10:54 -0700697 return "OK";
698}
699
Ed Tanous23a21a12020-07-25 04:45:05 +0000700inline void setLedState(nlohmann::json& sensorJson,
Anthony Wilsond5005492019-07-31 16:34:17 -0500701 const InventoryItem* inventoryItem)
702{
703 if (inventoryItem != nullptr && !inventoryItem->ledObjectPath.empty())
704 {
705 switch (inventoryItem->ledState)
706 {
707 case LedState::OFF:
708 sensorJson["IndicatorLED"] = "Off";
709 break;
710 case LedState::ON:
711 sensorJson["IndicatorLED"] = "Lit";
712 break;
713 case LedState::BLINK:
714 sensorJson["IndicatorLED"] = "Blinking";
715 break;
Ed Tanous4da04902024-03-19 11:32:44 -0700716 default:
Anthony Wilsond5005492019-07-31 16:34:17 -0500717 break;
718 }
719 }
720}
721
James Feist34dd1792019-05-17 14:10:54 -0700722/**
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100723 * @brief Builds a json sensor representation of a sensor.
724 * @param sensorName The name of the sensor to be built
Gunnar Mills274fad52018-06-13 15:45:36 -0500725 * @param sensorType The type (temperature, fan_tach, etc) of the sensor to
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100726 * build
Ed Tanous8ece0e42024-01-02 13:16:50 -0800727 * @param chassisSubNode The subnode (thermal, sensor, etc) of the sensor
Ed Tanous1d7c0052022-08-09 12:32:26 -0700728 * @param propertiesDict A dictionary of the properties to build the sensor
729 * from.
730 * @param sensorJson The json object to fill
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500731 * @param inventoryItem D-Bus inventory item associated with the sensor. Will
732 * be nullptr if no associated inventory item was found.
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100733 */
Ed Tanous1d7c0052022-08-09 12:32:26 -0700734inline void objectPropertiesToJson(
735 std::string_view sensorName, std::string_view sensorType,
736 std::string_view chassisSubNode,
737 const dbus::utility::DBusPropertiesMap& propertiesDict,
Ed Tanous81ce6092020-12-17 16:54:55 +0000738 nlohmann::json& sensorJson, InventoryItem* inventoryItem)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700739{
Ed Tanous1d7c0052022-08-09 12:32:26 -0700740 if (chassisSubNode == sensors::node::sensors)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500741 {
Ed Tanousc71d6122022-11-29 14:10:32 -0800742 std::string subNodeEscaped(sensorType);
Ed Tanous3544d2a2023-08-06 18:12:20 -0700743 auto remove = std::ranges::remove(subNodeEscaped, '_');
744 subNodeEscaped.erase(std::ranges::begin(remove), subNodeEscaped.end());
Ed Tanousc1d019a2022-08-06 09:36:06 -0700745
746 // For sensors in SensorCollection we set Id instead of MemberId,
747 // including power sensors.
748 subNodeEscaped += '_';
749 subNodeEscaped += sensorName;
750 sensorJson["Id"] = std::move(subNodeEscaped);
751
Ed Tanous1d7c0052022-08-09 12:32:26 -0700752 std::string sensorNameEs(sensorName);
753 std::replace(sensorNameEs.begin(), sensorNameEs.end(), '_', ' ');
754 sensorJson["Name"] = std::move(sensorNameEs);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500755 }
756 else if (sensorType != "power")
757 {
758 // Set MemberId and Name for non-power sensors. For PowerSupplies and
759 // PowerControl, those properties have more general values because
760 // multiple sensors can be stored in the same JSON object.
Ed Tanous1d7c0052022-08-09 12:32:26 -0700761 std::string sensorNameEs(sensorName);
762 std::replace(sensorNameEs.begin(), sensorNameEs.end(), '_', ' ');
763 sensorJson["Name"] = std::move(sensorNameEs);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500764 }
Ed Tanouse742b6c2019-05-03 15:06:53 -0700765
Matt Simmeringaaf08ac2023-10-04 08:41:01 -0700766 const bool* checkAvailable = nullptr;
767 bool available = true;
768 const bool success = sdbusplus::unpackPropertiesNoThrow(
769 dbus_utils::UnpackErrorPrinter(), propertiesDict, "Available",
770 checkAvailable);
771 if (!success)
772 {
773 messages::internalError();
774 }
775 if (checkAvailable != nullptr)
776 {
777 available = *checkAvailable;
778 }
779
780 sensorJson["Status"]["State"] = getState(inventoryItem, available);
Patrick Williams89492a12023-05-10 07:51:34 -0500781 sensorJson["Status"]["Health"] = getHealth(sensorJson, propertiesDict,
782 inventoryItem);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700783
784 // Parameter to set to override the type we get from dbus, and force it to
785 // int, regardless of what is available. This is used for schemas like fan,
786 // that require integers, not floats.
787 bool forceToInt = false;
788
Anthony Wilson3929aca2019-07-19 15:42:33 -0500789 nlohmann::json::json_pointer unit("/Reading");
Ed Tanous1d7c0052022-08-09 12:32:26 -0700790 if (chassisSubNode == sensors::node::sensors)
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500791 {
Shounak Mitra2a4ba192022-06-01 23:34:12 +0000792 sensorJson["@odata.type"] = "#Sensor.v1_2_0.Sensor";
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000793
Ed Tanous0ec8b832022-03-14 14:56:47 -0700794 sensor::ReadingType readingType = sensors::toReadingType(sensorType);
795 if (readingType == sensor::ReadingType::Invalid)
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500796 {
Ed Tanous62598e32023-07-17 17:06:25 -0700797 BMCWEB_LOG_ERROR("Redfish cannot map reading type for {}",
798 sensorType);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500799 }
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000800 else
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500801 {
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000802 sensorJson["ReadingType"] = readingType;
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500803 }
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000804
Ed Tanous1d7c0052022-08-09 12:32:26 -0700805 std::string_view readingUnits = sensors::toReadingUnits(sensorType);
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000806 if (readingUnits.empty())
Adrian Ambrożewiczf8ede152020-06-02 13:26:33 +0200807 {
Ed Tanous62598e32023-07-17 17:06:25 -0700808 BMCWEB_LOG_ERROR("Redfish cannot map reading unit for {}",
809 sensorType);
Wludzik, Jozefc2bf7f92021-03-08 14:35:54 +0000810 }
811 else
812 {
813 sensorJson["ReadingUnits"] = readingUnits;
Adrian Ambrożewiczf8ede152020-06-02 13:26:33 +0200814 }
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500815 }
816 else if (sensorType == "temperature")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700817 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500818 unit = "/ReadingCelsius"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000819 sensorJson["@odata.type"] = "#Thermal.v1_3_0.Temperature";
Ed Tanous1abe55e2018-09-05 08:30:59 -0700820 // TODO(ed) Documentation says that path should be type fan_tach,
821 // implementation seems to implement fan
822 }
823 else if (sensorType == "fan" || sensorType == "fan_tach")
824 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500825 unit = "/Reading"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000826 sensorJson["ReadingUnits"] = "RPM";
827 sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan";
828 setLedState(sensorJson, inventoryItem);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700829 forceToInt = true;
830 }
Ed Tanous6f6d0d32018-10-12 11:16:43 -0700831 else if (sensorType == "fan_pwm")
832 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500833 unit = "/Reading"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000834 sensorJson["ReadingUnits"] = "Percent";
835 sensorJson["@odata.type"] = "#Thermal.v1_3_0.Fan";
836 setLedState(sensorJson, inventoryItem);
Ed Tanous6f6d0d32018-10-12 11:16:43 -0700837 forceToInt = true;
838 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700839 else if (sensorType == "voltage")
840 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500841 unit = "/ReadingVolts"_json_pointer;
Ed Tanous81ce6092020-12-17 16:54:55 +0000842 sensorJson["@odata.type"] = "#Power.v1_0_0.Voltage";
Ed Tanous1abe55e2018-09-05 08:30:59 -0700843 }
Ed Tanous2474adf2018-09-05 16:31:16 -0700844 else if (sensorType == "power")
845 {
Ed Tanous18f8f602023-07-18 10:07:23 -0700846 std::string lower;
847 std::ranges::transform(sensorName, std::back_inserter(lower),
848 bmcweb::asciiToLower);
849 if (lower == "total_power")
Eddie James028f7eb2019-05-17 21:24:36 +0000850 {
Ed Tanous81ce6092020-12-17 16:54:55 +0000851 sensorJson["@odata.type"] = "#Power.v1_0_0.PowerControl";
Gunnar Mills7ab06f42019-07-02 13:07:16 -0500852 // Put multiple "sensors" into a single PowerControl, so have
853 // generic names for MemberId and Name. Follows Redfish mockup.
Ed Tanous81ce6092020-12-17 16:54:55 +0000854 sensorJson["MemberId"] = "0";
855 sensorJson["Name"] = "Chassis Power Control";
Anthony Wilson3929aca2019-07-19 15:42:33 -0500856 unit = "/PowerConsumedWatts"_json_pointer;
Eddie James028f7eb2019-05-17 21:24:36 +0000857 }
Ed Tanous18f8f602023-07-18 10:07:23 -0700858 else if (lower.find("input") != std::string::npos)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700859 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500860 unit = "/PowerInputWatts"_json_pointer;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700861 }
862 else
863 {
Anthony Wilson3929aca2019-07-19 15:42:33 -0500864 unit = "/PowerOutputWatts"_json_pointer;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -0700865 }
Ed Tanous2474adf2018-09-05 16:31:16 -0700866 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700867 else
868 {
Ed Tanous62598e32023-07-17 17:06:25 -0700869 BMCWEB_LOG_ERROR("Redfish cannot map object type for {}", sensorName);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700870 return;
871 }
872 // Map of dbus interface name, dbus property name and redfish property_name
Anthony Wilson3929aca2019-07-19 15:42:33 -0500873 std::vector<
874 std::tuple<const char*, const char*, nlohmann::json::json_pointer>>
875 properties;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700876 properties.reserve(7);
877
878 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "Value", unit);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600879
Ed Tanous1d7c0052022-08-09 12:32:26 -0700880 if (chassisSubNode == sensors::node::sensors)
Anthony Wilson3929aca2019-07-19 15:42:33 -0500881 {
882 properties.emplace_back(
883 "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningHigh",
884 "/Thresholds/UpperCaution/Reading"_json_pointer);
885 properties.emplace_back(
886 "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningLow",
887 "/Thresholds/LowerCaution/Reading"_json_pointer);
888 properties.emplace_back(
889 "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalHigh",
890 "/Thresholds/UpperCritical/Reading"_json_pointer);
891 properties.emplace_back(
892 "xyz.openbmc_project.Sensor.Threshold.Critical", "CriticalLow",
893 "/Thresholds/LowerCritical/Reading"_json_pointer);
894 }
895 else if (sensorType != "power")
Shawn McCarneyde629b62019-03-08 10:42:51 -0600896 {
897 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500898 "WarningHigh",
899 "/UpperThresholdNonCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600900 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Warning",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500901 "WarningLow",
902 "/LowerThresholdNonCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600903 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500904 "CriticalHigh",
905 "/UpperThresholdCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600906 properties.emplace_back("xyz.openbmc_project.Sensor.Threshold.Critical",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500907 "CriticalLow",
908 "/LowerThresholdCritical"_json_pointer);
Shawn McCarneyde629b62019-03-08 10:42:51 -0600909 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700910
Ed Tanous2474adf2018-09-05 16:31:16 -0700911 // TODO Need to get UpperThresholdFatal and LowerThresholdFatal
912
Ed Tanous1d7c0052022-08-09 12:32:26 -0700913 if (chassisSubNode == sensors::node::sensors)
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500914 {
915 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500916 "/ReadingRangeMin"_json_pointer);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500917 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500918 "/ReadingRangeMax"_json_pointer);
George Liu51c35a82022-10-13 20:22:14 +0800919 properties.emplace_back("xyz.openbmc_project.Sensor.Accuracy",
920 "Accuracy", "/Accuracy"_json_pointer);
Anthony Wilson95a3eca2019-06-11 10:44:47 -0500921 }
922 else if (sensorType == "temperature")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700923 {
924 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500925 "/MinReadingRangeTemp"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700926 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500927 "/MaxReadingRangeTemp"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700928 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -0500929 else if (sensorType != "power")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700930 {
931 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MinValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500932 "/MinReadingRange"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700933 properties.emplace_back("xyz.openbmc_project.Sensor.Value", "MaxValue",
Anthony Wilson3929aca2019-07-19 15:42:33 -0500934 "/MaxReadingRange"_json_pointer);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700935 }
936
Anthony Wilson3929aca2019-07-19 15:42:33 -0500937 for (const std::tuple<const char*, const char*,
938 nlohmann::json::json_pointer>& p : properties)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700939 {
Ed Tanous1d7c0052022-08-09 12:32:26 -0700940 for (const auto& [valueName, valueVariant] : propertiesDict)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700941 {
Ed Tanous1d7c0052022-08-09 12:32:26 -0700942 if (valueName != std::get<1>(p))
Ed Tanous1abe55e2018-09-05 08:30:59 -0700943 {
Ed Tanous711ac7a2021-12-20 09:34:41 -0800944 continue;
945 }
Ed Tanous1d7c0052022-08-09 12:32:26 -0700946
947 // The property we want to set may be nested json, so use
948 // a json_pointer for easy indexing into the json structure.
949 const nlohmann::json::json_pointer& key = std::get<2>(p);
950
Ed Tanous1d7c0052022-08-09 12:32:26 -0700951 const double* doubleValue = std::get_if<double>(&valueVariant);
Ed Tanous40e4f382022-08-09 18:42:51 -0700952 if (doubleValue == nullptr)
Ed Tanous711ac7a2021-12-20 09:34:41 -0800953 {
Ed Tanous62598e32023-07-17 17:06:25 -0700954 BMCWEB_LOG_ERROR("Got value interface that wasn't double");
Ed Tanous1d7c0052022-08-09 12:32:26 -0700955 continue;
956 }
Ed Tanous283860f2022-08-29 14:08:50 -0700957 if (!std::isfinite(*doubleValue))
958 {
959 if (valueName == "Value")
960 {
961 // Readings are allowed to be NAN for unavailable; coerce
962 // them to null in the json response.
963 sensorJson[key] = nullptr;
964 continue;
965 }
Ed Tanous62598e32023-07-17 17:06:25 -0700966 BMCWEB_LOG_WARNING("Sensor value for {} was unexpectedly {}",
967 valueName, *doubleValue);
Ed Tanous283860f2022-08-29 14:08:50 -0700968 continue;
969 }
Ed Tanous1d7c0052022-08-09 12:32:26 -0700970 if (forceToInt)
971 {
Ed Tanous40e4f382022-08-09 18:42:51 -0700972 sensorJson[key] = static_cast<int64_t>(*doubleValue);
Ed Tanous1d7c0052022-08-09 12:32:26 -0700973 }
974 else
975 {
Ed Tanous40e4f382022-08-09 18:42:51 -0700976 sensorJson[key] = *doubleValue;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700977 }
978 }
979 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100980}
981
Ed Tanous1d7c0052022-08-09 12:32:26 -0700982/**
983 * @brief Builds a json sensor representation of a sensor.
984 * @param sensorName The name of the sensor to be built
985 * @param sensorType The type (temperature, fan_tach, etc) of the sensor to
986 * build
Ed Tanous8ece0e42024-01-02 13:16:50 -0800987 * @param chassisSubNode The subnode (thermal, sensor, etc) of the sensor
Ed Tanous1d7c0052022-08-09 12:32:26 -0700988 * @param interfacesDict A dictionary of the interfaces and properties of said
989 * interfaces to be built from
990 * @param sensorJson The json object to fill
991 * @param inventoryItem D-Bus inventory item associated with the sensor. Will
992 * be nullptr if no associated inventory item was found.
993 */
994inline void objectInterfacesToJson(
995 const std::string& sensorName, const std::string& sensorType,
996 const std::string& chassisSubNode,
Michael Shen80f79a42023-08-24 13:41:53 +0000997 const dbus::utility::DBusInterfacesMap& interfacesDict,
Ed Tanous1d7c0052022-08-09 12:32:26 -0700998 nlohmann::json& sensorJson, InventoryItem* inventoryItem)
999{
Ed Tanous1d7c0052022-08-09 12:32:26 -07001000 for (const auto& [interface, valuesDict] : interfacesDict)
1001 {
1002 objectPropertiesToJson(sensorName, sensorType, chassisSubNode,
1003 valuesDict, sensorJson, inventoryItem);
1004 }
Ed Tanous62598e32023-07-17 17:06:25 -07001005 BMCWEB_LOG_DEBUG("Added sensor {}", sensorName);
Ed Tanous1d7c0052022-08-09 12:32:26 -07001006}
1007
Ed Tanousb5a76932020-09-29 16:16:58 -07001008inline void populateFanRedundancy(
1009 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
James Feist8bd25cc2019-03-15 15:14:00 -07001010{
George Liue99073f2022-12-09 11:06:16 +08001011 constexpr std::array<std::string_view, 1> interfaces = {
1012 "xyz.openbmc_project.Control.FanRedundancy"};
1013 dbus::utility::getSubTree(
1014 "/xyz/openbmc_project/control", 2, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001015 [sensorsAsyncResp](
George Liue99073f2022-12-09 11:06:16 +08001016 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001017 const dbus::utility::MapperGetSubTreeResponse& resp) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001018 if (ec)
1019 {
1020 return; // don't have to have this interface
1021 }
George Liu6c3e9452023-03-03 13:55:29 +08001022 for (const std::pair<std::string, dbus::utility::MapperServiceMap>&
Ed Tanous002d39b2022-05-31 08:59:27 -07001023 pathPair : resp)
1024 {
1025 const std::string& path = pathPair.first;
George Liu6c3e9452023-03-03 13:55:29 +08001026 const dbus::utility::MapperServiceMap& objDict = pathPair.second;
Ed Tanous002d39b2022-05-31 08:59:27 -07001027 if (objDict.empty())
James Feist8bd25cc2019-03-15 15:14:00 -07001028 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001029 continue; // this should be impossible
James Feist8bd25cc2019-03-15 15:14:00 -07001030 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001031
1032 const std::string& owner = objDict.begin()->first;
George Liu6c3e9452023-03-03 13:55:29 +08001033 dbus::utility::getAssociationEndPoints(
1034 path + "/chassis",
1035 [path, owner, sensorsAsyncResp](
Ed Tanous8b242752023-06-27 17:17:13 -07001036 const boost::system::error_code& ec2,
George Liu6c3e9452023-03-03 13:55:29 +08001037 const dbus::utility::MapperEndPoints& endpoints) {
Ed Tanous8b242752023-06-27 17:17:13 -07001038 if (ec2)
James Feist8bd25cc2019-03-15 15:14:00 -07001039 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001040 return; // if they don't have an association we
1041 // can't tell what chassis is
James Feist8bd25cc2019-03-15 15:14:00 -07001042 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001043 auto found = std::ranges::find_if(
1044 endpoints, [sensorsAsyncResp](const std::string& entry) {
Patrick Williams5a39f772023-10-20 11:20:21 -05001045 return entry.find(sensorsAsyncResp->chassisId) !=
1046 std::string::npos;
1047 });
James Feist8bd25cc2019-03-15 15:14:00 -07001048
Ed Tanous002d39b2022-05-31 08:59:27 -07001049 if (found == endpoints.end())
1050 {
1051 return;
1052 }
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +02001053 sdbusplus::asio::getAllProperties(
1054 *crow::connections::systemBus, owner, path,
1055 "xyz.openbmc_project.Control.FanRedundancy",
Ed Tanous002d39b2022-05-31 08:59:27 -07001056 [path, sensorsAsyncResp](
Ed Tanous8b242752023-06-27 17:17:13 -07001057 const boost::system::error_code& ec3,
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +02001058 const dbus::utility::DBusPropertiesMap& ret) {
Ed Tanous8b242752023-06-27 17:17:13 -07001059 if (ec3)
Ed Tanous002d39b2022-05-31 08:59:27 -07001060 {
1061 return; // don't have to have this
1062 // interface
1063 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001064
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +02001065 const uint8_t* allowedFailures = nullptr;
1066 const std::vector<std::string>* collection = nullptr;
1067 const std::string* status = nullptr;
1068
1069 const bool success = sdbusplus::unpackPropertiesNoThrow(
1070 dbus_utils::UnpackErrorPrinter(), ret,
1071 "AllowedFailures", allowedFailures, "Collection",
1072 collection, "Status", status);
1073
1074 if (!success)
1075 {
1076 messages::internalError(
1077 sensorsAsyncResp->asyncResp->res);
1078 return;
1079 }
1080
1081 if (allowedFailures == nullptr || collection == nullptr ||
1082 status == nullptr)
Ed Tanous002d39b2022-05-31 08:59:27 -07001083 {
Ed Tanous62598e32023-07-17 17:06:25 -07001084 BMCWEB_LOG_ERROR("Invalid redundancy interface");
Ed Tanous002d39b2022-05-31 08:59:27 -07001085 messages::internalError(
1086 sensorsAsyncResp->asyncResp->res);
1087 return;
1088 }
1089
Ed Tanous002d39b2022-05-31 08:59:27 -07001090 sdbusplus::message::object_path objectPath(path);
1091 std::string name = objectPath.filename();
1092 if (name.empty())
1093 {
1094 // this should be impossible
1095 messages::internalError(
1096 sensorsAsyncResp->asyncResp->res);
1097 return;
1098 }
Ed Tanous18f8f602023-07-18 10:07:23 -07001099 std::ranges::replace(name, '_', ' ');
Ed Tanous002d39b2022-05-31 08:59:27 -07001100
1101 std::string health;
1102
Ed Tanous11ba3972022-07-11 09:50:41 -07001103 if (status->ends_with("Full"))
Ed Tanous002d39b2022-05-31 08:59:27 -07001104 {
1105 health = "OK";
1106 }
Ed Tanous11ba3972022-07-11 09:50:41 -07001107 else if (status->ends_with("Degraded"))
Ed Tanous002d39b2022-05-31 08:59:27 -07001108 {
1109 health = "Warning";
1110 }
1111 else
1112 {
1113 health = "Critical";
1114 }
1115 nlohmann::json::array_t redfishCollection;
1116 const auto& fanRedfish =
1117 sensorsAsyncResp->asyncResp->res.jsonValue["Fans"];
1118 for (const std::string& item : *collection)
1119 {
Ed Tanous8a592812022-06-04 09:06:59 -07001120 sdbusplus::message::object_path itemPath(item);
1121 std::string itemName = itemPath.filename();
Ed Tanous002d39b2022-05-31 08:59:27 -07001122 if (itemName.empty())
James Feist8bd25cc2019-03-15 15:14:00 -07001123 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001124 continue;
James Feist8bd25cc2019-03-15 15:14:00 -07001125 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001126 /*
1127 todo(ed): merge patch that fixes the names
1128 std::replace(itemName.begin(),
1129 itemName.end(), '_', ' ');*/
Ed Tanous3544d2a2023-08-06 18:12:20 -07001130 auto schemaItem = std::ranges::find_if(
1131 fanRedfish, [itemName](const nlohmann::json& fan) {
Patrick Williams5a39f772023-10-20 11:20:21 -05001132 return fan["Name"] == itemName;
1133 });
Ed Tanous002d39b2022-05-31 08:59:27 -07001134 if (schemaItem != fanRedfish.end())
James Feist8bd25cc2019-03-15 15:14:00 -07001135 {
Ed Tanous8a592812022-06-04 09:06:59 -07001136 nlohmann::json::object_t collectionId;
1137 collectionId["@odata.id"] =
Ed Tanous002d39b2022-05-31 08:59:27 -07001138 (*schemaItem)["@odata.id"];
1139 redfishCollection.emplace_back(
Ed Tanous8a592812022-06-04 09:06:59 -07001140 std::move(collectionId));
Ed Tanous002d39b2022-05-31 08:59:27 -07001141 }
1142 else
1143 {
Ed Tanous62598e32023-07-17 17:06:25 -07001144 BMCWEB_LOG_ERROR("failed to find fan in schema");
Ed Tanous002d39b2022-05-31 08:59:27 -07001145 messages::internalError(
1146 sensorsAsyncResp->asyncResp->res);
James Feist8bd25cc2019-03-15 15:14:00 -07001147 return;
1148 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001149 }
James Feist8bd25cc2019-03-15 15:14:00 -07001150
Patrick Williams89492a12023-05-10 07:51:34 -05001151 size_t minNumNeeded = collection->empty()
1152 ? 0
1153 : collection->size() -
1154 *allowedFailures;
Ed Tanous002d39b2022-05-31 08:59:27 -07001155 nlohmann::json& jResp = sensorsAsyncResp->asyncResp->res
1156 .jsonValue["Redundancy"];
James Feist8bd25cc2019-03-15 15:14:00 -07001157
Ed Tanous002d39b2022-05-31 08:59:27 -07001158 nlohmann::json::object_t redundancy;
Ed Tanousef4c65b2023-04-24 15:28:50 -07001159 boost::urls::url url =
1160 boost::urls::format("/redfish/v1/Chassis/{}/{}",
1161 sensorsAsyncResp->chassisId,
1162 sensorsAsyncResp->chassisSubNode);
Willy Tueddfc432022-09-26 16:46:38 +00001163 url.set_fragment(("/Redundancy"_json_pointer / jResp.size())
1164 .to_string());
1165 redundancy["@odata.id"] = std::move(url);
Ed Tanous002d39b2022-05-31 08:59:27 -07001166 redundancy["@odata.type"] = "#Redundancy.v1_3_2.Redundancy";
1167 redundancy["MinNumNeeded"] = minNumNeeded;
Ed Tanous002d39b2022-05-31 08:59:27 -07001168 redundancy["Mode"] = "N+m";
1169 redundancy["Name"] = name;
1170 redundancy["RedundancySet"] = redfishCollection;
1171 redundancy["Status"]["Health"] = health;
1172 redundancy["Status"]["State"] = "Enabled";
James Feist8bd25cc2019-03-15 15:14:00 -07001173
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001174 jResp.emplace_back(std::move(redundancy));
Ed Tanous002d39b2022-05-31 08:59:27 -07001175 });
Patrick Williams5a39f772023-10-20 11:20:21 -05001176 });
Ed Tanous002d39b2022-05-31 08:59:27 -07001177 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001178 });
James Feist8bd25cc2019-03-15 15:14:00 -07001179}
1180
Ed Tanousb5a76932020-09-29 16:16:58 -07001181inline void
Ed Tanous81ce6092020-12-17 16:54:55 +00001182 sortJSONResponse(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001183{
zhanghch058d1b46d2021-04-01 11:18:24 +08001184 nlohmann::json& response = sensorsAsyncResp->asyncResp->res.jsonValue;
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001185 std::array<std::string, 2> sensorHeaders{"Temperatures", "Fans"};
Ed Tanous81ce6092020-12-17 16:54:55 +00001186 if (sensorsAsyncResp->chassisSubNode == sensors::node::power)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001187 {
1188 sensorHeaders = {"Voltages", "PowerSupplies"};
1189 }
1190 for (const std::string& sensorGroup : sensorHeaders)
1191 {
1192 nlohmann::json::iterator entry = response.find(sensorGroup);
1193 if (entry != response.end())
1194 {
1195 std::sort(entry->begin(), entry->end(),
Ed Tanous02cad962022-06-30 16:50:15 -07001196 [](const nlohmann::json& c1, const nlohmann::json& c2) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001197 return c1["Name"] < c2["Name"];
1198 });
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001199
1200 // add the index counts to the end of each entry
1201 size_t count = 0;
1202 for (nlohmann::json& sensorJson : *entry)
1203 {
1204 nlohmann::json::iterator odata = sensorJson.find("@odata.id");
1205 if (odata == sensorJson.end())
1206 {
1207 continue;
1208 }
1209 std::string* value = odata->get_ptr<std::string*>();
1210 if (value != nullptr)
1211 {
Willy Tueddfc432022-09-26 16:46:38 +00001212 *value += "/" + std::to_string(count);
George Liu3e35c762023-03-08 16:56:38 +08001213 sensorJson["MemberId"] = std::to_string(count);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001214 count++;
Ed Tanous81ce6092020-12-17 16:54:55 +00001215 sensorsAsyncResp->updateUri(sensorJson["Name"], *value);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07001216 }
1217 }
1218 }
1219 }
1220}
1221
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01001222/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001223 * @brief Finds the inventory item with the specified object path.
1224 * @param inventoryItems D-Bus inventory items associated with sensors.
1225 * @param invItemObjPath D-Bus object path of inventory item.
1226 * @return Inventory item within vector, or nullptr if no match found.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001227 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001228inline InventoryItem* findInventoryItem(
Ed Tanousb5a76932020-09-29 16:16:58 -07001229 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001230 const std::string& invItemObjPath)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001231{
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001232 for (InventoryItem& inventoryItem : *inventoryItems)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001233 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001234 if (inventoryItem.objectPath == invItemObjPath)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001235 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001236 return &inventoryItem;
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001237 }
1238 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001239 return nullptr;
1240}
1241
1242/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001243 * @brief Finds the inventory item associated with the specified sensor.
1244 * @param inventoryItems D-Bus inventory items associated with sensors.
1245 * @param sensorObjPath D-Bus object path of sensor.
1246 * @return Inventory item within vector, or nullptr if no match found.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001247 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001248inline InventoryItem* findInventoryItemForSensor(
Ed Tanousb5a76932020-09-29 16:16:58 -07001249 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001250 const std::string& sensorObjPath)
1251{
1252 for (InventoryItem& inventoryItem : *inventoryItems)
1253 {
Ed Tanousdb0d36e2023-06-30 10:37:05 -07001254 if (inventoryItem.sensors.contains(sensorObjPath))
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001255 {
1256 return &inventoryItem;
1257 }
1258 }
1259 return nullptr;
1260}
1261
1262/**
Anthony Wilsond5005492019-07-31 16:34:17 -05001263 * @brief Finds the inventory item associated with the specified led path.
1264 * @param inventoryItems D-Bus inventory items associated with sensors.
1265 * @param ledObjPath D-Bus object path of led.
1266 * @return Inventory item within vector, or nullptr if no match found.
1267 */
1268inline InventoryItem*
1269 findInventoryItemForLed(std::vector<InventoryItem>& inventoryItems,
1270 const std::string& ledObjPath)
1271{
1272 for (InventoryItem& inventoryItem : inventoryItems)
1273 {
1274 if (inventoryItem.ledObjectPath == ledObjPath)
1275 {
1276 return &inventoryItem;
1277 }
1278 }
1279 return nullptr;
1280}
1281
1282/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001283 * @brief Adds inventory item and associated sensor to specified vector.
1284 *
1285 * Adds a new InventoryItem to the vector if necessary. Searches for an
1286 * existing InventoryItem with the specified object path. If not found, one is
1287 * added to the vector.
1288 *
1289 * Next, the specified sensor is added to the set of sensors associated with the
1290 * InventoryItem.
1291 *
1292 * @param inventoryItems D-Bus inventory items associated with sensors.
1293 * @param invItemObjPath D-Bus object path of inventory item.
1294 * @param sensorObjPath D-Bus object path of sensor
1295 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001296inline void addInventoryItem(
1297 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
1298 const std::string& invItemObjPath, const std::string& sensorObjPath)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001299{
1300 // Look for inventory item in vector
Patrick Williams89492a12023-05-10 07:51:34 -05001301 InventoryItem* inventoryItem = findInventoryItem(inventoryItems,
1302 invItemObjPath);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001303
1304 // If inventory item doesn't exist in vector, add it
1305 if (inventoryItem == nullptr)
1306 {
1307 inventoryItems->emplace_back(invItemObjPath);
1308 inventoryItem = &(inventoryItems->back());
1309 }
1310
1311 // Add sensor to set of sensors associated with inventory item
1312 inventoryItem->sensors.emplace(sensorObjPath);
1313}
1314
1315/**
1316 * @brief Stores D-Bus data in the specified inventory item.
1317 *
1318 * Finds D-Bus data in the specified map of interfaces. Stores the data in the
1319 * specified InventoryItem.
1320 *
1321 * This data is later used to provide sensor property values in the JSON
1322 * response.
1323 *
1324 * @param inventoryItem Inventory item where data will be stored.
1325 * @param interfacesDict Map containing D-Bus interfaces and their properties
1326 * for the specified inventory item.
1327 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001328inline void storeInventoryItemData(
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001329 InventoryItem& inventoryItem,
Michael Shen80f79a42023-08-24 13:41:53 +00001330 const dbus::utility::DBusInterfacesMap& interfacesDict)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001331{
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001332 // Get properties from Inventory.Item interface
Ed Tanous711ac7a2021-12-20 09:34:41 -08001333
Ed Tanous9eb808c2022-01-25 10:19:23 -08001334 for (const auto& [interface, values] : interfacesDict)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001335 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001336 if (interface == "xyz.openbmc_project.Inventory.Item")
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001337 {
Ed Tanous9eb808c2022-01-25 10:19:23 -08001338 for (const auto& [name, dbusValue] : values)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001339 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001340 if (name == "Present")
1341 {
1342 const bool* value = std::get_if<bool>(&dbusValue);
1343 if (value != nullptr)
1344 {
1345 inventoryItem.isPresent = *value;
1346 }
1347 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001348 }
1349 }
Ed Tanous711ac7a2021-12-20 09:34:41 -08001350 // Check if Inventory.Item.PowerSupply interface is present
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001351
Ed Tanous711ac7a2021-12-20 09:34:41 -08001352 if (interface == "xyz.openbmc_project.Inventory.Item.PowerSupply")
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001353 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001354 inventoryItem.isPowerSupply = true;
1355 }
1356
1357 // Get properties from Inventory.Decorator.Asset interface
1358 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
1359 {
Ed Tanous9eb808c2022-01-25 10:19:23 -08001360 for (const auto& [name, dbusValue] : values)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001361 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001362 if (name == "Manufacturer")
1363 {
1364 const std::string* value =
1365 std::get_if<std::string>(&dbusValue);
1366 if (value != nullptr)
1367 {
1368 inventoryItem.manufacturer = *value;
1369 }
1370 }
1371 if (name == "Model")
1372 {
1373 const std::string* value =
1374 std::get_if<std::string>(&dbusValue);
1375 if (value != nullptr)
1376 {
1377 inventoryItem.model = *value;
1378 }
1379 }
1380 if (name == "SerialNumber")
1381 {
1382 const std::string* value =
1383 std::get_if<std::string>(&dbusValue);
1384 if (value != nullptr)
1385 {
1386 inventoryItem.serialNumber = *value;
1387 }
1388 }
1389 if (name == "PartNumber")
1390 {
1391 const std::string* value =
1392 std::get_if<std::string>(&dbusValue);
1393 if (value != nullptr)
1394 {
1395 inventoryItem.partNumber = *value;
1396 }
1397 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001398 }
1399 }
1400
Ed Tanous711ac7a2021-12-20 09:34:41 -08001401 if (interface ==
1402 "xyz.openbmc_project.State.Decorator.OperationalStatus")
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001403 {
Ed Tanous9eb808c2022-01-25 10:19:23 -08001404 for (const auto& [name, dbusValue] : values)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001405 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001406 if (name == "Functional")
1407 {
1408 const bool* value = std::get_if<bool>(&dbusValue);
1409 if (value != nullptr)
1410 {
1411 inventoryItem.isFunctional = *value;
1412 }
1413 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001414 }
1415 }
1416 }
1417}
1418
1419/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001420 * @brief Gets D-Bus data for inventory items associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001421 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001422 * Uses the specified connections (services) to obtain D-Bus data for inventory
1423 * items associated with sensors. Stores the resulting data in the
1424 * inventoryItems vector.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001425 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001426 * This data is later used to provide sensor property values in the JSON
1427 * response.
1428 *
1429 * Finds the inventory item data asynchronously. Invokes callback when data has
1430 * been obtained.
1431 *
1432 * The callback must have the following signature:
1433 * @code
Anthony Wilsond5005492019-07-31 16:34:17 -05001434 * callback(void)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001435 * @endcode
1436 *
1437 * This function is called recursively, obtaining data asynchronously from one
1438 * connection in each call. This ensures the callback is not invoked until the
1439 * last asynchronous function has completed.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001440 *
1441 * @param sensorsAsyncResp Pointer to object holding response data.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001442 * @param inventoryItems D-Bus inventory items associated with sensors.
1443 * @param invConnections Connections that provide data for the inventory items.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001444 * implements ObjectManager.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001445 * @param callback Callback to invoke when inventory data has been obtained.
1446 * @param invConnectionsIndex Current index in invConnections. Only specified
1447 * in recursive calls to this function.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001448 */
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001449template <typename Callback>
1450static void getInventoryItemsData(
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001451 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001452 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
Ed Tanousd0090732022-10-04 17:22:56 -07001453 std::shared_ptr<std::set<std::string>> invConnections, Callback&& callback,
1454 size_t invConnectionsIndex = 0)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001455{
Ed Tanous62598e32023-07-17 17:06:25 -07001456 BMCWEB_LOG_DEBUG("getInventoryItemsData enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001457
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001458 // If no more connections left, call callback
1459 if (invConnectionsIndex >= invConnections->size())
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001460 {
Anthony Wilsond5005492019-07-31 16:34:17 -05001461 callback();
Ed Tanous62598e32023-07-17 17:06:25 -07001462 BMCWEB_LOG_DEBUG("getInventoryItemsData exit");
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001463 return;
1464 }
1465
1466 // Get inventory item data from current connection
Nan Zhoufe04d492022-06-22 17:10:41 +00001467 auto it = invConnections->begin();
1468 std::advance(it, invConnectionsIndex);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001469 if (it != invConnections->end())
1470 {
1471 const std::string& invConnection = *it;
1472
George Liu5eb468d2023-06-20 17:03:24 +08001473 // Get all object paths and their interfaces for current connection
1474 sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
1475 dbus::utility::getManagedObjects(
1476 invConnection, path,
1477 [sensorsAsyncResp, inventoryItems, invConnections,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001478 callback = std::forward<Callback>(callback), invConnectionsIndex](
George Liu5eb468d2023-06-20 17:03:24 +08001479 const boost::system::error_code& ec,
1480 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous62598e32023-07-17 17:06:25 -07001481 BMCWEB_LOG_DEBUG("getInventoryItemsData respHandler enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001482 if (ec)
1483 {
Ed Tanous62598e32023-07-17 17:06:25 -07001484 BMCWEB_LOG_ERROR(
1485 "getInventoryItemsData respHandler DBus error {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08001486 messages::internalError(sensorsAsyncResp->asyncResp->res);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001487 return;
1488 }
1489
1490 // Loop through returned object paths
1491 for (const auto& objDictEntry : resp)
1492 {
1493 const std::string& objPath =
1494 static_cast<const std::string&>(objDictEntry.first);
1495
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001496 // If this object path is one of the specified inventory items
Patrick Williams89492a12023-05-10 07:51:34 -05001497 InventoryItem* inventoryItem = findInventoryItem(inventoryItems,
1498 objPath);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001499 if (inventoryItem != nullptr)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001500 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001501 // Store inventory data in InventoryItem
1502 storeInventoryItemData(*inventoryItem, objDictEntry.second);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001503 }
1504 }
1505
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001506 // Recurse to get inventory item data from next connection
1507 getInventoryItemsData(sensorsAsyncResp, inventoryItems,
Ed Tanousd0090732022-10-04 17:22:56 -07001508 invConnections, std::move(callback),
1509 invConnectionsIndex + 1);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001510
Ed Tanous62598e32023-07-17 17:06:25 -07001511 BMCWEB_LOG_DEBUG("getInventoryItemsData respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001512 });
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001513 }
1514
Ed Tanous62598e32023-07-17 17:06:25 -07001515 BMCWEB_LOG_DEBUG("getInventoryItemsData exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001516}
1517
1518/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001519 * @brief Gets connections that provide D-Bus data for inventory items.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001520 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001521 * Gets the D-Bus connections (services) that provide data for the inventory
1522 * items that are associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001523 *
1524 * Finds the connections asynchronously. Invokes callback when information has
1525 * been obtained.
1526 *
1527 * The callback must have the following signature:
1528 * @code
Nan Zhoufe04d492022-06-22 17:10:41 +00001529 * callback(std::shared_ptr<std::set<std::string>> invConnections)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001530 * @endcode
1531 *
1532 * @param sensorsAsyncResp Pointer to object holding response data.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001533 * @param inventoryItems D-Bus inventory items associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001534 * @param callback Callback to invoke when connections have been obtained.
1535 */
1536template <typename Callback>
1537static void getInventoryItemsConnections(
Ed Tanousb5a76932020-09-29 16:16:58 -07001538 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
1539 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems,
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001540 Callback&& callback)
1541{
Ed Tanous62598e32023-07-17 17:06:25 -07001542 BMCWEB_LOG_DEBUG("getInventoryItemsConnections enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001543
1544 const std::string path = "/xyz/openbmc_project/inventory";
George Liue99073f2022-12-09 11:06:16 +08001545 constexpr std::array<std::string_view, 4> interfaces = {
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001546 "xyz.openbmc_project.Inventory.Item",
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001547 "xyz.openbmc_project.Inventory.Item.PowerSupply",
1548 "xyz.openbmc_project.Inventory.Decorator.Asset",
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001549 "xyz.openbmc_project.State.Decorator.OperationalStatus"};
1550
George Liue99073f2022-12-09 11:06:16 +08001551 // Make call to ObjectMapper to find all inventory items
1552 dbus::utility::getSubTree(
1553 path, 0, interfaces,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001554 [callback = std::forward<Callback>(callback), sensorsAsyncResp,
Ed Tanous002d39b2022-05-31 08:59:27 -07001555 inventoryItems](
George Liue99073f2022-12-09 11:06:16 +08001556 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001557 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liue99073f2022-12-09 11:06:16 +08001558 // Response handler for parsing output from GetSubTree
Ed Tanous62598e32023-07-17 17:06:25 -07001559 BMCWEB_LOG_DEBUG("getInventoryItemsConnections respHandler enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001560 if (ec)
1561 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001562 messages::internalError(sensorsAsyncResp->asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07001563 BMCWEB_LOG_ERROR(
1564 "getInventoryItemsConnections respHandler DBus error {}", ec);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001565 return;
1566 }
1567
1568 // Make unique list of connections for desired inventory items
Nan Zhoufe04d492022-06-22 17:10:41 +00001569 std::shared_ptr<std::set<std::string>> invConnections =
1570 std::make_shared<std::set<std::string>>();
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001571
1572 // Loop through objects from GetSubTree
1573 for (const std::pair<
1574 std::string,
1575 std::vector<std::pair<std::string, std::vector<std::string>>>>&
1576 object : subtree)
1577 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001578 // Check if object path is one of the specified inventory items
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001579 const std::string& objPath = object.first;
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001580 if (findInventoryItem(inventoryItems, objPath) != nullptr)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001581 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001582 // Store all connections to inventory item
1583 for (const std::pair<std::string, std::vector<std::string>>&
1584 objData : object.second)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001585 {
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001586 const std::string& invConnection = objData.first;
1587 invConnections->insert(invConnection);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001588 }
1589 }
1590 }
Anthony Wilsond5005492019-07-31 16:34:17 -05001591
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001592 callback(invConnections);
Ed Tanous62598e32023-07-17 17:06:25 -07001593 BMCWEB_LOG_DEBUG("getInventoryItemsConnections respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001594 });
Ed Tanous62598e32023-07-17 17:06:25 -07001595 BMCWEB_LOG_DEBUG("getInventoryItemsConnections exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001596}
1597
1598/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001599 * @brief Gets associations from sensors to inventory items.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001600 *
1601 * Looks for ObjectMapper associations from the specified sensors to related
Anthony Wilsond5005492019-07-31 16:34:17 -05001602 * inventory items. Then finds the associations from those inventory items to
1603 * their LEDs, if any.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001604 *
1605 * Finds the inventory items asynchronously. Invokes callback when information
1606 * has been obtained.
1607 *
1608 * The callback must have the following signature:
1609 * @code
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001610 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001611 * @endcode
1612 *
1613 * @param sensorsAsyncResp Pointer to object holding response data.
1614 * @param sensorNames All sensors within the current chassis.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001615 * implements ObjectManager.
1616 * @param callback Callback to invoke when inventory items have been obtained.
1617 */
1618template <typename Callback>
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001619static void getInventoryItemAssociations(
Ed Tanousb5a76932020-09-29 16:16:58 -07001620 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Nan Zhoufe04d492022-06-22 17:10:41 +00001621 const std::shared_ptr<std::set<std::string>>& sensorNames,
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001622 Callback&& callback)
1623{
Ed Tanous62598e32023-07-17 17:06:25 -07001624 BMCWEB_LOG_DEBUG("getInventoryItemAssociations enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001625
George Liu5eb468d2023-06-20 17:03:24 +08001626 // Call GetManagedObjects on the ObjectMapper to get all associations
1627 sdbusplus::message::object_path path("/");
1628 dbus::utility::getManagedObjects(
1629 "xyz.openbmc_project.ObjectMapper", path,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001630 [callback = std::forward<Callback>(callback), sensorsAsyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001631 sensorNames](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -07001632 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous62598e32023-07-17 17:06:25 -07001633 BMCWEB_LOG_DEBUG("getInventoryItemAssociations respHandler enter");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001634 if (ec)
1635 {
Ed Tanous62598e32023-07-17 17:06:25 -07001636 BMCWEB_LOG_ERROR(
1637 "getInventoryItemAssociations respHandler DBus error {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08001638 messages::internalError(sensorsAsyncResp->asyncResp->res);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001639 return;
1640 }
1641
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001642 // Create vector to hold list of inventory items
1643 std::shared_ptr<std::vector<InventoryItem>> inventoryItems =
1644 std::make_shared<std::vector<InventoryItem>>();
1645
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001646 // Loop through returned object paths
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001647 std::string sensorAssocPath;
1648 sensorAssocPath.reserve(128); // avoid memory allocations
1649 for (const auto& objDictEntry : resp)
1650 {
1651 const std::string& objPath =
1652 static_cast<const std::string&>(objDictEntry.first);
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001653
1654 // If path is inventory association for one of the specified sensors
1655 for (const std::string& sensorName : *sensorNames)
1656 {
1657 sensorAssocPath = sensorName;
1658 sensorAssocPath += "/inventory";
1659 if (objPath == sensorAssocPath)
1660 {
1661 // Get Association interface for object path
Ed Tanous711ac7a2021-12-20 09:34:41 -08001662 for (const auto& [interface, values] : objDictEntry.second)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001663 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001664 if (interface == "xyz.openbmc_project.Association")
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001665 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001666 for (const auto& [valueName, value] : values)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001667 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001668 if (valueName == "endpoints")
1669 {
1670 const std::vector<std::string>* endpoints =
1671 std::get_if<std::vector<std::string>>(
1672 &value);
1673 if ((endpoints != nullptr) &&
1674 !endpoints->empty())
1675 {
1676 // Add inventory item to vector
1677 const std::string& invItemPath =
1678 endpoints->front();
1679 addInventoryItem(inventoryItems,
1680 invItemPath,
1681 sensorName);
1682 }
1683 }
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001684 }
1685 }
1686 }
1687 break;
1688 }
1689 }
1690 }
1691
Anthony Wilsond5005492019-07-31 16:34:17 -05001692 // Now loop through the returned object paths again, this time to
1693 // find the leds associated with the inventory items we just found
1694 std::string inventoryAssocPath;
1695 inventoryAssocPath.reserve(128); // avoid memory allocations
1696 for (const auto& objDictEntry : resp)
1697 {
1698 const std::string& objPath =
1699 static_cast<const std::string&>(objDictEntry.first);
Anthony Wilsond5005492019-07-31 16:34:17 -05001700
1701 for (InventoryItem& inventoryItem : *inventoryItems)
1702 {
1703 inventoryAssocPath = inventoryItem.objectPath;
1704 inventoryAssocPath += "/leds";
1705 if (objPath == inventoryAssocPath)
1706 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001707 for (const auto& [interface, values] : objDictEntry.second)
Anthony Wilsond5005492019-07-31 16:34:17 -05001708 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001709 if (interface == "xyz.openbmc_project.Association")
Anthony Wilsond5005492019-07-31 16:34:17 -05001710 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001711 for (const auto& [valueName, value] : values)
Anthony Wilsond5005492019-07-31 16:34:17 -05001712 {
Ed Tanous711ac7a2021-12-20 09:34:41 -08001713 if (valueName == "endpoints")
1714 {
1715 const std::vector<std::string>* endpoints =
1716 std::get_if<std::vector<std::string>>(
1717 &value);
1718 if ((endpoints != nullptr) &&
1719 !endpoints->empty())
1720 {
1721 // Add inventory item to vector
1722 // Store LED path in inventory item
1723 const std::string& ledPath =
1724 endpoints->front();
1725 inventoryItem.ledObjectPath = ledPath;
1726 }
1727 }
Anthony Wilsond5005492019-07-31 16:34:17 -05001728 }
1729 }
1730 }
Ed Tanous711ac7a2021-12-20 09:34:41 -08001731
Anthony Wilsond5005492019-07-31 16:34:17 -05001732 break;
1733 }
1734 }
1735 }
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05001736 callback(inventoryItems);
Ed Tanous62598e32023-07-17 17:06:25 -07001737 BMCWEB_LOG_DEBUG("getInventoryItemAssociations respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001738 });
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001739
Ed Tanous62598e32023-07-17 17:06:25 -07001740 BMCWEB_LOG_DEBUG("getInventoryItemAssociations exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05001741}
1742
1743/**
Anthony Wilsond5005492019-07-31 16:34:17 -05001744 * @brief Gets D-Bus data for inventory item leds associated with sensors.
1745 *
1746 * Uses the specified connections (services) to obtain D-Bus data for inventory
1747 * item leds associated with sensors. Stores the resulting data in the
1748 * inventoryItems vector.
1749 *
1750 * This data is later used to provide sensor property values in the JSON
1751 * response.
1752 *
1753 * Finds the inventory item led data asynchronously. Invokes callback when data
1754 * has been obtained.
1755 *
1756 * The callback must have the following signature:
1757 * @code
Gunnar Mills42cbe532019-08-15 15:26:54 -05001758 * callback()
Anthony Wilsond5005492019-07-31 16:34:17 -05001759 * @endcode
1760 *
1761 * This function is called recursively, obtaining data asynchronously from one
1762 * connection in each call. This ensures the callback is not invoked until the
1763 * last asynchronous function has completed.
1764 *
1765 * @param sensorsAsyncResp Pointer to object holding response data.
1766 * @param inventoryItems D-Bus inventory items associated with sensors.
1767 * @param ledConnections Connections that provide data for the inventory leds.
1768 * @param callback Callback to invoke when inventory data has been obtained.
1769 * @param ledConnectionsIndex Current index in ledConnections. Only specified
1770 * in recursive calls to this function.
1771 */
1772template <typename Callback>
1773void getInventoryLedData(
1774 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1775 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
Nan Zhoufe04d492022-06-22 17:10:41 +00001776 std::shared_ptr<std::map<std::string, std::string>> ledConnections,
Anthony Wilsond5005492019-07-31 16:34:17 -05001777 Callback&& callback, size_t ledConnectionsIndex = 0)
1778{
Ed Tanous62598e32023-07-17 17:06:25 -07001779 BMCWEB_LOG_DEBUG("getInventoryLedData enter");
Anthony Wilsond5005492019-07-31 16:34:17 -05001780
1781 // If no more connections left, call callback
1782 if (ledConnectionsIndex >= ledConnections->size())
1783 {
Gunnar Mills42cbe532019-08-15 15:26:54 -05001784 callback();
Ed Tanous62598e32023-07-17 17:06:25 -07001785 BMCWEB_LOG_DEBUG("getInventoryLedData exit");
Anthony Wilsond5005492019-07-31 16:34:17 -05001786 return;
1787 }
1788
1789 // Get inventory item data from current connection
Nan Zhoufe04d492022-06-22 17:10:41 +00001790 auto it = ledConnections->begin();
1791 std::advance(it, ledConnectionsIndex);
Anthony Wilsond5005492019-07-31 16:34:17 -05001792 if (it != ledConnections->end())
1793 {
1794 const std::string& ledPath = (*it).first;
1795 const std::string& ledConnection = (*it).second;
1796 // Response handler for Get State property
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001797 auto respHandler =
1798 [sensorsAsyncResp, inventoryItems, ledConnections, ledPath,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001799 callback = std::forward<Callback>(callback), ledConnectionsIndex](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001800 const boost::system::error_code& ec, const std::string& state) {
Ed Tanous62598e32023-07-17 17:06:25 -07001801 BMCWEB_LOG_DEBUG("getInventoryLedData respHandler enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07001802 if (ec)
1803 {
Ed Tanous62598e32023-07-17 17:06:25 -07001804 BMCWEB_LOG_ERROR(
1805 "getInventoryLedData respHandler DBus error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07001806 messages::internalError(sensorsAsyncResp->asyncResp->res);
1807 return;
1808 }
1809
Ed Tanous62598e32023-07-17 17:06:25 -07001810 BMCWEB_LOG_DEBUG("Led state: {}", state);
Ed Tanous002d39b2022-05-31 08:59:27 -07001811 // Find inventory item with this LED object path
1812 InventoryItem* inventoryItem =
1813 findInventoryItemForLed(*inventoryItems, ledPath);
1814 if (inventoryItem != nullptr)
1815 {
1816 // Store LED state in InventoryItem
Ed Tanous11ba3972022-07-11 09:50:41 -07001817 if (state.ends_with("On"))
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001818 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001819 inventoryItem->ledState = LedState::ON;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001820 }
Ed Tanous11ba3972022-07-11 09:50:41 -07001821 else if (state.ends_with("Blink"))
Anthony Wilsond5005492019-07-31 16:34:17 -05001822 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001823 inventoryItem->ledState = LedState::BLINK;
Anthony Wilsond5005492019-07-31 16:34:17 -05001824 }
Ed Tanous11ba3972022-07-11 09:50:41 -07001825 else if (state.ends_with("Off"))
Ed Tanous002d39b2022-05-31 08:59:27 -07001826 {
1827 inventoryItem->ledState = LedState::OFF;
1828 }
1829 else
1830 {
1831 inventoryItem->ledState = LedState::UNKNOWN;
1832 }
1833 }
Anthony Wilsond5005492019-07-31 16:34:17 -05001834
Ed Tanous002d39b2022-05-31 08:59:27 -07001835 // Recurse to get LED data from next connection
1836 getInventoryLedData(sensorsAsyncResp, inventoryItems,
1837 ledConnections, std::move(callback),
1838 ledConnectionsIndex + 1);
Anthony Wilsond5005492019-07-31 16:34:17 -05001839
Ed Tanous62598e32023-07-17 17:06:25 -07001840 BMCWEB_LOG_DEBUG("getInventoryLedData respHandler exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07001841 };
Anthony Wilsond5005492019-07-31 16:34:17 -05001842
1843 // Get the State property for the current LED
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001844 sdbusplus::asio::getProperty<std::string>(
1845 *crow::connections::systemBus, ledConnection, ledPath,
1846 "xyz.openbmc_project.Led.Physical", "State",
1847 std::move(respHandler));
Anthony Wilsond5005492019-07-31 16:34:17 -05001848 }
1849
Ed Tanous62598e32023-07-17 17:06:25 -07001850 BMCWEB_LOG_DEBUG("getInventoryLedData exit");
Anthony Wilsond5005492019-07-31 16:34:17 -05001851}
1852
1853/**
1854 * @brief Gets LED data for LEDs associated with given inventory items.
1855 *
1856 * Gets the D-Bus connections (services) that provide LED data for the LEDs
1857 * associated with the specified inventory items. Then gets the LED data from
1858 * each connection and stores it in the inventory item.
1859 *
1860 * This data is later used to provide sensor property values in the JSON
1861 * response.
1862 *
1863 * Finds the LED data asynchronously. Invokes callback when information has
1864 * been obtained.
1865 *
1866 * The callback must have the following signature:
1867 * @code
Gunnar Mills42cbe532019-08-15 15:26:54 -05001868 * callback()
Anthony Wilsond5005492019-07-31 16:34:17 -05001869 * @endcode
1870 *
1871 * @param sensorsAsyncResp Pointer to object holding response data.
1872 * @param inventoryItems D-Bus inventory items associated with sensors.
1873 * @param callback Callback to invoke when inventory items have been obtained.
1874 */
1875template <typename Callback>
1876void getInventoryLeds(
1877 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
1878 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
1879 Callback&& callback)
1880{
Ed Tanous62598e32023-07-17 17:06:25 -07001881 BMCWEB_LOG_DEBUG("getInventoryLeds enter");
Anthony Wilsond5005492019-07-31 16:34:17 -05001882
1883 const std::string path = "/xyz/openbmc_project";
George Liue99073f2022-12-09 11:06:16 +08001884 constexpr std::array<std::string_view, 1> interfaces = {
Anthony Wilsond5005492019-07-31 16:34:17 -05001885 "xyz.openbmc_project.Led.Physical"};
1886
George Liue99073f2022-12-09 11:06:16 +08001887 // Make call to ObjectMapper to find all inventory items
1888 dbus::utility::getSubTree(
1889 path, 0, interfaces,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001890 [callback = std::forward<Callback>(callback), sensorsAsyncResp,
Ed Tanous002d39b2022-05-31 08:59:27 -07001891 inventoryItems](
George Liue99073f2022-12-09 11:06:16 +08001892 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07001893 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liue99073f2022-12-09 11:06:16 +08001894 // Response handler for parsing output from GetSubTree
Ed Tanous62598e32023-07-17 17:06:25 -07001895 BMCWEB_LOG_DEBUG("getInventoryLeds respHandler enter");
Anthony Wilsond5005492019-07-31 16:34:17 -05001896 if (ec)
1897 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001898 messages::internalError(sensorsAsyncResp->asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07001899 BMCWEB_LOG_ERROR("getInventoryLeds respHandler DBus error {}", ec);
Anthony Wilsond5005492019-07-31 16:34:17 -05001900 return;
1901 }
1902
1903 // Build map of LED object paths to connections
Nan Zhoufe04d492022-06-22 17:10:41 +00001904 std::shared_ptr<std::map<std::string, std::string>> ledConnections =
1905 std::make_shared<std::map<std::string, std::string>>();
Anthony Wilsond5005492019-07-31 16:34:17 -05001906
1907 // Loop through objects from GetSubTree
1908 for (const std::pair<
1909 std::string,
1910 std::vector<std::pair<std::string, std::vector<std::string>>>>&
1911 object : subtree)
1912 {
1913 // Check if object path is LED for one of the specified inventory
1914 // items
1915 const std::string& ledPath = object.first;
1916 if (findInventoryItemForLed(*inventoryItems, ledPath) != nullptr)
1917 {
1918 // Add mapping from ledPath to connection
1919 const std::string& connection = object.second.begin()->first;
1920 (*ledConnections)[ledPath] = connection;
Ed Tanous62598e32023-07-17 17:06:25 -07001921 BMCWEB_LOG_DEBUG("Added mapping {} -> {}", ledPath, connection);
Anthony Wilsond5005492019-07-31 16:34:17 -05001922 }
1923 }
1924
1925 getInventoryLedData(sensorsAsyncResp, inventoryItems, ledConnections,
1926 std::move(callback));
Ed Tanous62598e32023-07-17 17:06:25 -07001927 BMCWEB_LOG_DEBUG("getInventoryLeds respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05001928 });
Ed Tanous62598e32023-07-17 17:06:25 -07001929 BMCWEB_LOG_DEBUG("getInventoryLeds exit");
Anthony Wilsond5005492019-07-31 16:34:17 -05001930}
1931
1932/**
Gunnar Mills42cbe532019-08-15 15:26:54 -05001933 * @brief Gets D-Bus data for Power Supply Attributes such as EfficiencyPercent
1934 *
1935 * Uses the specified connections (services) (currently assumes just one) to
1936 * obtain D-Bus data for Power Supply Attributes. Stores the resulting data in
1937 * the inventoryItems vector. Only stores data in Power Supply inventoryItems.
1938 *
1939 * This data is later used to provide sensor property values in the JSON
1940 * response.
1941 *
1942 * Finds the Power Supply Attributes data asynchronously. Invokes callback
1943 * when data has been obtained.
1944 *
1945 * The callback must have the following signature:
1946 * @code
1947 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
1948 * @endcode
1949 *
1950 * @param sensorsAsyncResp Pointer to object holding response data.
1951 * @param inventoryItems D-Bus inventory items associated with sensors.
1952 * @param psAttributesConnections Connections that provide data for the Power
1953 * Supply Attributes
1954 * @param callback Callback to invoke when data has been obtained.
1955 */
1956template <typename Callback>
1957void getPowerSupplyAttributesData(
Ed Tanousb5a76932020-09-29 16:16:58 -07001958 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Gunnar Mills42cbe532019-08-15 15:26:54 -05001959 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
Nan Zhoufe04d492022-06-22 17:10:41 +00001960 const std::map<std::string, std::string>& psAttributesConnections,
Gunnar Mills42cbe532019-08-15 15:26:54 -05001961 Callback&& callback)
1962{
Ed Tanous62598e32023-07-17 17:06:25 -07001963 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05001964
1965 if (psAttributesConnections.empty())
1966 {
Ed Tanous62598e32023-07-17 17:06:25 -07001967 BMCWEB_LOG_DEBUG("Can't find PowerSupplyAttributes, no connections!");
Gunnar Mills42cbe532019-08-15 15:26:54 -05001968 callback(inventoryItems);
1969 return;
1970 }
1971
1972 // Assuming just one connection (service) for now
Nan Zhoufe04d492022-06-22 17:10:41 +00001973 auto it = psAttributesConnections.begin();
Gunnar Mills42cbe532019-08-15 15:26:54 -05001974
1975 const std::string& psAttributesPath = (*it).first;
1976 const std::string& psAttributesConnection = (*it).second;
1977
1978 // Response handler for Get DeratingFactor property
Patrick Williams5a39f772023-10-20 11:20:21 -05001979 auto respHandler = [sensorsAsyncResp, inventoryItems,
Ed Tanous8cb2c022024-03-27 16:31:46 -07001980 callback = std::forward<Callback>(callback)](
Patrick Williams5a39f772023-10-20 11:20:21 -05001981 const boost::system::error_code& ec,
1982 const uint32_t value) {
Ed Tanous62598e32023-07-17 17:06:25 -07001983 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData respHandler enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05001984 if (ec)
1985 {
Ed Tanous62598e32023-07-17 17:06:25 -07001986 BMCWEB_LOG_ERROR(
1987 "getPowerSupplyAttributesData respHandler DBus error {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08001988 messages::internalError(sensorsAsyncResp->asyncResp->res);
Gunnar Mills42cbe532019-08-15 15:26:54 -05001989 return;
1990 }
1991
Ed Tanous62598e32023-07-17 17:06:25 -07001992 BMCWEB_LOG_DEBUG("PS EfficiencyPercent value: {}", value);
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001993 // Store value in Power Supply Inventory Items
1994 for (InventoryItem& inventoryItem : *inventoryItems)
Gunnar Mills42cbe532019-08-15 15:26:54 -05001995 {
Ed Tanous55f79e62022-01-25 11:26:16 -08001996 if (inventoryItem.isPowerSupply)
Gunnar Mills42cbe532019-08-15 15:26:54 -05001997 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001998 inventoryItem.powerSupplyEfficiencyPercent =
1999 static_cast<int>(value);
Gunnar Mills42cbe532019-08-15 15:26:54 -05002000 }
2001 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002002
Ed Tanous62598e32023-07-17 17:06:25 -07002003 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData respHandler exit");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002004 callback(inventoryItems);
2005 };
2006
2007 // Get the DeratingFactor property for the PowerSupplyAttributes
2008 // Currently only property on the interface/only one we care about
Jonathan Doman1e1e5982021-06-11 09:36:17 -07002009 sdbusplus::asio::getProperty<uint32_t>(
2010 *crow::connections::systemBus, psAttributesConnection, psAttributesPath,
2011 "xyz.openbmc_project.Control.PowerSupplyAttributes", "DeratingFactor",
2012 std::move(respHandler));
Gunnar Mills42cbe532019-08-15 15:26:54 -05002013
Ed Tanous62598e32023-07-17 17:06:25 -07002014 BMCWEB_LOG_DEBUG("getPowerSupplyAttributesData exit");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002015}
2016
2017/**
2018 * @brief Gets the Power Supply Attributes such as EfficiencyPercent
2019 *
2020 * Gets the D-Bus connection (service) that provides Power Supply Attributes
2021 * data. Then gets the Power Supply Attributes data from the connection
2022 * (currently just assumes 1 connection) and stores the data in the inventory
2023 * item.
2024 *
2025 * This data is later used to provide sensor property values in the JSON
2026 * response. DeratingFactor on D-Bus is mapped to EfficiencyPercent on Redfish.
2027 *
2028 * Finds the Power Supply Attributes data asynchronously. Invokes callback
2029 * when information has been obtained.
2030 *
2031 * The callback must have the following signature:
2032 * @code
2033 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
2034 * @endcode
2035 *
2036 * @param sensorsAsyncResp Pointer to object holding response data.
2037 * @param inventoryItems D-Bus inventory items associated with sensors.
2038 * @param callback Callback to invoke when data has been obtained.
2039 */
2040template <typename Callback>
2041void getPowerSupplyAttributes(
2042 std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
2043 std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
2044 Callback&& callback)
2045{
Ed Tanous62598e32023-07-17 17:06:25 -07002046 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002047
2048 // Only need the power supply attributes when the Power Schema
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002049 if (sensorsAsyncResp->chassisSubNode != sensors::node::power)
Gunnar Mills42cbe532019-08-15 15:26:54 -05002050 {
Ed Tanous62598e32023-07-17 17:06:25 -07002051 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes exit since not Power");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002052 callback(inventoryItems);
2053 return;
2054 }
2055
George Liue99073f2022-12-09 11:06:16 +08002056 constexpr std::array<std::string_view, 1> interfaces = {
Gunnar Mills42cbe532019-08-15 15:26:54 -05002057 "xyz.openbmc_project.Control.PowerSupplyAttributes"};
2058
George Liue99073f2022-12-09 11:06:16 +08002059 // Make call to ObjectMapper to find the PowerSupplyAttributes service
2060 dbus::utility::getSubTree(
2061 "/xyz/openbmc_project", 0, interfaces,
Ed Tanous8cb2c022024-03-27 16:31:46 -07002062 [callback = std::forward<Callback>(callback), sensorsAsyncResp,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002063 inventoryItems](
George Liue99073f2022-12-09 11:06:16 +08002064 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002065 const dbus::utility::MapperGetSubTreeResponse& subtree) {
George Liue99073f2022-12-09 11:06:16 +08002066 // Response handler for parsing output from GetSubTree
Ed Tanous62598e32023-07-17 17:06:25 -07002067 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes respHandler enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002068 if (ec)
2069 {
2070 messages::internalError(sensorsAsyncResp->asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07002071 BMCWEB_LOG_ERROR(
2072 "getPowerSupplyAttributes respHandler DBus error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -07002073 return;
2074 }
2075 if (subtree.empty())
2076 {
Ed Tanous62598e32023-07-17 17:06:25 -07002077 BMCWEB_LOG_DEBUG("Can't find Power Supply Attributes!");
Ed Tanous002d39b2022-05-31 08:59:27 -07002078 callback(inventoryItems);
2079 return;
2080 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002081
Ed Tanous002d39b2022-05-31 08:59:27 -07002082 // Currently we only support 1 power supply attribute, use this for
2083 // all the power supplies. Build map of object path to connection.
2084 // Assume just 1 connection and 1 path for now.
Nan Zhoufe04d492022-06-22 17:10:41 +00002085 std::map<std::string, std::string> psAttributesConnections;
Gunnar Mills42cbe532019-08-15 15:26:54 -05002086
Ed Tanous002d39b2022-05-31 08:59:27 -07002087 if (subtree[0].first.empty() || subtree[0].second.empty())
2088 {
Ed Tanous62598e32023-07-17 17:06:25 -07002089 BMCWEB_LOG_DEBUG("Power Supply Attributes mapper error!");
Ed Tanous002d39b2022-05-31 08:59:27 -07002090 callback(inventoryItems);
2091 return;
2092 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002093
Ed Tanous002d39b2022-05-31 08:59:27 -07002094 const std::string& psAttributesPath = subtree[0].first;
2095 const std::string& connection = subtree[0].second.begin()->first;
Gunnar Mills42cbe532019-08-15 15:26:54 -05002096
Ed Tanous002d39b2022-05-31 08:59:27 -07002097 if (connection.empty())
2098 {
Ed Tanous62598e32023-07-17 17:06:25 -07002099 BMCWEB_LOG_DEBUG("Power Supply Attributes mapper error!");
Ed Tanous002d39b2022-05-31 08:59:27 -07002100 callback(inventoryItems);
2101 return;
2102 }
Gunnar Mills42cbe532019-08-15 15:26:54 -05002103
Ed Tanous002d39b2022-05-31 08:59:27 -07002104 psAttributesConnections[psAttributesPath] = connection;
Ed Tanous62598e32023-07-17 17:06:25 -07002105 BMCWEB_LOG_DEBUG("Added mapping {} -> {}", psAttributesPath,
2106 connection);
Gunnar Mills42cbe532019-08-15 15:26:54 -05002107
Ed Tanous002d39b2022-05-31 08:59:27 -07002108 getPowerSupplyAttributesData(sensorsAsyncResp, inventoryItems,
2109 psAttributesConnections,
2110 std::move(callback));
Ed Tanous62598e32023-07-17 17:06:25 -07002111 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes respHandler exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05002112 });
Ed Tanous62598e32023-07-17 17:06:25 -07002113 BMCWEB_LOG_DEBUG("getPowerSupplyAttributes exit");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002114}
2115
2116/**
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002117 * @brief Gets inventory items associated with sensors.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002118 *
2119 * Finds the inventory items that are associated with the specified sensors.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002120 * Then gets D-Bus data for the inventory items, such as presence and VPD.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002121 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002122 * This data is later used to provide sensor property values in the JSON
2123 * response.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002124 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002125 * Finds the inventory items asynchronously. Invokes callback when the
2126 * inventory items have been obtained.
2127 *
2128 * The callback must have the following signature:
2129 * @code
2130 * callback(std::shared_ptr<std::vector<InventoryItem>> inventoryItems)
2131 * @endcode
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002132 *
2133 * @param sensorsAsyncResp Pointer to object holding response data.
2134 * @param sensorNames All sensors within the current chassis.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002135 * implements ObjectManager.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002136 * @param callback Callback to invoke when inventory items have been obtained.
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002137 */
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002138template <typename Callback>
Ed Tanousd0090732022-10-04 17:22:56 -07002139static void
2140 getInventoryItems(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
2141 const std::shared_ptr<std::set<std::string>> sensorNames,
2142 Callback&& callback)
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002143{
Ed Tanous62598e32023-07-17 17:06:25 -07002144 BMCWEB_LOG_DEBUG("getInventoryItems enter");
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002145 auto getInventoryItemAssociationsCb =
Ed Tanous8cb2c022024-03-27 16:31:46 -07002146 [sensorsAsyncResp, callback = std::forward<Callback>(callback)](
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002147 std::shared_ptr<std::vector<InventoryItem>> inventoryItems) {
Ed Tanous62598e32023-07-17 17:06:25 -07002148 BMCWEB_LOG_DEBUG("getInventoryItemAssociationsCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002149 auto getInventoryItemsConnectionsCb =
Ed Tanousd0090732022-10-04 17:22:56 -07002150 [sensorsAsyncResp, inventoryItems,
Ed Tanous8cb2c022024-03-27 16:31:46 -07002151 callback = std::forward<const Callback>(callback)](
Nan Zhoufe04d492022-06-22 17:10:41 +00002152 std::shared_ptr<std::set<std::string>> invConnections) {
Ed Tanous62598e32023-07-17 17:06:25 -07002153 BMCWEB_LOG_DEBUG("getInventoryItemsConnectionsCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002154 auto getInventoryItemsDataCb = [sensorsAsyncResp, inventoryItems,
2155 callback{std::move(callback)}]() {
Ed Tanous62598e32023-07-17 17:06:25 -07002156 BMCWEB_LOG_DEBUG("getInventoryItemsDataCb enter");
Gunnar Mills42cbe532019-08-15 15:26:54 -05002157
Ed Tanous002d39b2022-05-31 08:59:27 -07002158 auto getInventoryLedsCb = [sensorsAsyncResp, inventoryItems,
2159 callback{std::move(callback)}]() {
Ed Tanous62598e32023-07-17 17:06:25 -07002160 BMCWEB_LOG_DEBUG("getInventoryLedsCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002161 // Find Power Supply Attributes and get the data
2162 getPowerSupplyAttributes(sensorsAsyncResp, inventoryItems,
2163 std::move(callback));
Ed Tanous62598e32023-07-17 17:06:25 -07002164 BMCWEB_LOG_DEBUG("getInventoryLedsCb exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002165 };
2166
Ed Tanous002d39b2022-05-31 08:59:27 -07002167 // Find led connections and get the data
2168 getInventoryLeds(sensorsAsyncResp, inventoryItems,
2169 std::move(getInventoryLedsCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002170 BMCWEB_LOG_DEBUG("getInventoryItemsDataCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002171 };
2172
2173 // Get inventory item data from connections
2174 getInventoryItemsData(sensorsAsyncResp, inventoryItems,
Ed Tanousd0090732022-10-04 17:22:56 -07002175 invConnections,
Ed Tanous002d39b2022-05-31 08:59:27 -07002176 std::move(getInventoryItemsDataCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002177 BMCWEB_LOG_DEBUG("getInventoryItemsConnectionsCb exit");
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002178 };
2179
Ed Tanous002d39b2022-05-31 08:59:27 -07002180 // Get connections that provide inventory item data
2181 getInventoryItemsConnections(sensorsAsyncResp, inventoryItems,
2182 std::move(getInventoryItemsConnectionsCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002183 BMCWEB_LOG_DEBUG("getInventoryItemAssociationsCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002184 };
2185
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002186 // Get associations from sensors to inventory items
Ed Tanousd0090732022-10-04 17:22:56 -07002187 getInventoryItemAssociations(sensorsAsyncResp, sensorNames,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002188 std::move(getInventoryItemAssociationsCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002189 BMCWEB_LOG_DEBUG("getInventoryItems exit");
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002190}
2191
2192/**
2193 * @brief Returns JSON PowerSupply object for the specified inventory item.
2194 *
2195 * Searches for a JSON PowerSupply object that matches the specified inventory
2196 * item. If one is not found, a new PowerSupply object is added to the JSON
2197 * array.
2198 *
2199 * Multiple sensors are often associated with one power supply inventory item.
2200 * As a result, multiple sensor values are stored in one JSON PowerSupply
2201 * object.
2202 *
2203 * @param powerSupplyArray JSON array containing Redfish PowerSupply objects.
2204 * @param inventoryItem Inventory item for the power supply.
2205 * @param chassisId Chassis that contains the power supply.
2206 * @return JSON PowerSupply object for the specified inventory item.
2207 */
Ed Tanous23a21a12020-07-25 04:45:05 +00002208inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002209 const InventoryItem& inventoryItem,
2210 const std::string& chassisId)
2211{
Ed Tanous18f8f602023-07-18 10:07:23 -07002212 std::string nameS;
Alexander Hansen6f4bd292024-03-08 17:04:54 +01002213 nameS.resize(inventoryItem.name.size());
Ed Tanous18f8f602023-07-18 10:07:23 -07002214 std::ranges::replace_copy(inventoryItem.name, nameS.begin(), '_', ' ');
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002215 // Check if matching PowerSupply object already exists in JSON array
2216 for (nlohmann::json& powerSupply : powerSupplyArray)
2217 {
Ed Tanous18f8f602023-07-18 10:07:23 -07002218 nlohmann::json::iterator nameIt = powerSupply.find("Name");
2219 if (nameIt == powerSupply.end())
2220 {
2221 continue;
2222 }
2223 const std::string* name = nameIt->get_ptr<std::string*>();
2224 if (name == nullptr)
2225 {
2226 continue;
2227 }
2228 if (nameS == *name)
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002229 {
2230 return powerSupply;
2231 }
2232 }
2233
2234 // Add new PowerSupply object to JSON array
2235 powerSupplyArray.push_back({});
2236 nlohmann::json& powerSupply = powerSupplyArray.back();
Ed Tanousef4c65b2023-04-24 15:28:50 -07002237 boost::urls::url url = boost::urls::format("/redfish/v1/Chassis/{}/Power",
2238 chassisId);
Willy Tueddfc432022-09-26 16:46:38 +00002239 url.set_fragment(("/PowerSupplies"_json_pointer).to_string());
2240 powerSupply["@odata.id"] = std::move(url);
Ed Tanous18f8f602023-07-18 10:07:23 -07002241 std::string escaped;
Alexander Hansen6f4bd292024-03-08 17:04:54 +01002242 escaped.resize(inventoryItem.name.size());
Ed Tanous18f8f602023-07-18 10:07:23 -07002243 std::ranges::replace_copy(inventoryItem.name, escaped.begin(), '_', ' ');
2244 powerSupply["Name"] = std::move(escaped);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002245 powerSupply["Manufacturer"] = inventoryItem.manufacturer;
2246 powerSupply["Model"] = inventoryItem.model;
2247 powerSupply["PartNumber"] = inventoryItem.partNumber;
2248 powerSupply["SerialNumber"] = inventoryItem.serialNumber;
Anthony Wilsond5005492019-07-31 16:34:17 -05002249 setLedState(powerSupply, &inventoryItem);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002250
Gunnar Mills42cbe532019-08-15 15:26:54 -05002251 if (inventoryItem.powerSupplyEfficiencyPercent >= 0)
2252 {
2253 powerSupply["EfficiencyPercent"] =
2254 inventoryItem.powerSupplyEfficiencyPercent;
2255 }
2256
Matt Simmeringaaf08ac2023-10-04 08:41:01 -07002257 powerSupply["Status"]["State"] = getState(&inventoryItem, true);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002258 const char* health = inventoryItem.isFunctional ? "OK" : "Critical";
2259 powerSupply["Status"]["Health"] = health;
2260
2261 return powerSupply;
Shawn McCarney8fb49dd2019-06-12 17:47:00 -05002262}
2263
2264/**
Shawn McCarneyde629b62019-03-08 10:42:51 -06002265 * @brief Gets the values of the specified sensors.
2266 *
2267 * Stores the results as JSON in the SensorsAsyncResp.
2268 *
2269 * Gets the sensor values asynchronously. Stores the results later when the
2270 * information has been obtained.
2271 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002272 * The sensorNames set contains all requested sensors for the current chassis.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002273 *
2274 * To minimize the number of DBus calls, the DBus method
2275 * org.freedesktop.DBus.ObjectManager.GetManagedObjects() is used to get the
2276 * values of all sensors provided by a connection (service).
2277 *
2278 * The connections set contains all the connections that provide sensor values.
2279 *
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002280 * The InventoryItem vector contains D-Bus inventory items associated with the
2281 * sensors. Inventory item data is needed for some Redfish sensor properties.
2282 *
Shawn McCarneyde629b62019-03-08 10:42:51 -06002283 * @param SensorsAsyncResp Pointer to object holding response data.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002284 * @param sensorNames All requested sensors within the current chassis.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002285 * @param connections Connections that provide sensor values.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002286 * implements ObjectManager.
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002287 * @param inventoryItems Inventory items associated with the sensors.
Shawn McCarneyde629b62019-03-08 10:42:51 -06002288 */
Ed Tanous23a21a12020-07-25 04:45:05 +00002289inline void getSensorData(
Ed Tanous81ce6092020-12-17 16:54:55 +00002290 const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
Nan Zhoufe04d492022-06-22 17:10:41 +00002291 const std::shared_ptr<std::set<std::string>>& sensorNames,
2292 const std::set<std::string>& connections,
Ed Tanousb5a76932020-09-29 16:16:58 -07002293 const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems)
Shawn McCarneyde629b62019-03-08 10:42:51 -06002294{
Ed Tanous62598e32023-07-17 17:06:25 -07002295 BMCWEB_LOG_DEBUG("getSensorData enter");
Shawn McCarneyde629b62019-03-08 10:42:51 -06002296 // Get managed objects from all services exposing sensors
2297 for (const std::string& connection : connections)
2298 {
George Liu5eb468d2023-06-20 17:03:24 +08002299 sdbusplus::message::object_path sensorPath(
2300 "/xyz/openbmc_project/sensors");
2301 dbus::utility::getManagedObjects(
2302 connection, sensorPath,
Ed Tanous002d39b2022-05-31 08:59:27 -07002303 [sensorsAsyncResp, sensorNames,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002304 inventoryItems](const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -07002305 const dbus::utility::ManagedObjectType& resp) {
Ed Tanous62598e32023-07-17 17:06:25 -07002306 BMCWEB_LOG_DEBUG("getManagedObjectsCb enter");
Shawn McCarneyde629b62019-03-08 10:42:51 -06002307 if (ec)
2308 {
Ed Tanous62598e32023-07-17 17:06:25 -07002309 BMCWEB_LOG_ERROR("getManagedObjectsCb DBUS error: {}", ec);
zhanghch058d1b46d2021-04-01 11:18:24 +08002310 messages::internalError(sensorsAsyncResp->asyncResp->res);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002311 return;
2312 }
2313 // Go through all objects and update response with sensor data
2314 for (const auto& objDictEntry : resp)
2315 {
2316 const std::string& objPath =
2317 static_cast<const std::string&>(objDictEntry.first);
Ed Tanous62598e32023-07-17 17:06:25 -07002318 BMCWEB_LOG_DEBUG("getManagedObjectsCb parsing object {}",
2319 objPath);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002320
Shawn McCarneyde629b62019-03-08 10:42:51 -06002321 std::vector<std::string> split;
2322 // Reserve space for
2323 // /xyz/openbmc_project/sensors/<name>/<subname>
2324 split.reserve(6);
Ed Tanous50ebd4a2023-01-19 19:03:17 -08002325 // NOLINTNEXTLINE
2326 bmcweb::split(split, objPath, '/');
Shawn McCarneyde629b62019-03-08 10:42:51 -06002327 if (split.size() < 6)
2328 {
Ed Tanous62598e32023-07-17 17:06:25 -07002329 BMCWEB_LOG_ERROR("Got path that isn't long enough {}",
2330 objPath);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002331 continue;
2332 }
Ed Tanous50ebd4a2023-01-19 19:03:17 -08002333 // These indexes aren't intuitive, as split puts an empty
Shawn McCarneyde629b62019-03-08 10:42:51 -06002334 // string at the beginning
2335 const std::string& sensorType = split[4];
2336 const std::string& sensorName = split[5];
Ed Tanous62598e32023-07-17 17:06:25 -07002337 BMCWEB_LOG_DEBUG("sensorName {} sensorType {}", sensorName,
2338 sensorType);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002339 if (sensorNames->find(objPath) == sensorNames->end())
Shawn McCarneyde629b62019-03-08 10:42:51 -06002340 {
Ed Tanous62598e32023-07-17 17:06:25 -07002341 BMCWEB_LOG_DEBUG("{} not in sensor list ", sensorName);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002342 continue;
2343 }
2344
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002345 // Find inventory item (if any) associated with sensor
2346 InventoryItem* inventoryItem =
2347 findInventoryItemForSensor(inventoryItems, objPath);
2348
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002349 const std::string& sensorSchema =
Ed Tanous81ce6092020-12-17 16:54:55 +00002350 sensorsAsyncResp->chassisSubNode;
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002351
2352 nlohmann::json* sensorJson = nullptr;
2353
Nan Zhou928fefb2022-03-28 08:45:00 -07002354 if (sensorSchema == sensors::node::sensors &&
2355 !sensorsAsyncResp->efficientExpand)
Shawn McCarneyde629b62019-03-08 10:42:51 -06002356 {
Ed Tanousc1d019a2022-08-06 09:36:06 -07002357 std::string sensorTypeEscaped(sensorType);
Ed Tanous3544d2a2023-08-06 18:12:20 -07002358 auto remove = std::ranges::remove(sensorTypeEscaped, '_');
2359
2360 sensorTypeEscaped.erase(std::ranges::begin(remove),
2361 sensorTypeEscaped.end());
Ed Tanousc1d019a2022-08-06 09:36:06 -07002362 std::string sensorId(sensorTypeEscaped);
2363 sensorId += "_";
2364 sensorId += sensorName;
2365
zhanghch058d1b46d2021-04-01 11:18:24 +08002366 sensorsAsyncResp->asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -07002367 boost::urls::format("/redfish/v1/Chassis/{}/{}/{}",
2368 sensorsAsyncResp->chassisId,
2369 sensorsAsyncResp->chassisSubNode,
2370 sensorId);
zhanghch058d1b46d2021-04-01 11:18:24 +08002371 sensorJson = &(sensorsAsyncResp->asyncResp->res.jsonValue);
Shawn McCarneyde629b62019-03-08 10:42:51 -06002372 }
2373 else
2374 {
Ed Tanous271584a2019-07-09 16:24:22 -07002375 std::string fieldName;
Nan Zhou928fefb2022-03-28 08:45:00 -07002376 if (sensorsAsyncResp->efficientExpand)
2377 {
2378 fieldName = "Members";
2379 }
2380 else if (sensorType == "temperature")
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002381 {
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002382 fieldName = "Temperatures";
2383 }
2384 else if (sensorType == "fan" || sensorType == "fan_tach" ||
2385 sensorType == "fan_pwm")
2386 {
2387 fieldName = "Fans";
2388 }
2389 else if (sensorType == "voltage")
2390 {
2391 fieldName = "Voltages";
2392 }
2393 else if (sensorType == "power")
2394 {
Ed Tanous55f79e62022-01-25 11:26:16 -08002395 if (sensorName == "total_power")
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002396 {
2397 fieldName = "PowerControl";
2398 }
2399 else if ((inventoryItem != nullptr) &&
2400 (inventoryItem->isPowerSupply))
2401 {
2402 fieldName = "PowerSupplies";
2403 }
2404 else
2405 {
2406 // Other power sensors are in SensorCollection
2407 continue;
2408 }
2409 }
2410 else
2411 {
Ed Tanous62598e32023-07-17 17:06:25 -07002412 BMCWEB_LOG_ERROR("Unsure how to handle sensorType {}",
2413 sensorType);
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002414 continue;
2415 }
2416
2417 nlohmann::json& tempArray =
zhanghch058d1b46d2021-04-01 11:18:24 +08002418 sensorsAsyncResp->asyncResp->res.jsonValue[fieldName];
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002419 if (fieldName == "PowerControl")
2420 {
2421 if (tempArray.empty())
2422 {
2423 // Put multiple "sensors" into a single
2424 // PowerControl. Follows MemberId naming and
2425 // naming in power.hpp.
Ed Tanous14766872022-03-15 10:44:42 -07002426 nlohmann::json::object_t power;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002427 boost::urls::url url = boost::urls::format(
2428 "/redfish/v1/Chassis/{}/{}",
Willy Tueddfc432022-09-26 16:46:38 +00002429 sensorsAsyncResp->chassisId,
2430 sensorsAsyncResp->chassisSubNode);
2431 url.set_fragment((""_json_pointer / fieldName / "0")
2432 .to_string());
2433 power["@odata.id"] = std::move(url);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002434 tempArray.emplace_back(std::move(power));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002435 }
2436 sensorJson = &(tempArray.back());
2437 }
2438 else if (fieldName == "PowerSupplies")
2439 {
2440 if (inventoryItem != nullptr)
2441 {
2442 sensorJson =
2443 &(getPowerSupply(tempArray, *inventoryItem,
Ed Tanous81ce6092020-12-17 16:54:55 +00002444 sensorsAsyncResp->chassisId));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002445 }
2446 }
Nan Zhou928fefb2022-03-28 08:45:00 -07002447 else if (fieldName == "Members")
2448 {
Ed Tanous677bb752022-09-15 10:52:19 -07002449 std::string sensorTypeEscaped(sensorType);
Ed Tanous3544d2a2023-08-06 18:12:20 -07002450 auto remove = std::ranges::remove(sensorTypeEscaped,
2451 '_');
2452 sensorTypeEscaped.erase(std::ranges::begin(remove),
2453 sensorTypeEscaped.end());
Ed Tanous677bb752022-09-15 10:52:19 -07002454 std::string sensorId(sensorTypeEscaped);
2455 sensorId += "_";
2456 sensorId += sensorName;
2457
Ed Tanous14766872022-03-15 10:44:42 -07002458 nlohmann::json::object_t member;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002459 member["@odata.id"] = boost::urls::format(
2460 "/redfish/v1/Chassis/{}/{}/{}",
Ed Tanous677bb752022-09-15 10:52:19 -07002461 sensorsAsyncResp->chassisId,
2462 sensorsAsyncResp->chassisSubNode, sensorId);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002463 tempArray.emplace_back(std::move(member));
Nan Zhou928fefb2022-03-28 08:45:00 -07002464 sensorJson = &(tempArray.back());
2465 }
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002466 else
2467 {
Ed Tanous14766872022-03-15 10:44:42 -07002468 nlohmann::json::object_t member;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002469 boost::urls::url url = boost::urls::format(
2470 "/redfish/v1/Chassis/{}/{}",
Willy Tueddfc432022-09-26 16:46:38 +00002471 sensorsAsyncResp->chassisId,
2472 sensorsAsyncResp->chassisSubNode);
2473 url.set_fragment(
2474 (""_json_pointer / fieldName).to_string());
2475 member["@odata.id"] = std::move(url);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002476 tempArray.emplace_back(std::move(member));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002477 sensorJson = &(tempArray.back());
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002478 }
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002479 }
Shawn McCarneyde629b62019-03-08 10:42:51 -06002480
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002481 if (sensorJson != nullptr)
2482 {
Ed Tanous1d7c0052022-08-09 12:32:26 -07002483 objectInterfacesToJson(sensorName, sensorType,
2484 sensorsAsyncResp->chassisSubNode,
2485 objDictEntry.second, *sensorJson,
2486 inventoryItem);
2487
2488 std::string path = "/xyz/openbmc_project/sensors/";
2489 path += sensorType;
2490 path += "/";
2491 path += sensorName;
Ed Tanousc1d019a2022-08-06 09:36:06 -07002492 sensorsAsyncResp->addMetadata(*sensorJson, path);
Shawn McCarneyadc4f0d2019-07-24 09:21:50 -05002493 }
Shawn McCarneyde629b62019-03-08 10:42:51 -06002494 }
Ed Tanous81ce6092020-12-17 16:54:55 +00002495 if (sensorsAsyncResp.use_count() == 1)
James Feist8bd25cc2019-03-15 15:14:00 -07002496 {
Ed Tanous81ce6092020-12-17 16:54:55 +00002497 sortJSONResponse(sensorsAsyncResp);
Nan Zhou928fefb2022-03-28 08:45:00 -07002498 if (sensorsAsyncResp->chassisSubNode ==
2499 sensors::node::sensors &&
2500 sensorsAsyncResp->efficientExpand)
2501 {
2502 sensorsAsyncResp->asyncResp->res
2503 .jsonValue["Members@odata.count"] =
2504 sensorsAsyncResp->asyncResp->res.jsonValue["Members"]
2505 .size();
2506 }
2507 else if (sensorsAsyncResp->chassisSubNode ==
2508 sensors::node::thermal)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002509 {
Ed Tanous81ce6092020-12-17 16:54:55 +00002510 populateFanRedundancy(sensorsAsyncResp);
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002511 }
James Feist8bd25cc2019-03-15 15:14:00 -07002512 }
Ed Tanous62598e32023-07-17 17:06:25 -07002513 BMCWEB_LOG_DEBUG("getManagedObjectsCb exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05002514 });
Ed Tanous23a21a12020-07-25 04:45:05 +00002515 }
Ed Tanous62598e32023-07-17 17:06:25 -07002516 BMCWEB_LOG_DEBUG("getSensorData exit");
Shawn McCarneyde629b62019-03-08 10:42:51 -06002517}
2518
Nan Zhoufe04d492022-06-22 17:10:41 +00002519inline void
2520 processSensorList(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
2521 const std::shared_ptr<std::set<std::string>>& sensorNames)
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002522{
Nan Zhoufe04d492022-06-22 17:10:41 +00002523 auto getConnectionCb = [sensorsAsyncResp, sensorNames](
2524 const std::set<std::string>& connections) {
Ed Tanous62598e32023-07-17 17:06:25 -07002525 BMCWEB_LOG_DEBUG("getConnectionCb enter");
Ed Tanousd0090732022-10-04 17:22:56 -07002526 auto getInventoryItemsCb =
2527 [sensorsAsyncResp, sensorNames,
2528 connections](const std::shared_ptr<std::vector<InventoryItem>>&
2529 inventoryItems) {
Ed Tanous62598e32023-07-17 17:06:25 -07002530 BMCWEB_LOG_DEBUG("getInventoryItemsCb enter");
Ed Tanousd0090732022-10-04 17:22:56 -07002531 // Get sensor data and store results in JSON
2532 getSensorData(sensorsAsyncResp, sensorNames, connections,
2533 inventoryItems);
Ed Tanous62598e32023-07-17 17:06:25 -07002534 BMCWEB_LOG_DEBUG("getInventoryItemsCb exit");
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002535 };
2536
Ed Tanousd0090732022-10-04 17:22:56 -07002537 // Get inventory items associated with sensors
2538 getInventoryItems(sensorsAsyncResp, sensorNames,
2539 std::move(getInventoryItemsCb));
2540
Ed Tanous62598e32023-07-17 17:06:25 -07002541 BMCWEB_LOG_DEBUG("getConnectionCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002542 };
2543
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002544 // Get set of connections that provide sensor values
Ed Tanous81ce6092020-12-17 16:54:55 +00002545 getConnections(sensorsAsyncResp, sensorNames, std::move(getConnectionCb));
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002546}
2547
Shawn McCarneyde629b62019-03-08 10:42:51 -06002548/**
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01002549 * @brief Entry point for retrieving sensors data related to requested
2550 * chassis.
Kowalski, Kamil588c3f02018-04-03 14:55:27 +02002551 * @param SensorsAsyncResp Pointer to object holding response data
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01002552 */
Ed Tanousb5a76932020-09-29 16:16:58 -07002553inline void
Ed Tanous81ce6092020-12-17 16:54:55 +00002554 getChassisData(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07002555{
Ed Tanous62598e32023-07-17 17:06:25 -07002556 BMCWEB_LOG_DEBUG("getChassisData enter");
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002557 auto getChassisCb =
Ed Tanous81ce6092020-12-17 16:54:55 +00002558 [sensorsAsyncResp](
Nan Zhoufe04d492022-06-22 17:10:41 +00002559 const std::shared_ptr<std::set<std::string>>& sensorNames) {
Ed Tanous62598e32023-07-17 17:06:25 -07002560 BMCWEB_LOG_DEBUG("getChassisCb enter");
Ed Tanous002d39b2022-05-31 08:59:27 -07002561 processSensorList(sensorsAsyncResp, sensorNames);
Ed Tanous62598e32023-07-17 17:06:25 -07002562 BMCWEB_LOG_DEBUG("getChassisCb exit");
Ed Tanous002d39b2022-05-31 08:59:27 -07002563 };
Nan Zhou928fefb2022-03-28 08:45:00 -07002564 // SensorCollection doesn't contain the Redundancy property
2565 if (sensorsAsyncResp->chassisSubNode != sensors::node::sensors)
2566 {
2567 sensorsAsyncResp->asyncResp->res.jsonValue["Redundancy"] =
2568 nlohmann::json::array();
2569 }
Shawn McCarney26f03892019-05-03 13:20:24 -05002570 // Get set of sensors in chassis
Ed Tanous7f1cc262022-08-09 13:33:57 -07002571 getChassis(sensorsAsyncResp->asyncResp, sensorsAsyncResp->chassisId,
2572 sensorsAsyncResp->chassisSubNode, sensorsAsyncResp->types,
2573 std::move(getChassisCb));
Ed Tanous62598e32023-07-17 17:06:25 -07002574 BMCWEB_LOG_DEBUG("getChassisData exit");
Ed Tanous271584a2019-07-09 16:24:22 -07002575}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01002576
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302577/**
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002578 * @brief Find the requested sensorName in the list of all sensors supplied by
2579 * the chassis node
2580 *
2581 * @param sensorName The sensor name supplied in the PATCH request
2582 * @param sensorsList The list of sensors managed by the chassis node
2583 * @param sensorsModified The list of sensors that were found as a result of
2584 * repeated calls to this function
2585 */
Nan Zhoufe04d492022-06-22 17:10:41 +00002586inline bool
2587 findSensorNameUsingSensorPath(std::string_view sensorName,
Ed Tanous02cad962022-06-30 16:50:15 -07002588 const std::set<std::string>& sensorsList,
Nan Zhoufe04d492022-06-22 17:10:41 +00002589 std::set<std::string>& sensorsModified)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002590{
Nan Zhoufe04d492022-06-22 17:10:41 +00002591 for (const auto& chassisSensor : sensorsList)
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002592 {
George Liu28aa8de2021-02-01 15:13:30 +08002593 sdbusplus::message::object_path path(chassisSensor);
Ed Tanousb00dcc22021-02-23 12:52:50 -08002594 std::string thisSensorName = path.filename();
George Liu28aa8de2021-02-01 15:13:30 +08002595 if (thisSensorName.empty())
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002596 {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002597 continue;
2598 }
2599 if (thisSensorName == sensorName)
2600 {
2601 sensorsModified.emplace(chassisSensor);
2602 return true;
2603 }
2604 }
2605 return false;
2606}
2607
Ed Tanousc71d6122022-11-29 14:10:32 -08002608inline std::pair<std::string, std::string>
2609 splitSensorNameAndType(std::string_view sensorId)
2610{
2611 size_t index = sensorId.find('_');
2612 if (index == std::string::npos)
2613 {
2614 return std::make_pair<std::string, std::string>("", "");
2615 }
2616 std::string sensorType{sensorId.substr(0, index)};
2617 std::string sensorName{sensorId.substr(index + 1)};
2618 // fan_pwm and fan_tach need special handling
2619 if (sensorType == "fantach" || sensorType == "fanpwm")
2620 {
2621 sensorType.insert(3, 1, '_');
2622 }
2623 return std::make_pair(sensorType, sensorName);
2624}
2625
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002626/**
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302627 * @brief Entry point for overriding sensor values of given sensor
2628 *
zhanghch058d1b46d2021-04-01 11:18:24 +08002629 * @param sensorAsyncResp response object
Carol Wang4bb3dc32019-10-17 18:15:02 +08002630 * @param allCollections Collections extract from sensors' request patch info
jayaprakash Mutyala91e130a2020-03-04 22:26:38 +00002631 * @param chassisSubNode Chassis Node for which the query has to happen
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302632 */
Ed Tanous23a21a12020-07-25 04:45:05 +00002633inline void setSensorsOverride(
Ed Tanousb5a76932020-09-29 16:16:58 -07002634 const std::shared_ptr<SensorsAsyncResp>& sensorAsyncResp,
Ed Tanous08850572024-03-06 15:09:17 -08002635 std::unordered_map<std::string, std::vector<nlohmann::json::object_t>>&
jayaprakash Mutyala397fd612020-02-06 23:33:34 +00002636 allCollections)
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302637{
Ed Tanous62598e32023-07-17 17:06:25 -07002638 BMCWEB_LOG_INFO("setSensorsOverride for subNode{}",
2639 sensorAsyncResp->chassisSubNode);
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302640
Ed Tanousd02aad32024-02-13 14:43:34 -08002641 std::string_view propertyValueName;
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302642 std::unordered_map<std::string, std::pair<double, std::string>> overrideMap;
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302643 std::string memberId;
Ed Tanous543f4402022-01-06 13:12:53 -08002644 double value = 0.0;
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302645 for (auto& collectionItems : allCollections)
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302646 {
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302647 if (collectionItems.first == "Temperatures")
2648 {
2649 propertyValueName = "ReadingCelsius";
2650 }
2651 else if (collectionItems.first == "Fans")
2652 {
2653 propertyValueName = "Reading";
2654 }
2655 else
2656 {
2657 propertyValueName = "ReadingVolts";
2658 }
2659 for (auto& item : collectionItems.second)
2660 {
Ed Tanous08850572024-03-06 15:09:17 -08002661 if (!json_util::readJsonObject(
2662 item, sensorAsyncResp->asyncResp->res, "MemberId", memberId,
2663 propertyValueName, value))
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302664 {
2665 return;
2666 }
2667 overrideMap.emplace(memberId,
2668 std::make_pair(value, collectionItems.first));
2669 }
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302670 }
Carol Wang4bb3dc32019-10-17 18:15:02 +08002671
Ed Tanous002d39b2022-05-31 08:59:27 -07002672 auto getChassisSensorListCb =
Ed Tanousd02aad32024-02-13 14:43:34 -08002673 [sensorAsyncResp, overrideMap,
2674 propertyValueNameStr = std::string(propertyValueName)](
Nan Zhoufe04d492022-06-22 17:10:41 +00002675 const std::shared_ptr<std::set<std::string>>& sensorsList) {
Johnathan Mantey49c53ac2019-05-02 09:22:38 -07002676 // Match sensor names in the PATCH request to those managed by the
2677 // chassis node
Nan Zhoufe04d492022-06-22 17:10:41 +00002678 const std::shared_ptr<std::set<std::string>> sensorNames =
2679 std::make_shared<std::set<std::string>>();
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302680 for (const auto& item : overrideMap)
2681 {
2682 const auto& sensor = item.first;
Ed Tanousc71d6122022-11-29 14:10:32 -08002683 std::pair<std::string, std::string> sensorNameType =
2684 splitSensorNameAndType(sensor);
2685 if (!findSensorNameUsingSensorPath(sensorNameType.second,
2686 *sensorsList, *sensorNames))
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302687 {
Ed Tanous62598e32023-07-17 17:06:25 -07002688 BMCWEB_LOG_INFO("Unable to find memberId {}", item.first);
zhanghch058d1b46d2021-04-01 11:18:24 +08002689 messages::resourceNotFound(sensorAsyncResp->asyncResp->res,
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302690 item.second.second, item.first);
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302691 return;
2692 }
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302693 }
2694 // Get the connection to which the memberId belongs
Ed Tanous002d39b2022-05-31 08:59:27 -07002695 auto getObjectsWithConnectionCb =
Ed Tanousd02aad32024-02-13 14:43:34 -08002696 [sensorAsyncResp, overrideMap, propertyValueNameStr](
2697 const std::set<std::string>& /*connections*/,
2698 const std::set<std::pair<std::string, std::string>>&
2699 objectsWithConnection) {
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002700 if (objectsWithConnection.size() != overrideMap.size())
2701 {
Ed Tanous62598e32023-07-17 17:06:25 -07002702 BMCWEB_LOG_INFO(
2703 "Unable to find all objects with proper connection {} requested {}",
2704 objectsWithConnection.size(), overrideMap.size());
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002705 messages::resourceNotFound(sensorAsyncResp->asyncResp->res,
2706 sensorAsyncResp->chassisSubNode ==
2707 sensors::node::thermal
2708 ? "Temperatures"
2709 : "Voltages",
2710 "Count");
2711 return;
2712 }
2713 for (const auto& item : objectsWithConnection)
2714 {
2715 sdbusplus::message::object_path path(item.first);
2716 std::string sensorName = path.filename();
2717 if (sensorName.empty())
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302718 {
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002719 messages::internalError(sensorAsyncResp->asyncResp->res);
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302720 return;
2721 }
Ban Feng3f5eb752023-06-29 09:19:20 +08002722 std::string id = path.parent_path().filename();
Ed Tanous3544d2a2023-08-06 18:12:20 -07002723 auto remove = std::ranges::remove(id, '_');
2724 id.erase(std::ranges::begin(remove), id.end());
Ban Feng3f5eb752023-06-29 09:19:20 +08002725 id += "_";
2726 id += sensorName;
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302727
Ban Feng3f5eb752023-06-29 09:19:20 +08002728 const auto& iterator = overrideMap.find(id);
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002729 if (iterator == overrideMap.end())
2730 {
Ed Tanous62598e32023-07-17 17:06:25 -07002731 BMCWEB_LOG_INFO("Unable to find sensor object{}",
2732 item.first);
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002733 messages::internalError(sensorAsyncResp->asyncResp->res);
2734 return;
2735 }
Ed Tanousd02aad32024-02-13 14:43:34 -08002736 setDbusProperty(sensorAsyncResp->asyncResp, item.second,
2737 item.first, "xyz.openbmc_project.Sensor.Value",
2738 "Value", propertyValueNameStr,
2739 iterator->second.first);
Jayaprakash Mutyala4f277b52021-12-08 22:46:49 +00002740 }
2741 };
Richard Marian Thomaiyarf65af9e2019-02-13 23:35:05 +05302742 // Get object with connection for the given sensor name
2743 getObjectsWithConnection(sensorAsyncResp, sensorNames,
2744 std::move(getObjectsWithConnectionCb));
2745 };
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302746 // get full sensor list for the given chassisId and cross verify the sensor.
Ed Tanous7f1cc262022-08-09 13:33:57 -07002747 getChassis(sensorAsyncResp->asyncResp, sensorAsyncResp->chassisId,
2748 sensorAsyncResp->chassisSubNode, sensorAsyncResp->types,
2749 std::move(getChassisSensorListCb));
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +05302750}
2751
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002752/**
2753 * @brief Retrieves mapping of Redfish URIs to sensor value property to D-Bus
2754 * path of the sensor.
2755 *
2756 * Function builds valid Redfish response for sensor query of given chassis and
2757 * node. It then builds metadata about Redfish<->D-Bus correlations and provides
2758 * it to caller in a callback.
2759 *
2760 * @param chassis Chassis for which retrieval should be performed
2761 * @param node Node (group) of sensors. See sensors::node for supported values
2762 * @param mapComplete Callback to be called with retrieval result
2763 */
Ed Tanous931edc72023-11-01 12:09:07 -07002764template <typename Callback>
Krzysztof Grobelny021d32c2021-10-29 16:00:07 +02002765inline void retrieveUriToDbusMap(const std::string& chassis,
2766 const std::string& node,
Ed Tanous931edc72023-11-01 12:09:07 -07002767 Callback&& mapComplete)
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002768{
Ed Tanous02da7c52022-02-27 00:09:02 -08002769 decltype(sensors::paths)::const_iterator pathIt =
2770 std::find_if(sensors::paths.cbegin(), sensors::paths.cend(),
2771 [&node](auto&& val) { return val.first == node; });
2772 if (pathIt == sensors::paths.cend())
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002773 {
Ed Tanous62598e32023-07-17 17:06:25 -07002774 BMCWEB_LOG_ERROR("Wrong node provided : {}", node);
Ed Tanous6804b5c2023-10-31 14:50:03 -07002775 std::map<std::string, std::string> noop;
2776 mapComplete(boost::beast::http::status::bad_request, noop);
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002777 return;
2778 }
Krzysztof Grobelnyd51e0722021-04-16 13:15:21 +00002779
Nan Zhou72374eb2022-01-27 17:06:51 -08002780 auto asyncResp = std::make_shared<bmcweb::AsyncResp>();
Ed Tanous931edc72023-11-01 12:09:07 -07002781 auto callback = [asyncResp,
Ed Tanous8cb2c022024-03-27 16:31:46 -07002782 mapCompleteCb = std::forward<Callback>(mapComplete)](
Nan Zhoufe04d492022-06-22 17:10:41 +00002783 const boost::beast::http::status status,
2784 const std::map<std::string, std::string>& uriToDbus) {
2785 mapCompleteCb(status, uriToDbus);
2786 };
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002787
2788 auto resp = std::make_shared<SensorsAsyncResp>(
Krzysztof Grobelnyd51e0722021-04-16 13:15:21 +00002789 asyncResp, chassis, pathIt->second, node, std::move(callback));
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +02002790 getChassisData(resp);
2791}
2792
Nan Zhoubacb2162022-04-06 11:28:32 -07002793namespace sensors
2794{
Nan Zhou928fefb2022-03-28 08:45:00 -07002795
Nan Zhoubacb2162022-04-06 11:28:32 -07002796inline void getChassisCallback(
Ed Tanousc1d019a2022-08-06 09:36:06 -07002797 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2798 std::string_view chassisId, std::string_view chassisSubNode,
Nan Zhoufe04d492022-06-22 17:10:41 +00002799 const std::shared_ptr<std::set<std::string>>& sensorNames)
Nan Zhoubacb2162022-04-06 11:28:32 -07002800{
Ed Tanous62598e32023-07-17 17:06:25 -07002801 BMCWEB_LOG_DEBUG("getChassisCallback enter ");
Nan Zhoubacb2162022-04-06 11:28:32 -07002802
Ed Tanousc1d019a2022-08-06 09:36:06 -07002803 nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
2804 for (const std::string& sensor : *sensorNames)
Nan Zhoubacb2162022-04-06 11:28:32 -07002805 {
Ed Tanous62598e32023-07-17 17:06:25 -07002806 BMCWEB_LOG_DEBUG("Adding sensor: {}", sensor);
Nan Zhoubacb2162022-04-06 11:28:32 -07002807
2808 sdbusplus::message::object_path path(sensor);
2809 std::string sensorName = path.filename();
2810 if (sensorName.empty())
2811 {
Ed Tanous62598e32023-07-17 17:06:25 -07002812 BMCWEB_LOG_ERROR("Invalid sensor path: {}", sensor);
Ed Tanousc1d019a2022-08-06 09:36:06 -07002813 messages::internalError(asyncResp->res);
Nan Zhoubacb2162022-04-06 11:28:32 -07002814 return;
2815 }
Ed Tanousc1d019a2022-08-06 09:36:06 -07002816 std::string type = path.parent_path().filename();
2817 // fan_tach has an underscore in it, so remove it to "normalize" the
2818 // type in the URI
Ed Tanous3544d2a2023-08-06 18:12:20 -07002819 auto remove = std::ranges::remove(type, '_');
2820 type.erase(std::ranges::begin(remove), type.end());
Ed Tanousc1d019a2022-08-06 09:36:06 -07002821
Ed Tanous14766872022-03-15 10:44:42 -07002822 nlohmann::json::object_t member;
Ed Tanousc1d019a2022-08-06 09:36:06 -07002823 std::string id = type;
2824 id += "_";
2825 id += sensorName;
Ed Tanousef4c65b2023-04-24 15:28:50 -07002826 member["@odata.id"] = boost::urls::format(
2827 "/redfish/v1/Chassis/{}/{}/{}", chassisId, chassisSubNode, id);
Ed Tanousc1d019a2022-08-06 09:36:06 -07002828
Patrick Williamsb2ba3072023-05-12 10:27:39 -05002829 entriesArray.emplace_back(std::move(member));
Nan Zhoubacb2162022-04-06 11:28:32 -07002830 }
2831
Ed Tanousc1d019a2022-08-06 09:36:06 -07002832 asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
Ed Tanous62598e32023-07-17 17:06:25 -07002833 BMCWEB_LOG_DEBUG("getChassisCallback exit");
Nan Zhoubacb2162022-04-06 11:28:32 -07002834}
Nan Zhoue6bd8462022-06-01 04:35:35 +00002835
Ed Tanousac106bf2023-06-07 09:24:59 -07002836inline void handleSensorCollectionGet(
2837 App& app, const crow::Request& req,
2838 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2839 const std::string& chassisId)
Nan Zhoude167a62022-06-01 04:47:45 +00002840{
2841 query_param::QueryCapabilities capabilities = {
2842 .canDelegateExpandLevel = 1,
2843 };
2844 query_param::Query delegatedQuery;
Ed Tanousac106bf2023-06-07 09:24:59 -07002845 if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
Nan Zhoude167a62022-06-01 04:47:45 +00002846 delegatedQuery, capabilities))
2847 {
2848 return;
2849 }
2850
2851 if (delegatedQuery.expandType != query_param::ExpandType::None)
2852 {
2853 // we perform efficient expand.
Ed Tanousac106bf2023-06-07 09:24:59 -07002854 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
2855 asyncResp, chassisId, sensors::dbus::sensorPaths,
Nan Zhoude167a62022-06-01 04:47:45 +00002856 sensors::node::sensors,
2857 /*efficientExpand=*/true);
Ed Tanousac106bf2023-06-07 09:24:59 -07002858 getChassisData(sensorsAsyncResp);
Nan Zhoude167a62022-06-01 04:47:45 +00002859
Ed Tanous62598e32023-07-17 17:06:25 -07002860 BMCWEB_LOG_DEBUG(
2861 "SensorCollection doGet exit via efficient expand handler");
Nan Zhoude167a62022-06-01 04:47:45 +00002862 return;
Ed Tanous0bad3202022-06-02 13:53:59 -07002863 }
Nan Zhoude167a62022-06-01 04:47:45 +00002864
Nan Zhoude167a62022-06-01 04:47:45 +00002865 // We get all sensors as hyperlinkes in the chassis (this
2866 // implies we reply on the default query parameters handler)
Ed Tanousac106bf2023-06-07 09:24:59 -07002867 getChassis(asyncResp, chassisId, sensors::node::sensors, dbus::sensorPaths,
2868 std::bind_front(sensors::getChassisCallback, asyncResp,
2869 chassisId, sensors::node::sensors));
Ed Tanousc1d019a2022-08-06 09:36:06 -07002870}
Ed Tanous7f1cc262022-08-09 13:33:57 -07002871
Ed Tanousc1d019a2022-08-06 09:36:06 -07002872inline void
2873 getSensorFromDbus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2874 const std::string& sensorPath,
2875 const ::dbus::utility::MapperGetObject& mapperResponse)
2876{
2877 if (mapperResponse.size() != 1)
2878 {
2879 messages::internalError(asyncResp->res);
2880 return;
2881 }
2882 const auto& valueIface = *mapperResponse.begin();
2883 const std::string& connectionName = valueIface.first;
Ed Tanous62598e32023-07-17 17:06:25 -07002884 BMCWEB_LOG_DEBUG("Looking up {}", connectionName);
2885 BMCWEB_LOG_DEBUG("Path {}", sensorPath);
Krzysztof Grobelnyc1343bf2022-08-31 13:15:26 +02002886
2887 sdbusplus::asio::getAllProperties(
2888 *crow::connections::systemBus, connectionName, sensorPath, "",
Ed Tanousc1d019a2022-08-06 09:36:06 -07002889 [asyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002890 sensorPath](const boost::system::error_code& ec,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002891 const ::dbus::utility::DBusPropertiesMap& valuesDict) {
2892 if (ec)
2893 {
2894 messages::internalError(asyncResp->res);
2895 return;
2896 }
2897 sdbusplus::message::object_path path(sensorPath);
2898 std::string name = path.filename();
2899 path = path.parent_path();
2900 std::string type = path.filename();
2901 objectPropertiesToJson(name, type, sensors::node::sensors, valuesDict,
2902 asyncResp->res.jsonValue, nullptr);
Patrick Williams5a39f772023-10-20 11:20:21 -05002903 });
Nan Zhoude167a62022-06-01 04:47:45 +00002904}
2905
Nan Zhoue6bd8462022-06-01 04:35:35 +00002906inline void handleSensorGet(App& app, const crow::Request& req,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002907 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous677bb752022-09-15 10:52:19 -07002908 const std::string& chassisId,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002909 const std::string& sensorId)
Nan Zhoue6bd8462022-06-01 04:35:35 +00002910{
Ed Tanousc1d019a2022-08-06 09:36:06 -07002911 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Nan Zhoue6bd8462022-06-01 04:35:35 +00002912 {
2913 return;
2914 }
Ed Tanousc71d6122022-11-29 14:10:32 -08002915 std::pair<std::string, std::string> nameType =
2916 splitSensorNameAndType(sensorId);
2917 if (nameType.first.empty() || nameType.second.empty())
Ed Tanousc1d019a2022-08-06 09:36:06 -07002918 {
2919 messages::resourceNotFound(asyncResp->res, sensorId, "Sensor");
2920 return;
2921 }
Ed Tanousc71d6122022-11-29 14:10:32 -08002922
Ed Tanousef4c65b2023-04-24 15:28:50 -07002923 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2924 "/redfish/v1/Chassis/{}/Sensors/{}", chassisId, sensorId);
Ed Tanousc1d019a2022-08-06 09:36:06 -07002925
Ed Tanous62598e32023-07-17 17:06:25 -07002926 BMCWEB_LOG_DEBUG("Sensor doGet enter");
Nan Zhoue6bd8462022-06-01 04:35:35 +00002927
George Liu2b731192023-01-11 16:27:13 +08002928 constexpr std::array<std::string_view, 1> interfaces = {
Nan Zhoue6bd8462022-06-01 04:35:35 +00002929 "xyz.openbmc_project.Sensor.Value"};
Ed Tanousc71d6122022-11-29 14:10:32 -08002930 std::string sensorPath = "/xyz/openbmc_project/sensors/" + nameType.first +
2931 '/' + nameType.second;
Nan Zhoue6bd8462022-06-01 04:35:35 +00002932 // Get a list of all of the sensors that implement Sensor.Value
2933 // and get the path and service name associated with the sensor
George Liu2b731192023-01-11 16:27:13 +08002934 ::dbus::utility::getDbusObject(
2935 sensorPath, interfaces,
Myung Baeaec0ec32023-05-31 15:10:01 -05002936 [asyncResp, sensorId,
George Liu2b731192023-01-11 16:27:13 +08002937 sensorPath](const boost::system::error_code& ec,
Ed Tanousc1d019a2022-08-06 09:36:06 -07002938 const ::dbus::utility::MapperGetObject& subtree) {
Ed Tanous62598e32023-07-17 17:06:25 -07002939 BMCWEB_LOG_DEBUG("respHandler1 enter");
Myung Baeaec0ec32023-05-31 15:10:01 -05002940 if (ec == boost::system::errc::io_error)
2941 {
Ed Tanous62598e32023-07-17 17:06:25 -07002942 BMCWEB_LOG_WARNING("Sensor not found from getSensorPaths");
Myung Baeaec0ec32023-05-31 15:10:01 -05002943 messages::resourceNotFound(asyncResp->res, sensorId, "Sensor");
2944 return;
2945 }
Nan Zhoue6bd8462022-06-01 04:35:35 +00002946 if (ec)
2947 {
Ed Tanousc1d019a2022-08-06 09:36:06 -07002948 messages::internalError(asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07002949 BMCWEB_LOG_ERROR(
2950 "Sensor getSensorPaths resp_handler: Dbus error {}", ec);
Nan Zhoue6bd8462022-06-01 04:35:35 +00002951 return;
2952 }
Ed Tanousc1d019a2022-08-06 09:36:06 -07002953 getSensorFromDbus(asyncResp, sensorPath, subtree);
Ed Tanous62598e32023-07-17 17:06:25 -07002954 BMCWEB_LOG_DEBUG("respHandler1 exit");
Patrick Williams5a39f772023-10-20 11:20:21 -05002955 });
Nan Zhoue6bd8462022-06-01 04:35:35 +00002956}
2957
Nan Zhoubacb2162022-04-06 11:28:32 -07002958} // namespace sensors
2959
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002960inline void requestRoutesSensorCollection(App& app)
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002961{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002962 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/")
Ed Tanoused398212021-06-09 17:05:54 -07002963 .privileges(redfish::privileges::getSensorCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07002964 .methods(boost::beast::http::verb::get)(
Nan Zhoude167a62022-06-01 04:47:45 +00002965 std::bind_front(sensors::handleSensorCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002966}
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002967
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002968inline void requestRoutesSensor(App& app)
2969{
2970 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Sensors/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002971 .privileges(redfish::privileges::getSensor)
Ed Tanous002d39b2022-05-31 08:59:27 -07002972 .methods(boost::beast::http::verb::get)(
Nan Zhoue6bd8462022-06-01 04:35:35 +00002973 std::bind_front(sensors::handleSensorGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002974}
Anthony Wilson95a3eca2019-06-11 10:44:47 -05002975
Ed Tanous1abe55e2018-09-05 08:30:59 -07002976} // namespace redfish