1 #pragma once 2 3 namespace redfish 4 { 5 6 namespace telemetry 7 { 8 9 constexpr const char* service = "xyz.openbmc_project.Telemetry"; 10 constexpr const char* reportInterface = "xyz.openbmc_project.Telemetry.Report"; 11 constexpr const char* metricReportDefinitionUri = 12 "/redfish/v1/TelemetryService/MetricReportDefinitions/"; 13 constexpr const char* metricReportUri = 14 "/redfish/v1/TelemetryService/MetricReports/"; 15 16 inline void getReportCollection(const std::shared_ptr<AsyncResp>& asyncResp, 17 const std::string& uri) 18 { 19 const std::array<const char*, 1> interfaces = {reportInterface}; 20 21 crow::connections::systemBus->async_method_call( 22 [asyncResp, uri](const boost::system::error_code ec, 23 const std::vector<std::string>& reports) { 24 if (ec == boost::system::errc::io_error) 25 { 26 asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 27 asyncResp->res.jsonValue["Members@odata.count"] = 0; 28 return; 29 } 30 if (ec) 31 { 32 BMCWEB_LOG_ERROR << "Dbus method call failed: " << ec; 33 messages::internalError(asyncResp->res); 34 return; 35 } 36 37 nlohmann::json& members = asyncResp->res.jsonValue["Members"]; 38 members = nlohmann::json::array(); 39 40 for (const std::string& report : reports) 41 { 42 sdbusplus::message::object_path path(report); 43 std::string name = path.filename(); 44 if (name.empty()) 45 { 46 BMCWEB_LOG_ERROR << "Received invalid path: " << report; 47 messages::internalError(asyncResp->res); 48 return; 49 } 50 members.push_back({{"@odata.id", uri + name}}); 51 } 52 53 asyncResp->res.jsonValue["Members@odata.count"] = members.size(); 54 }, 55 "xyz.openbmc_project.ObjectMapper", 56 "/xyz/openbmc_project/object_mapper", 57 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 58 "/xyz/openbmc_project/Telemetry/Reports/TelemetryService", 1, 59 interfaces); 60 } 61 62 inline std::string getDbusReportPath(const std::string& id) 63 { 64 std::string path = 65 "/xyz/openbmc_project/Telemetry/Reports/TelemetryService/" + id; 66 dbus::utility::escapePathForDbus(path); 67 return path; 68 } 69 70 } // namespace telemetry 71 } // namespace redfish 72