3
3
#include " async_resp.hpp"
4
4
#include " generated/enums/metric_definition.hpp"
5
5
#include " sensors.hpp"
6
+ #include " error_messages.hpp"
7
+ #include " dbus_singleton.hpp"
8
+ #include " http_request.hpp"
9
+ #include " logging.hpp"
6
10
#include " utils/get_chassis_names.hpp"
7
11
#include " utils/sensor_utils.hpp"
8
12
#include " utils/telemetry_utils.hpp"
9
13
14
+ #include < boost/beast/http/status.hpp>
15
+ #include < boost/beast/http/verb.hpp>
10
16
#include < boost/container/flat_map.hpp>
11
17
#include < boost/system/error_code.hpp>
12
18
#include < registries/privilege_registry.hpp>
13
19
14
20
#include < algorithm>
15
21
#include < cmath>
22
+ #include < cstddef>
23
+ #include < cstdint>
24
+ #include < functional>
16
25
#include < map>
17
26
#include < memory>
18
27
#include < string>
@@ -249,47 +258,47 @@ inline void requestRoutesMetricDefinitionCollection(App& app)
249
258
.methods (boost::beast::http::verb::get)(
250
259
[](const crow::Request&,
251
260
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
252
- telemetry::mapRedfishUriToDbusPath (
253
- [asyncResp](boost::system::error_code ec,
254
- const boost::container::flat_map<
255
- std::string, std::string>& uriToDbus) {
256
- if (ec)
257
- {
258
- messages::internalError (asyncResp->res );
259
- BMCWEB_LOG_ERROR (
260
- " mapRedfishUriToDbusPath error: {}" ,
261
- ec.value ());
262
- return ;
263
- }
264
-
265
- std::set<std::string> members;
266
-
267
- for (const auto & [uri, dbusPath] : uriToDbus)
268
- {
269
- members.insert (
270
- telemetry::mapSensorToMetricDefinition (
271
- dbusPath));
272
- }
273
-
274
- for (const std::string& odataId : members)
275
- {
276
- asyncResp->res .jsonValue [" Members" ].push_back (
277
- {{" @odata.id" , odataId}});
278
- }
279
-
280
- asyncResp->
res .
jsonValue [
" [email protected] " ] =
281
- asyncResp->res .jsonValue [" Members" ].size ();
261
+ telemetry::mapRedfishUriToDbusPath (
262
+ [asyncResp](boost::system::error_code ec,
263
+ const boost::container::flat_map<
264
+ std::string, std::string>& uriToDbus) {
265
+ if (ec)
266
+ {
267
+ messages::internalError (asyncResp->res );
268
+ BMCWEB_LOG_ERROR (
269
+ " mapRedfishUriToDbusPath error: {}" ,
270
+ ec.value ());
271
+ return ;
272
+ }
273
+
274
+ std::set<std::string> members;
275
+
276
+ for (const auto & [uri, dbusPath] : uriToDbus)
277
+ {
278
+ members.insert (
279
+ telemetry::mapSensorToMetricDefinition (
280
+ dbusPath));
281
+ }
282
+
283
+ for (const std::string& odataId : members)
284
+ {
285
+ asyncResp->res .jsonValue [" Members" ].push_back (
286
+ {{" @odata.id" , odataId}});
287
+ }
288
+
289
+ asyncResp->
res .
jsonValue [
" [email protected] " ] =
290
+ asyncResp->res .jsonValue [" Members" ].size ();
291
+ });
292
+
293
+ asyncResp->res .jsonValue [" @odata.type" ] =
294
+ " #MetricDefinitionCollection.MetricDefinitionCollection" ;
295
+ asyncResp->res .jsonValue [" @odata.id" ] =
296
+ " /redfish/v1/TelemetryService/MetricDefinitions" ;
297
+ asyncResp->res .jsonValue [" Name" ] =
298
+ " Metric Definition Collection" ;
299
+ asyncResp->res .jsonValue [" Members" ] = nlohmann::json::array ();
300
+ asyncResp->
res .
jsonValue [
" [email protected] " ] =
0 ;
282
301
});
283
-
284
- asyncResp->res .jsonValue [" @odata.type" ] =
285
- " #MetricDefinitionCollection.MetricDefinitionCollection" ;
286
- asyncResp->res .jsonValue [" @odata.id" ] =
287
- " /redfish/v1/TelemetryService/MetricDefinitions" ;
288
- asyncResp->res .jsonValue [" Name" ] =
289
- " Metric Definition Collection" ;
290
- asyncResp->res .jsonValue [" Members" ] = nlohmann::json::array ();
291
- asyncResp->
res .
jsonValue [
" [email protected] " ] =
0 ;
292
- });
293
302
}
294
303
295
304
inline void requestRoutesMetricDefinition (App& app)
@@ -301,77 +310,80 @@ inline void requestRoutesMetricDefinition(App& app)
301
310
const std::shared_ptr<
302
311
bmcweb::AsyncResp>& asyncResp,
303
312
const std::string& name) {
304
- telemetry::mapRedfishUriToDbusPath (
305
- [asyncResp, name](
306
- boost::system::error_code ec2,
307
- const boost::container::flat_map<std::string, std::string>&
308
- uriToDbus) {
309
- if (ec2)
310
- {
311
- messages::internalError (asyncResp->res );
312
- BMCWEB_LOG_ERROR (" mapRedfishUriToDbusPath error: {}" ,
313
- ec2.value ());
314
- return ;
315
- }
313
+ telemetry::mapRedfishUriToDbusPath (
314
+ [asyncResp, name](
315
+ boost::system::error_code ec2,
316
+ const boost::container::flat_map<std::string, std::string>&
317
+ uriToDbus) {
318
+ if (ec2)
319
+ {
320
+ messages::internalError (asyncResp->res );
321
+ BMCWEB_LOG_ERROR (" mapRedfishUriToDbusPath error: {}" ,
322
+ ec2.value ());
323
+ return ;
324
+ }
316
325
317
- std::string odataId = telemetry::metricDefinitionUri + name;
318
- boost::container::flat_map<std::string, std::string> matchingUris;
326
+ std::string odataId = telemetry::metricDefinitionUri + name;
327
+ boost::container::flat_map<std::string, std::string>
328
+ matchingUris;
319
329
320
- for (const auto & [uri, dbusPath] : uriToDbus)
321
- {
322
- if (telemetry::mapSensorToMetricDefinition (dbusPath) == odataId)
330
+ for (const auto & [uri, dbusPath] : uriToDbus)
323
331
{
324
- matchingUris.emplace (uri, dbusPath);
332
+ if (telemetry::mapSensorToMetricDefinition (dbusPath) ==
333
+ odataId)
334
+ {
335
+ matchingUris.emplace (uri, dbusPath);
336
+ }
325
337
}
326
- }
327
338
328
- if (matchingUris.empty ())
329
- {
330
- messages::resourceNotFound (asyncResp->res ,
331
- " MetricDefinition" , name);
332
- return ;
333
- }
334
-
335
- std::string sensorPath = matchingUris.begin ()->second ;
336
-
337
- telemetry::getSensorService (
338
- sensorPath,
339
- [asyncResp, name, odataId = std::move (odataId),
340
- sensorPath, matchingUris = std::move (matchingUris)](
341
- boost::system::error_code ec3,
342
- const std::string& serviceName) {
343
- if (ec3)
344
- {
345
- messages::internalError (asyncResp->res );
346
- BMCWEB_LOG_ERROR (" getServiceSensorFailed: {}" ,
347
- ec3.value ());
348
- return ;
349
- }
350
-
351
- asyncResp->res .jsonValue [" Id" ] = name;
352
- asyncResp->res .jsonValue [" Name" ] = name;
353
- asyncResp->res .jsonValue [" @odata.id" ] = odataId;
354
- asyncResp->res .jsonValue [" @odata.type" ] =
355
- " #MetricDefinition.v1_0_3.MetricDefinition" ;
356
- asyncResp->res .jsonValue [" MetricDataType" ] =
357
- metric_definition::MetricDataType::Decimal;
358
- asyncResp->res .jsonValue [" IsLinear" ] = true ;
359
- asyncResp->res .jsonValue [" Units" ] =
360
- sensor_utils::sensors::toReadingUnits (
361
- sdbusplus::message::object_path{sensorPath}
362
- .parent_path ()
363
- .filename ());
364
-
365
- for (const auto & [uri, dbusPath] : matchingUris)
339
+ if (matchingUris.empty ())
366
340
{
367
- asyncResp->res .jsonValue [" MetricProperties" ].push_back (uri);
341
+ messages::resourceNotFound (asyncResp->res ,
342
+ " MetricDefinition" , name);
343
+ return ;
368
344
}
369
345
370
- telemetry::fillMinMaxReadingRange (asyncResp, serviceName,
371
- sensorPath);
346
+ std::string sensorPath = matchingUris.begin ()->second ;
347
+
348
+ telemetry::getSensorService (
349
+ sensorPath,
350
+ [asyncResp, name, odataId = std::move (odataId),
351
+ sensorPath, matchingUris = std::move (matchingUris)](
352
+ boost::system::error_code ec3,
353
+ const std::string& serviceName) {
354
+ if (ec3)
355
+ {
356
+ messages::internalError (asyncResp->res );
357
+ BMCWEB_LOG_ERROR (" getServiceSensorFailed: {}" ,
358
+ ec3.value ());
359
+ return ;
360
+ }
361
+
362
+ asyncResp->res .jsonValue [" Id" ] = name;
363
+ asyncResp->res .jsonValue [" Name" ] = name;
364
+ asyncResp->res .jsonValue [" @odata.id" ] = odataId;
365
+ asyncResp->res .jsonValue [" @odata.type" ] =
366
+ " #MetricDefinition.v1_0_3.MetricDefinition" ;
367
+ asyncResp->res .jsonValue [" MetricDataType" ] =
368
+ metric_definition::MetricDataType::Decimal;
369
+ asyncResp->res .jsonValue [" IsLinear" ] = true ;
370
+ asyncResp->res .jsonValue [" Units" ] =
371
+ sensor_utils::sensors::toReadingUnits (
372
+ sdbusplus::message::object_path{sensorPath}
373
+ .parent_path ()
374
+ .filename ());
375
+
376
+ for (const auto & [uri, dbusPath] : matchingUris)
377
+ {
378
+ asyncResp->res .jsonValue [" MetricProperties" ]
379
+ .push_back (uri);
380
+ }
381
+
382
+ telemetry::fillMinMaxReadingRange (
383
+ asyncResp, serviceName, sensorPath);
384
+ });
372
385
});
373
- });
374
- });
386
+ });
375
387
}
376
388
377
389
} // namespace redfish
0 commit comments