1081ebf06SWludzik, Jozef #pragma once 2081ebf06SWludzik, Jozef 3081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp" 4081ebf06SWludzik, Jozef 57e860f15SJohn Edward Broadbent #include <app.hpp> 6168e20c1SEd Tanous #include <dbus_utility.hpp> 745ca1b86SEd Tanous #include <query.hpp> 8ed398213SEd Tanous #include <registries/privilege_registry.hpp> 9*89474494SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 10*89474494SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 11*89474494SKrzysztof Grobelny #include <utils/dbus_utils.hpp> 127e860f15SJohn Edward Broadbent 13081ebf06SWludzik, Jozef namespace redfish 14081ebf06SWludzik, Jozef { 15081ebf06SWludzik, Jozef 1626bd9b57SJohn Edward Broadbent inline void handleTelemetryServiceGet( 1745ca1b86SEd Tanous crow::App& app, const crow::Request& req, 18104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 19081ebf06SWludzik, Jozef { 203ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2145ca1b86SEd Tanous { 2245ca1b86SEd Tanous return; 2345ca1b86SEd Tanous } 248d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 25081ebf06SWludzik, Jozef "#TelemetryService.v1_2_1.TelemetryService"; 2626bd9b57SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; 278d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "TelemetryService"; 288d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Telemetry Service"; 29081ebf06SWludzik, Jozef 308d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = 31081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReportDefinitions"; 328d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = 33081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReports"; 3407148cf2SLukasz Kazmierczak asyncResp->res.jsonValue["Triggers"]["@odata.id"] = 3507148cf2SLukasz Kazmierczak "/redfish/v1/TelemetryService/Triggers"; 36081ebf06SWludzik, Jozef 37*89474494SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 38*89474494SKrzysztof Grobelny *crow::connections::systemBus, telemetry::service, 39*89474494SKrzysztof Grobelny "/xyz/openbmc_project/Telemetry/Reports", 40*89474494SKrzysztof Grobelny "xyz.openbmc_project.Telemetry.ReportManager", 41b9d36b47SEd Tanous [asyncResp](const boost::system::error_code ec, 42b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& ret) { 43081ebf06SWludzik, Jozef if (ec == boost::system::errc::host_unreachable) 44081ebf06SWludzik, Jozef { 45081ebf06SWludzik, Jozef asyncResp->res.jsonValue["Status"]["State"] = "Absent"; 46081ebf06SWludzik, Jozef return; 47081ebf06SWludzik, Jozef } 48081ebf06SWludzik, Jozef if (ec) 49081ebf06SWludzik, Jozef { 50081ebf06SWludzik, Jozef BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; 51081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 52081ebf06SWludzik, Jozef return; 53081ebf06SWludzik, Jozef } 54081ebf06SWludzik, Jozef 55081ebf06SWludzik, Jozef asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 56081ebf06SWludzik, Jozef 57081ebf06SWludzik, Jozef const size_t* maxReports = nullptr; 58081ebf06SWludzik, Jozef const uint64_t* minInterval = nullptr; 59*89474494SKrzysztof Grobelny 60*89474494SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 61*89474494SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports, 62*89474494SKrzysztof Grobelny "MinInterval", minInterval); 63*89474494SKrzysztof Grobelny 64*89474494SKrzysztof Grobelny if (!success) 65081ebf06SWludzik, Jozef { 66081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 67081ebf06SWludzik, Jozef return; 68081ebf06SWludzik, Jozef } 69081ebf06SWludzik, Jozef 70*89474494SKrzysztof Grobelny if (maxReports != nullptr) 71*89474494SKrzysztof Grobelny { 72081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MaxReports"] = *maxReports; 73*89474494SKrzysztof Grobelny } 74*89474494SKrzysztof Grobelny 75*89474494SKrzysztof Grobelny if (minInterval != nullptr) 76*89474494SKrzysztof Grobelny { 77081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MinCollectionInterval"] = 78*89474494SKrzysztof Grobelny time_utils::toDurationString(std::chrono::milliseconds( 79*89474494SKrzysztof Grobelny static_cast<time_t>(*minInterval))); 80*89474494SKrzysztof Grobelny } 81*89474494SKrzysztof Grobelny }); 82081ebf06SWludzik, Jozef } 8326bd9b57SJohn Edward Broadbent 8426bd9b57SJohn Edward Broadbent inline void requestRoutesTelemetryService(App& app) 8526bd9b57SJohn Edward Broadbent { 8626bd9b57SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") 8726bd9b57SJohn Edward Broadbent .privileges(redfish::privileges::getTelemetryService) 8845ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 8945ca1b86SEd Tanous std::bind_front(handleTelemetryServiceGet, std::ref(app))); 9026bd9b57SJohn Edward Broadbent } 9126bd9b57SJohn Edward Broadbent 92081ebf06SWludzik, Jozef } // namespace redfish 93