blob: 7743486389b8166355e9ba414f75047b0c600860 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Albert Zhang4ca3ec32021-06-13 14:39:38 +08003#pragma once
4
5#include "app.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "query.hpp"
7#include "registries/privilege_registry.hpp"
Albert Zhang4ca3ec32021-06-13 14:39:38 +08008#include "utils/chassis_utils.hpp"
9
Ed Tanousef4c65b2023-04-24 15:28:50 -070010#include <boost/url/format.hpp>
11
Albert Zhang4ca3ec32021-06-13 14:39:38 +080012#include <memory>
13#include <optional>
14#include <string>
15
16namespace redfish
17{
18
19inline void handleEnvironmentMetricsHead(
20 App& app, const crow::Request& req,
21 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
22 const std::string& chassisId)
23{
24 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
25 {
26 return;
27 }
28
29 auto respHandler = [asyncResp, chassisId](
30 const std::optional<std::string>& validChassisPath) {
31 if (!validChassisPath)
32 {
33 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
34 return;
35 }
36
37 asyncResp->res.addHeader(
38 boost::beast::http::field::link,
39 "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby");
40 };
41
42 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
43 std::move(respHandler));
44}
45
46inline void handleEnvironmentMetricsGet(
47 App& app, const crow::Request& req,
48 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
49 const std::string& chassisId)
50{
51 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
52 {
53 return;
54 }
55
56 auto respHandler = [asyncResp, chassisId](
57 const std::optional<std::string>& validChassisPath) {
58 if (!validChassisPath)
59 {
60 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
61 return;
62 }
63
64 asyncResp->res.addHeader(
65 boost::beast::http::field::link,
66 "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby");
67 asyncResp->res.jsonValue["@odata.type"] =
68 "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics";
69 asyncResp->res.jsonValue["Name"] = "Chassis Environment Metrics";
70 asyncResp->res.jsonValue["Id"] = "EnvironmentMetrics";
Ed Tanousef4c65b2023-04-24 15:28:50 -070071 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
72 "/redfish/v1/Chassis/{}/EnvironmentMetrics", chassisId);
Albert Zhang4ca3ec32021-06-13 14:39:38 +080073 };
74
75 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
76 std::move(respHandler));
77}
78
79inline void requestRoutesEnvironmentMetrics(App& app)
80{
81 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/")
82 .privileges(redfish::privileges::headEnvironmentMetrics)
83 .methods(boost::beast::http::verb::head)(
84 std::bind_front(handleEnvironmentMetricsHead, std::ref(app)));
85
86 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/")
87 .privileges(redfish::privileges::getEnvironmentMetrics)
88 .methods(boost::beast::http::verb::get)(
89 std::bind_front(handleEnvironmentMetricsGet, std::ref(app)));
90}
91
92} // namespace redfish