diff options
Diffstat (limited to 'redfish-core/lib')
-rw-r--r-- | redfish-core/lib/chassis.hpp | 4 | ||||
-rw-r--r-- | redfish-core/lib/environment_metrics.hpp | 86 |
2 files changed, 90 insertions, 0 deletions
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp index 4c4a9c4749..c6016cbe12 100644 --- a/redfish-core/lib/chassis.hpp +++ b/redfish-core/lib/chassis.hpp @@ -406,6 +406,10 @@ inline void asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] = crow::utility::urlFromPieces("redfish", "v1", "Chassis", chassisId, "PowerSubsystem"); + asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] = + crow::utility::urlFromPieces("redfish", "v1", "Chassis", + chassisId, + "EnvironmentMetrics"); #endif // SensorCollection asyncResp->res.jsonValue["Sensors"]["@odata.id"] = diff --git a/redfish-core/lib/environment_metrics.hpp b/redfish-core/lib/environment_metrics.hpp new file mode 100644 index 0000000000..f46ef34f13 --- /dev/null +++ b/redfish-core/lib/environment_metrics.hpp @@ -0,0 +1,86 @@ +#pragma once + +#include "app.hpp" +#include "utils/chassis_utils.hpp" + +#include <memory> +#include <optional> +#include <string> + +namespace redfish +{ + +inline void handleEnvironmentMetricsHead( + App& app, const crow::Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& chassisId) +{ + if (!redfish::setUpRedfishRoute(app, req, asyncResp)) + { + return; + } + + auto respHandler = [asyncResp, chassisId]( + const std::optional<std::string>& validChassisPath) { + if (!validChassisPath) + { + messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); + return; + } + + asyncResp->res.addHeader( + boost::beast::http::field::link, + "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby"); + }; + + redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, + std::move(respHandler)); +} + +inline void handleEnvironmentMetricsGet( + App& app, const crow::Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& chassisId) +{ + if (!redfish::setUpRedfishRoute(app, req, asyncResp)) + { + return; + } + + auto respHandler = [asyncResp, chassisId]( + const std::optional<std::string>& validChassisPath) { + if (!validChassisPath) + { + messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); + return; + } + + asyncResp->res.addHeader( + boost::beast::http::field::link, + "</redfish/v1/JsonSchemas/EnvironmentMetrics/EnvironmentMetrics.json>; rel=describedby"); + asyncResp->res.jsonValue["@odata.type"] = + "#EnvironmentMetrics.v1_3_0.EnvironmentMetrics"; + asyncResp->res.jsonValue["Name"] = "Chassis Environment Metrics"; + asyncResp->res.jsonValue["Id"] = "EnvironmentMetrics"; + asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( + "redfish", "v1", "Chassis", chassisId, "EnvironmentMetrics"); + }; + + redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, + std::move(respHandler)); +} + +inline void requestRoutesEnvironmentMetrics(App& app) +{ + BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/") + .privileges(redfish::privileges::headEnvironmentMetrics) + .methods(boost::beast::http::verb::head)( + std::bind_front(handleEnvironmentMetricsHead, std::ref(app))); + + BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/EnvironmentMetrics/") + .privileges(redfish::privileges::getEnvironmentMetrics) + .methods(boost::beast::http::verb::get)( + std::bind_front(handleEnvironmentMetricsGet, std::ref(app))); +} + +} // namespace redfish |