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