1081ebf06SWludzik, Jozef #pragma once 2081ebf06SWludzik, Jozef 33ccb3adbSEd Tanous #include "app.hpp" 43ccb3adbSEd Tanous #include "dbus_utility.hpp" 53ccb3adbSEd Tanous #include "query.hpp" 63ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 73ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 8081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp" 9d093c996SEd Tanous #include "utils/time_utils.hpp" 10081ebf06SWludzik, Jozef 1189474494SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 1289474494SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 137e860f15SJohn Edward Broadbent 14081ebf06SWludzik, Jozef namespace redfish 15081ebf06SWludzik, Jozef { 16081ebf06SWludzik, Jozef 1726bd9b57SJohn Edward Broadbent inline void handleTelemetryServiceGet( 1845ca1b86SEd Tanous crow::App& app, const crow::Request& req, 19104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 20081ebf06SWludzik, Jozef { 213ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2245ca1b86SEd Tanous { 2345ca1b86SEd Tanous return; 2445ca1b86SEd Tanous } 258d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 26081ebf06SWludzik, Jozef "#TelemetryService.v1_2_1.TelemetryService"; 2726bd9b57SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; 288d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "TelemetryService"; 298d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Telemetry Service"; 30081ebf06SWludzik, Jozef 318d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = 32081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReportDefinitions"; 338d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = 34081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReports"; 3507148cf2SLukasz Kazmierczak asyncResp->res.jsonValue["Triggers"]["@odata.id"] = 3607148cf2SLukasz Kazmierczak "/redfish/v1/TelemetryService/Triggers"; 37081ebf06SWludzik, Jozef 3889474494SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 3989474494SKrzysztof Grobelny *crow::connections::systemBus, telemetry::service, 4089474494SKrzysztof Grobelny "/xyz/openbmc_project/Telemetry/Reports", 4189474494SKrzysztof Grobelny "xyz.openbmc_project.Telemetry.ReportManager", 425e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 43b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& ret) { 44081ebf06SWludzik, Jozef if (ec == boost::system::errc::host_unreachable) 45081ebf06SWludzik, Jozef { 46081ebf06SWludzik, Jozef asyncResp->res.jsonValue["Status"]["State"] = "Absent"; 47081ebf06SWludzik, Jozef return; 48081ebf06SWludzik, Jozef } 49081ebf06SWludzik, Jozef if (ec) 50081ebf06SWludzik, Jozef { 51081ebf06SWludzik, Jozef BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; 52081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 53081ebf06SWludzik, Jozef return; 54081ebf06SWludzik, Jozef } 55081ebf06SWludzik, Jozef 56081ebf06SWludzik, Jozef asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 57081ebf06SWludzik, Jozef 58081ebf06SWludzik, Jozef const size_t* maxReports = nullptr; 59081ebf06SWludzik, Jozef const uint64_t* minInterval = nullptr; 6089474494SKrzysztof Grobelny 6189474494SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 6289474494SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports, 6389474494SKrzysztof Grobelny "MinInterval", minInterval); 6489474494SKrzysztof Grobelny 6589474494SKrzysztof Grobelny if (!success) 66081ebf06SWludzik, Jozef { 67081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 68081ebf06SWludzik, Jozef return; 69081ebf06SWludzik, Jozef } 70081ebf06SWludzik, Jozef 7189474494SKrzysztof Grobelny if (maxReports != nullptr) 7289474494SKrzysztof Grobelny { 73081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MaxReports"] = *maxReports; 7489474494SKrzysztof Grobelny } 7589474494SKrzysztof Grobelny 7689474494SKrzysztof Grobelny if (minInterval != nullptr) 7789474494SKrzysztof Grobelny { 78081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MinCollectionInterval"] = 7989474494SKrzysztof Grobelny time_utils::toDurationString(std::chrono::milliseconds( 8089474494SKrzysztof Grobelny static_cast<time_t>(*minInterval))); 8189474494SKrzysztof Grobelny } 82*479e899dSKrzysztof Grobelny nlohmann::json::array_t supportedCollectionFunctions; 83*479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Maximum"); 84*479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Minimum"); 85*479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Average"); 86*479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Summation"); 87*479e899dSKrzysztof Grobelny 88*479e899dSKrzysztof Grobelny asyncResp->res.jsonValue["SupportedCollectionFunctions"] = 89*479e899dSKrzysztof Grobelny std::move(supportedCollectionFunctions); 9089474494SKrzysztof Grobelny }); 91081ebf06SWludzik, Jozef } 9226bd9b57SJohn Edward Broadbent 9326bd9b57SJohn Edward Broadbent inline void requestRoutesTelemetryService(App& app) 9426bd9b57SJohn Edward Broadbent { 9526bd9b57SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") 9626bd9b57SJohn Edward Broadbent .privileges(redfish::privileges::getTelemetryService) 9745ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 9845ca1b86SEd Tanous std::bind_front(handleTelemetryServiceGet, std::ref(app))); 9926bd9b57SJohn Edward Broadbent } 10026bd9b57SJohn Edward Broadbent 101081ebf06SWludzik, Jozef } // namespace redfish 102