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