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