blob: c27d2c96848da8528b1beeee315782ef829d48be [file]
#ifndef THIRD_PARTY_GBMCWEB_REDFISH_CORE_LIB_PORT_METRICS_H_
#define THIRD_PARTY_GBMCWEB_REDFISH_CORE_LIB_PORT_METRICS_H_
#include <array>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include "app.hpp"
#include "http_request.hpp"
#include "logging.hpp"
#include "async_resp.hpp"
#include "query.hpp"
#include "registries/privilege_registry.hpp"
#include "dbus_utils.hpp"
#include "ports.hpp"
#include "managed_store_types.hpp"
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
#endif // THIRD_PARTY_GBMCWEB_REDFISH_CORE_LIB_PORT_METRICS_H_