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