1 #pragma once 2 3 #include "utils/telemetry_utils.hpp" 4 5 #include <app.hpp> 6 #include <dbus_utility.hpp> 7 #include <registries/privilege_registry.hpp> 8 9 namespace redfish 10 { 11 12 inline void handleTelemetryServiceGet( 13 const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 14 { 15 asyncResp->res.jsonValue["@odata.type"] = 16 "#TelemetryService.v1_2_1.TelemetryService"; 17 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; 18 asyncResp->res.jsonValue["Id"] = "TelemetryService"; 19 asyncResp->res.jsonValue["Name"] = "Telemetry Service"; 20 21 asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = 22 "/redfish/v1/TelemetryService/MetricReportDefinitions"; 23 asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = 24 "/redfish/v1/TelemetryService/MetricReports"; 25 asyncResp->res.jsonValue["Triggers"]["@odata.id"] = 26 "/redfish/v1/TelemetryService/Triggers"; 27 28 crow::connections::systemBus->async_method_call( 29 [asyncResp]( 30 const boost::system::error_code ec, 31 const std::vector< 32 std::pair<std::string, dbus::utility::DbusVariantType>>& ret) { 33 if (ec == boost::system::errc::host_unreachable) 34 { 35 asyncResp->res.jsonValue["Status"]["State"] = "Absent"; 36 return; 37 } 38 if (ec) 39 { 40 BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; 41 messages::internalError(asyncResp->res); 42 return; 43 } 44 45 asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 46 47 const size_t* maxReports = nullptr; 48 const uint64_t* minInterval = nullptr; 49 for (const auto& [key, var] : ret) 50 { 51 if (key == "MaxReports") 52 { 53 maxReports = std::get_if<size_t>(&var); 54 } 55 else if (key == "MinInterval") 56 { 57 minInterval = std::get_if<uint64_t>(&var); 58 } 59 } 60 if (!maxReports || !minInterval) 61 { 62 BMCWEB_LOG_ERROR 63 << "Property type mismatch or property is missing"; 64 messages::internalError(asyncResp->res); 65 return; 66 } 67 68 asyncResp->res.jsonValue["MaxReports"] = *maxReports; 69 asyncResp->res.jsonValue["MinCollectionInterval"] = 70 time_utils::toDurationString(std::chrono::milliseconds( 71 static_cast<time_t>(*minInterval))); 72 }, 73 telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", 74 "org.freedesktop.DBus.Properties", "GetAll", 75 "xyz.openbmc_project.Telemetry.ReportManager"); 76 } 77 78 inline void requestRoutesTelemetryService(App& app) 79 { 80 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") 81 .privileges(redfish::privileges::getTelemetryService) 82 .methods(boost::beast::http::verb::get)(handleTelemetryServiceGet); 83 } 84 85 } // namespace redfish 86