#pragma once #include "app.hpp" #include "async_resp.hpp" #include "http_request.hpp" #include "privileges.hpp" #include "query.hpp" #include "registries/privilege_registry.hpp" #include "routing.hpp" #include #include #include namespace redfish { inline void afterGetManagerStartTime( const std::shared_ptr& asyncResp, const boost::system::error_code& ec, uint64_t bmcwebResetTime) { if (ec) { // Not all servers will be running in systemd, so ignore the error. return; } using std::chrono::steady_clock; std::chrono::duration usReset{ bmcwebResetTime}; steady_clock::time_point resetTime{usReset}; steady_clock::time_point now = steady_clock::now(); steady_clock::duration runTime = now - resetTime; if (runTime < steady_clock::duration::zero()) { BMCWEB_LOG_CRITICAL("Uptime was negative????"); messages::internalError(asyncResp->res); return; } // Floor to the closest millisecond using Milli = std::chrono::duration; Milli milli = std::chrono::floor(runTime); using SecondsFloat = std::chrono::duration; SecondsFloat sec = std::chrono::duration_cast(milli); asyncResp->res.jsonValue["ServiceRootUptimeSeconds"] = sec.count(); } inline void managerGetServiceRootUptime( const std::shared_ptr& asyncResp) { sdbusplus::asio::getProperty( *crow::connections::systemBus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1/unit/bmcweb_2eservice", "org.freedesktop.systemd1.Unit", "ActiveEnterTimestampMonotonic", std::bind_front(afterGetManagerStartTime, asyncResp)); } /** * handleManagerDiagnosticData supports ManagerDiagnosticData. * It retrieves BMC health information from various DBus resources and returns * the information through the response. */ inline void handleManagerDiagnosticDataGet( crow::App& app, const crow::Request& req, const std::shared_ptr& asyncResp) { if (!redfish::setUpRedfishRoute(app, req, asyncResp)) { return; } asyncResp->res.jsonValue["@odata.type"] = "#ManagerDiagnosticData.v1_2_0.ManagerDiagnosticData"; asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc/ManagerDiagnosticData"; asyncResp->res.jsonValue["Id"] = "ManagerDiagnosticData"; asyncResp->res.jsonValue["Name"] = "Manager Diagnostic Data"; managerGetServiceRootUptime(asyncResp); } inline void requestRoutesManagerDiagnosticData(App& app) { BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ManagerDiagnosticData") .privileges(redfish::privileges::getManagerDiagnosticData) .methods(boost::beast::http::verb::get)( std::bind_front(handleManagerDiagnosticDataGet, std::ref(app))); } } // namespace redfish