| #include "managed_store_types.hpp" |
| #include "ports.hpp" |
| |
| #include <app.hpp> |
| #include <sdbusplus/asio/property.hpp> |
| |
| #include <array> |
| |
| namespace redfish |
| { |
| |
| inline void populatePortMetrics(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| const std::string& objectPath) |
| { |
| std::array<std::string, 2> portMetricsPropertyNames = { |
| {"RXDiscards", "TXDiscards"}}; |
| |
| managedStore::ManagedObjectStoreContext requestContext(asyncResp); |
| for (const std::string& propertyName : portMetricsPropertyNames) |
| { |
| dbus_utils::getProperty<uint32_t>( |
| "xyz.openbmc_project.Metric", objectPath, |
| "xyz.openbmc_project.Metric.Port", propertyName, requestContext, |
| [asyncResp, propertyName](const boost::system::error_code ec, |
| const uint32_t property) { |
| if (ec) |
| { |
| BMCWEB_LOG_ERROR << "DBus error getting port metrics"; |
| return; |
| } |
| |
| asyncResp->res.jsonValue["Networking"][propertyName] = property; |
| }); |
| } |
| } |
| |
| inline void handleDedicatedNetworkPortMetricsGet( |
| crow::App& app, const crow::Request& req, |
| const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| const std::string& portId) |
| { |
| if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| { |
| return; |
| } |
| |
| asyncResp->res.jsonValue["@odata.type"] = "#PortMetrics.v1_3_0.PortMetrics"; |
| asyncResp->res.jsonValue["@odata.id"] = |
| "/redfish/v1/Managers/bmc/DedicatedNetworkPorts/" + portId + "/Metrics"; |
| asyncResp->res.jsonValue["Id"] = "Metrics"; |
| asyncResp->res.jsonValue["Name"] = portId + " Metrics"; |
| |
| populatePortMetrics(asyncResp, portObjPathDir + portId); |
| } |
| |
| inline void requestPortMetricsRoutes(App& app) |
| { |
| BMCWEB_ROUTE(app, |
| "/redfish/v1/Managers/bmc/DedicatedNetworkPorts/<str>/Metrics") |
| .privileges(redfish::privileges::getPortMetrics) |
| .methods(boost::beast::http::verb::get)(std::bind_front( |
| handleDedicatedNetworkPortMetricsGet, std::ref(app))); |
| } |
| } // namespace redfish |