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