1 #pragma once 2 3 #include "dbus_utility.hpp" 4 #include "utility.hpp" 5 6 namespace redfish 7 { 8 9 namespace telemetry 10 { 11 constexpr const char* service = "xyz.openbmc_project.Telemetry"; 12 constexpr const char* reportInterface = "xyz.openbmc_project.Telemetry.Report"; 13 14 inline std::string getDbusReportPath(const std::string& id) 15 { 16 sdbusplus::message::object_path reportsPath( 17 "/xyz/openbmc_project/Telemetry/Reports/TelemetryService"); 18 return {reportsPath / id}; 19 } 20 21 inline std::string getDbusTriggerPath(const std::string& id) 22 { 23 sdbusplus::message::object_path triggersPath( 24 "/xyz/openbmc_project/Telemetry/Triggers/TelemetryService"); 25 return {triggersPath / id}; 26 } 27 28 struct IncorrectMetricUri 29 { 30 std::string uri; 31 size_t index; 32 }; 33 34 inline std::optional<IncorrectMetricUri> getChassisSensorNode( 35 const std::vector<std::string>& uris, 36 boost::container::flat_set<std::pair<std::string, std::string>>& matched) 37 { 38 size_t uriIdx = 0; 39 for (const std::string& uri : uris) 40 { 41 boost::urls::result<boost::urls::url_view> parsed = 42 boost::urls::parse_relative_ref(uri); 43 44 if (!parsed) 45 { 46 BMCWEB_LOG_ERROR << "Failed to get chassis and sensor Node " 47 "from " 48 << uri; 49 return std::make_optional<IncorrectMetricUri>({uri, uriIdx}); 50 } 51 52 std::string chassis; 53 std::string node; 54 55 if (crow::utility::readUrlSegments(*parsed, "redfish", "v1", "Chassis", 56 std::ref(chassis), std::ref(node))) 57 { 58 matched.emplace(std::move(chassis), std::move(node)); 59 uriIdx++; 60 continue; 61 } 62 63 // Those 2 segments cannot be validated here, as we don't know which 64 // sensors exist at the moment of parsing. 65 std::string ignoredSenorId; 66 std::string ignoredSensorUnit; 67 68 if (crow::utility::readUrlSegments(*parsed, "redfish", "v1", "Chassis", 69 std::ref(chassis), "Sensors", 70 std::ref(ignoredSenorId), 71 std::ref(ignoredSensorUnit))) 72 { 73 matched.emplace(std::move(chassis), "Sensors"); 74 uriIdx++; 75 continue; 76 } 77 78 BMCWEB_LOG_ERROR << "Failed to get chassis and sensor Node " 79 "from " 80 << uri; 81 return std::make_optional<IncorrectMetricUri>({uri, uriIdx}); 82 } 83 return std::nullopt; 84 } 85 86 } // namespace telemetry 87 } // namespace redfish 88