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 
67         if (crow::utility::readUrlSegments(*parsed, "redfish", "v1", "Chassis",
68                                            std::ref(chassis), "Sensors",
69                                            std::ref(ignoredSenorId)))
70         {
71             matched.emplace(std::move(chassis), "Sensors");
72             uriIdx++;
73             continue;
74         }
75 
76         BMCWEB_LOG_ERROR << "Failed to get chassis and sensor Node "
77                             "from "
78                          << uri;
79         return std::make_optional<IncorrectMetricUri>({uri, uriIdx});
80     }
81     return std::nullopt;
82 }
83 
84 } // namespace telemetry
85 } // namespace redfish
86