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