blob: 9d92fd4383279dc91363964c0b9d4bb3cdc1cffc [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 Tanousd7857202025-01-28 15:32:26 -08006#include "async_resp.hpp"
7#include "error_messages.hpp"
8#include "http_request.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08009#include "query.hpp"
10#include "registries/privilege_registry.hpp"
Albert Zhang4ca3ec32021-06-13 14:39:38 +080011#include "utils/chassis_utils.hpp"
12
Ed Tanousd7857202025-01-28 15:32:26 -080013#include <boost/beast/http/field.hpp>
14#include <boost/beast/http/verb.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070015#include <boost/url/format.hpp>
16
Ed Tanousd7857202025-01-28 15:32:26 -080017#include <functional>
Albert Zhang4ca3ec32021-06-13 14:39:38 +080018#include <memory>
19#include <optional>
20#include <string>
Ed Tanousd7857202025-01-28 15:32:26 -080021#include <utility>
Albert Zhang4ca3ec32021-06-13 14:39:38 +080022
23namespace redfish
24{
25
26inline void handleEnvironmentMetricsHead(
27 App& app, const crow::Request& req,
28 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
29 const std::string& chassisId)
30{
31 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
32 {
33 return;
34 }
35
36 auto respHandler = [asyncResp, chassisId](
37 const std::optional<std::string>& validChassisPath) {
38 if (!validChassisPath)
39 {
40 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
41 return;
42 }
43
44 asyncResp->res.addHeader(
45 boost::beast::http::field::link,
46 "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby");
47 };
48
49 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
50 std::move(respHandler));
51}
52
53inline void handleEnvironmentMetricsGet(
54 App& app, const crow::Request& req,
55 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
56 const std::string& chassisId)
57{
58 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
59 {
60 return;
61 }
62
63 auto respHandler = [asyncResp, chassisId](
64 const std::optional<std::string>& validChassisPath) {
65 if (!validChassisPath)
66 {
67 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
68 return;
69 }
70
71 asyncResp->res.addHeader(
72 boost::beast::http::field::link,
73 "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby");
74 asyncResp->res.jsonValue["@odata.type"] =
75 "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics";
76 asyncResp->res.jsonValue["Name"] = "Chassis Environment Metrics";
77 asyncResp->res.jsonValue["Id"] = "EnvironmentMetrics";
Ed Tanousef4c65b2023-04-24 15:28:50 -070078 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
79 "/redfish/v1/Chassis/{}/EnvironmentMetrics", chassisId);
Albert Zhang4ca3ec32021-06-13 14:39:38 +080080 };
81
82 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
83 std::move(respHandler));
84}
85
86inline void requestRoutesEnvironmentMetrics(App& app)
87{
88 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/")
89 .privileges(redfish::privileges::headEnvironmentMetrics)
90 .methods(boost::beast::http::verb::head)(
91 std::bind_front(handleEnvironmentMetricsHead, std::ref(app)));
92
93 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/")
94 .privileges(redfish::privileges::getEnvironmentMetrics)
95 .methods(boost::beast::http::verb::get)(
96 std::bind_front(handleEnvironmentMetricsGet, std::ref(app)));
97}
98
99} // namespace redfish