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