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