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