1081ebf06SWludzik, Jozef #pragma once 2081ebf06SWludzik, Jozef 33ccb3adbSEd Tanous #include "app.hpp" 43ccb3adbSEd Tanous #include "dbus_utility.hpp" 5539d8c6bSEd Tanous #include "generated/enums/resource.hpp" 63ccb3adbSEd Tanous #include "query.hpp" 73ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 83ccb3adbSEd Tanous #include "utils/dbus_utils.hpp" 9081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp" 10d093c996SEd Tanous #include "utils/time_utils.hpp" 11081ebf06SWludzik, Jozef 1289474494SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 1389474494SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 147e860f15SJohn Edward Broadbent 15081ebf06SWludzik, Jozef namespace redfish 16081ebf06SWludzik, Jozef { 17081ebf06SWludzik, Jozef 1826bd9b57SJohn Edward Broadbent inline void handleTelemetryServiceGet( 1945ca1b86SEd Tanous crow::App& app, const crow::Request& req, 20104f09c9SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 21081ebf06SWludzik, Jozef { 223ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2345ca1b86SEd Tanous { 2445ca1b86SEd Tanous return; 2545ca1b86SEd Tanous } 268d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 27081ebf06SWludzik, Jozef "#TelemetryService.v1_2_1.TelemetryService"; 2826bd9b57SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; 298d1b46d7Szhanghch05 asyncResp->res.jsonValue["Id"] = "TelemetryService"; 308d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Telemetry Service"; 31081ebf06SWludzik, Jozef 328d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = 33081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReportDefinitions"; 348d1b46d7Szhanghch05 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = 35081ebf06SWludzik, Jozef "/redfish/v1/TelemetryService/MetricReports"; 3607148cf2SLukasz Kazmierczak asyncResp->res.jsonValue["Triggers"]["@odata.id"] = 3707148cf2SLukasz Kazmierczak "/redfish/v1/TelemetryService/Triggers"; 38081ebf06SWludzik, Jozef 3989474494SKrzysztof Grobelny sdbusplus::asio::getAllProperties( 4089474494SKrzysztof Grobelny *crow::connections::systemBus, telemetry::service, 4189474494SKrzysztof Grobelny "/xyz/openbmc_project/Telemetry/Reports", 4289474494SKrzysztof Grobelny "xyz.openbmc_project.Telemetry.ReportManager", 435e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 44b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& ret) { 45081ebf06SWludzik, Jozef if (ec == boost::system::errc::host_unreachable) 46081ebf06SWludzik, Jozef { 47539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 48539d8c6bSEd Tanous resource::State::Absent; 49081ebf06SWludzik, Jozef return; 50081ebf06SWludzik, Jozef } 51081ebf06SWludzik, Jozef if (ec) 52081ebf06SWludzik, Jozef { 5362598e31SEd Tanous BMCWEB_LOG_ERROR("respHandler DBus error {}", ec); 54081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 55081ebf06SWludzik, Jozef return; 56081ebf06SWludzik, Jozef } 57081ebf06SWludzik, Jozef 58*bd79bce8SPatrick Williams asyncResp->res.jsonValue["Status"]["State"] = 59*bd79bce8SPatrick Williams resource::State::Enabled; 60081ebf06SWludzik, Jozef 61081ebf06SWludzik, Jozef const size_t* maxReports = nullptr; 62081ebf06SWludzik, Jozef const uint64_t* minInterval = nullptr; 6389474494SKrzysztof Grobelny 6489474494SKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 6589474494SKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), ret, "MaxReports", maxReports, 6689474494SKrzysztof Grobelny "MinInterval", minInterval); 6789474494SKrzysztof Grobelny 6889474494SKrzysztof Grobelny if (!success) 69081ebf06SWludzik, Jozef { 70081ebf06SWludzik, Jozef messages::internalError(asyncResp->res); 71081ebf06SWludzik, Jozef return; 72081ebf06SWludzik, Jozef } 73081ebf06SWludzik, Jozef 7489474494SKrzysztof Grobelny if (maxReports != nullptr) 7589474494SKrzysztof Grobelny { 76081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MaxReports"] = *maxReports; 7789474494SKrzysztof Grobelny } 7889474494SKrzysztof Grobelny 7989474494SKrzysztof Grobelny if (minInterval != nullptr) 8089474494SKrzysztof Grobelny { 81081ebf06SWludzik, Jozef asyncResp->res.jsonValue["MinCollectionInterval"] = 8289474494SKrzysztof Grobelny time_utils::toDurationString(std::chrono::milliseconds( 8389474494SKrzysztof Grobelny static_cast<time_t>(*minInterval))); 8489474494SKrzysztof Grobelny } 85479e899dSKrzysztof Grobelny nlohmann::json::array_t supportedCollectionFunctions; 86479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Maximum"); 87479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Minimum"); 88479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Average"); 89479e899dSKrzysztof Grobelny supportedCollectionFunctions.emplace_back("Summation"); 90479e899dSKrzysztof Grobelny 91479e899dSKrzysztof Grobelny asyncResp->res.jsonValue["SupportedCollectionFunctions"] = 92479e899dSKrzysztof Grobelny std::move(supportedCollectionFunctions); 9389474494SKrzysztof Grobelny }); 94081ebf06SWludzik, Jozef } 9526bd9b57SJohn Edward Broadbent 9626bd9b57SJohn Edward Broadbent inline void requestRoutesTelemetryService(App& app) 9726bd9b57SJohn Edward Broadbent { 9826bd9b57SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") 9926bd9b57SJohn Edward Broadbent .privileges(redfish::privileges::getTelemetryService) 10045ca1b86SEd Tanous .methods(boost::beast::http::verb::get)( 10145ca1b86SEd Tanous std::bind_front(handleTelemetryServiceGet, std::ref(app))); 10226bd9b57SJohn Edward Broadbent } 10326bd9b57SJohn Edward Broadbent 104081ebf06SWludzik, Jozef } // namespace redfish 105