xref: /openbmc/bmcweb/features/redfish/lib/metric_report_definition.hpp (revision b4361d638097f3e6636c712600fa2449c71b61cc)
1081ebf06SWludzik, Jozef #pragma once
2081ebf06SWludzik, Jozef 
33ccb3adbSEd Tanous #include "app.hpp"
43ccb3adbSEd Tanous #include "dbus_utility.hpp"
5479e899dSKrzysztof Grobelny #include "generated/enums/metric_report_definition.hpp"
6539d8c6bSEd Tanous #include "generated/enums/resource.hpp"
73ccb3adbSEd Tanous #include "query.hpp"
83ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
94dbb8aeaSWludzik, Jozef #include "sensors.hpp"
103ccb3adbSEd Tanous #include "utils/collection.hpp"
113ccb3adbSEd Tanous #include "utils/dbus_utils.hpp"
125b90429aSEd Tanous #include "utils/json_utils.hpp"
13081ebf06SWludzik, Jozef #include "utils/telemetry_utils.hpp"
14081ebf06SWludzik, Jozef #include "utils/time_utils.hpp"
15081ebf06SWludzik, Jozef 
164dbb8aeaSWludzik, Jozef #include <boost/container/flat_map.hpp>
17ef4c65b7SEd Tanous #include <boost/url/format.hpp>
1889474494SKrzysztof Grobelny #include <sdbusplus/asio/property.hpp>
1989474494SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
204dbb8aeaSWludzik, Jozef 
217a1dbc48SGeorge Liu #include <array>
22fe04d49cSNan Zhou #include <map>
23f19ab44aSSzymon Dompke #include <optional>
24f19ab44aSSzymon Dompke #include <span>
25f19ab44aSSzymon Dompke #include <string>
267a1dbc48SGeorge Liu #include <string_view>
27081ebf06SWludzik, Jozef #include <tuple>
28f19ab44aSSzymon Dompke #include <utility>
29081ebf06SWludzik, Jozef #include <variant>
30f19ab44aSSzymon Dompke #include <vector>
31081ebf06SWludzik, Jozef 
32081ebf06SWludzik, Jozef namespace redfish
33081ebf06SWludzik, Jozef {
34081ebf06SWludzik, Jozef 
35081ebf06SWludzik, Jozef namespace telemetry
36081ebf06SWludzik, Jozef {
37081ebf06SWludzik, Jozef 
38479e899dSKrzysztof Grobelny using ReadingParameters = std::vector<std::tuple<
39479e899dSKrzysztof Grobelny     std::vector<std::tuple<sdbusplus::message::object_path, std::string>>,
40479e899dSKrzysztof Grobelny     std::string, std::string, uint64_t>>;
41479e899dSKrzysztof Grobelny 
429e6c388aSLukasz Kazmierczak inline bool verifyCommonErrors(crow::Response& res, const std::string& id,
439e6c388aSLukasz Kazmierczak                                const boost::system::error_code& ec)
449e6c388aSLukasz Kazmierczak {
459e6c388aSLukasz Kazmierczak     if (ec.value() == EBADR || ec == boost::system::errc::host_unreachable)
469e6c388aSLukasz Kazmierczak     {
479e6c388aSLukasz Kazmierczak         messages::resourceNotFound(res, "MetricReportDefinition", id);
489e6c388aSLukasz Kazmierczak         return false;
499e6c388aSLukasz Kazmierczak     }
509e6c388aSLukasz Kazmierczak 
519e6c388aSLukasz Kazmierczak     if (ec == boost::system::errc::file_exists)
529e6c388aSLukasz Kazmierczak     {
539e6c388aSLukasz Kazmierczak         messages::resourceAlreadyExists(res, "MetricReportDefinition", "Id",
549e6c388aSLukasz Kazmierczak                                         id);
559e6c388aSLukasz Kazmierczak         return false;
569e6c388aSLukasz Kazmierczak     }
579e6c388aSLukasz Kazmierczak 
589e6c388aSLukasz Kazmierczak     if (ec == boost::system::errc::too_many_files_open)
599e6c388aSLukasz Kazmierczak     {
609e6c388aSLukasz Kazmierczak         messages::createLimitReachedForResource(res);
619e6c388aSLukasz Kazmierczak         return false;
629e6c388aSLukasz Kazmierczak     }
639e6c388aSLukasz Kazmierczak 
649e6c388aSLukasz Kazmierczak     if (ec)
659e6c388aSLukasz Kazmierczak     {
669e6c388aSLukasz Kazmierczak         BMCWEB_LOG_ERROR("DBUS response error {}", ec);
679e6c388aSLukasz Kazmierczak         messages::internalError(res);
689e6c388aSLukasz Kazmierczak         return false;
699e6c388aSLukasz Kazmierczak     }
709e6c388aSLukasz Kazmierczak 
719e6c388aSLukasz Kazmierczak     return true;
729e6c388aSLukasz Kazmierczak }
739e6c388aSLukasz Kazmierczak 
74479e899dSKrzysztof Grobelny inline metric_report_definition::ReportActionsEnum
75479e899dSKrzysztof Grobelny     toRedfishReportAction(std::string_view dbusValue)
76479e899dSKrzysztof Grobelny {
77479e899dSKrzysztof Grobelny     if (dbusValue ==
78479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportActions.EmitsReadingsUpdate")
79479e899dSKrzysztof Grobelny     {
80479e899dSKrzysztof Grobelny         return metric_report_definition::ReportActionsEnum::RedfishEvent;
81479e899dSKrzysztof Grobelny     }
82479e899dSKrzysztof Grobelny     if (dbusValue ==
83479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportActions.LogToMetricReportsCollection")
84479e899dSKrzysztof Grobelny     {
85479e899dSKrzysztof Grobelny         return metric_report_definition::ReportActionsEnum::
86479e899dSKrzysztof Grobelny             LogToMetricReportsCollection;
87479e899dSKrzysztof Grobelny     }
88479e899dSKrzysztof Grobelny     return metric_report_definition::ReportActionsEnum::Invalid;
89479e899dSKrzysztof Grobelny }
90479e899dSKrzysztof Grobelny 
91479e899dSKrzysztof Grobelny inline std::string toDbusReportAction(std::string_view redfishValue)
92479e899dSKrzysztof Grobelny {
93479e899dSKrzysztof Grobelny     if (redfishValue == "RedfishEvent")
94479e899dSKrzysztof Grobelny     {
95479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportActions.EmitsReadingsUpdate";
96479e899dSKrzysztof Grobelny     }
97479e899dSKrzysztof Grobelny     if (redfishValue == "LogToMetricReportsCollection")
98479e899dSKrzysztof Grobelny     {
99479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportActions.LogToMetricReportsCollection";
100479e899dSKrzysztof Grobelny     }
101479e899dSKrzysztof Grobelny     return "";
102479e899dSKrzysztof Grobelny }
103479e899dSKrzysztof Grobelny 
104479e899dSKrzysztof Grobelny inline metric_report_definition::MetricReportDefinitionType
105479e899dSKrzysztof Grobelny     toRedfishReportingType(std::string_view dbusValue)
106479e899dSKrzysztof Grobelny {
107479e899dSKrzysztof Grobelny     if (dbusValue ==
108479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportingType.OnChange")
109479e899dSKrzysztof Grobelny     {
110479e899dSKrzysztof Grobelny         return metric_report_definition::MetricReportDefinitionType::OnChange;
111479e899dSKrzysztof Grobelny     }
112479e899dSKrzysztof Grobelny     if (dbusValue ==
113479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportingType.OnRequest")
114479e899dSKrzysztof Grobelny     {
115479e899dSKrzysztof Grobelny         return metric_report_definition::MetricReportDefinitionType::OnRequest;
116479e899dSKrzysztof Grobelny     }
117479e899dSKrzysztof Grobelny     if (dbusValue ==
118479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportingType.Periodic")
119479e899dSKrzysztof Grobelny     {
120479e899dSKrzysztof Grobelny         return metric_report_definition::MetricReportDefinitionType::Periodic;
121479e899dSKrzysztof Grobelny     }
122479e899dSKrzysztof Grobelny     return metric_report_definition::MetricReportDefinitionType::Invalid;
123479e899dSKrzysztof Grobelny }
124479e899dSKrzysztof Grobelny 
125479e899dSKrzysztof Grobelny inline std::string toDbusReportingType(std::string_view redfishValue)
126479e899dSKrzysztof Grobelny {
127479e899dSKrzysztof Grobelny     if (redfishValue == "OnChange")
128479e899dSKrzysztof Grobelny     {
129479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportingType.OnChange";
130479e899dSKrzysztof Grobelny     }
131479e899dSKrzysztof Grobelny     if (redfishValue == "OnRequest")
132479e899dSKrzysztof Grobelny     {
133479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportingType.OnRequest";
134479e899dSKrzysztof Grobelny     }
135479e899dSKrzysztof Grobelny     if (redfishValue == "Periodic")
136479e899dSKrzysztof Grobelny     {
137479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportingType.Periodic";
138479e899dSKrzysztof Grobelny     }
139479e899dSKrzysztof Grobelny     return "";
140479e899dSKrzysztof Grobelny }
141479e899dSKrzysztof Grobelny 
142479e899dSKrzysztof Grobelny inline metric_report_definition::CollectionTimeScope
143479e899dSKrzysztof Grobelny     toRedfishCollectionTimeScope(std::string_view dbusValue)
144479e899dSKrzysztof Grobelny {
145479e899dSKrzysztof Grobelny     if (dbusValue ==
146479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.CollectionTimescope.Point")
147479e899dSKrzysztof Grobelny     {
148479e899dSKrzysztof Grobelny         return metric_report_definition::CollectionTimeScope::Point;
149479e899dSKrzysztof Grobelny     }
150479e899dSKrzysztof Grobelny     if (dbusValue ==
151479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.CollectionTimescope.Interval")
152479e899dSKrzysztof Grobelny     {
153479e899dSKrzysztof Grobelny         return metric_report_definition::CollectionTimeScope::Interval;
154479e899dSKrzysztof Grobelny     }
155479e899dSKrzysztof Grobelny     if (dbusValue ==
156479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.CollectionTimescope.StartupInterval")
157479e899dSKrzysztof Grobelny     {
158479e899dSKrzysztof Grobelny         return metric_report_definition::CollectionTimeScope::StartupInterval;
159479e899dSKrzysztof Grobelny     }
160479e899dSKrzysztof Grobelny     return metric_report_definition::CollectionTimeScope::Invalid;
161479e899dSKrzysztof Grobelny }
162479e899dSKrzysztof Grobelny 
163479e899dSKrzysztof Grobelny inline std::string toDbusCollectionTimeScope(std::string_view redfishValue)
164479e899dSKrzysztof Grobelny {
165479e899dSKrzysztof Grobelny     if (redfishValue == "Point")
166479e899dSKrzysztof Grobelny     {
167479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.CollectionTimescope.Point";
168479e899dSKrzysztof Grobelny     }
169479e899dSKrzysztof Grobelny     if (redfishValue == "Interval")
170479e899dSKrzysztof Grobelny     {
171479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.CollectionTimescope.Interval";
172479e899dSKrzysztof Grobelny     }
173479e899dSKrzysztof Grobelny     if (redfishValue == "StartupInterval")
174479e899dSKrzysztof Grobelny     {
175479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.CollectionTimescope.StartupInterval";
176479e899dSKrzysztof Grobelny     }
177479e899dSKrzysztof Grobelny     return "";
178479e899dSKrzysztof Grobelny }
179479e899dSKrzysztof Grobelny 
180479e899dSKrzysztof Grobelny inline metric_report_definition::ReportUpdatesEnum
181479e899dSKrzysztof Grobelny     toRedfishReportUpdates(std::string_view dbusValue)
182479e899dSKrzysztof Grobelny {
183479e899dSKrzysztof Grobelny     if (dbusValue ==
184479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportUpdates.Overwrite")
185479e899dSKrzysztof Grobelny     {
186479e899dSKrzysztof Grobelny         return metric_report_definition::ReportUpdatesEnum::Overwrite;
187479e899dSKrzysztof Grobelny     }
188479e899dSKrzysztof Grobelny     if (dbusValue ==
189479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportUpdates.AppendWrapsWhenFull")
190479e899dSKrzysztof Grobelny     {
191479e899dSKrzysztof Grobelny         return metric_report_definition::ReportUpdatesEnum::AppendWrapsWhenFull;
192479e899dSKrzysztof Grobelny     }
193479e899dSKrzysztof Grobelny     if (dbusValue ==
194479e899dSKrzysztof Grobelny         "xyz.openbmc_project.Telemetry.Report.ReportUpdates.AppendStopsWhenFull")
195479e899dSKrzysztof Grobelny     {
196479e899dSKrzysztof Grobelny         return metric_report_definition::ReportUpdatesEnum::AppendStopsWhenFull;
197479e899dSKrzysztof Grobelny     }
198479e899dSKrzysztof Grobelny     return metric_report_definition::ReportUpdatesEnum::Invalid;
199479e899dSKrzysztof Grobelny }
200479e899dSKrzysztof Grobelny 
201479e899dSKrzysztof Grobelny inline std::string toDbusReportUpdates(std::string_view redfishValue)
202479e899dSKrzysztof Grobelny {
203479e899dSKrzysztof Grobelny     if (redfishValue == "Overwrite")
204479e899dSKrzysztof Grobelny     {
205479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportUpdates.Overwrite";
206479e899dSKrzysztof Grobelny     }
207479e899dSKrzysztof Grobelny     if (redfishValue == "AppendWrapsWhenFull")
208479e899dSKrzysztof Grobelny     {
209479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportUpdates.AppendWrapsWhenFull";
210479e899dSKrzysztof Grobelny     }
211479e899dSKrzysztof Grobelny     if (redfishValue == "AppendStopsWhenFull")
212479e899dSKrzysztof Grobelny     {
213479e899dSKrzysztof Grobelny         return "xyz.openbmc_project.Telemetry.Report.ReportUpdates.AppendStopsWhenFull";
214479e899dSKrzysztof Grobelny     }
215479e899dSKrzysztof Grobelny     return "";
216479e899dSKrzysztof Grobelny }
217081ebf06SWludzik, Jozef 
218f19ab44aSSzymon Dompke inline std::optional<nlohmann::json::array_t> getLinkedTriggers(
219f19ab44aSSzymon Dompke     std::span<const sdbusplus::message::object_path> triggerPaths)
220f19ab44aSSzymon Dompke {
221f19ab44aSSzymon Dompke     nlohmann::json::array_t triggers;
222f19ab44aSSzymon Dompke 
223f19ab44aSSzymon Dompke     for (const sdbusplus::message::object_path& path : triggerPaths)
224f19ab44aSSzymon Dompke     {
225f19ab44aSSzymon Dompke         if (path.parent_path() !=
226f19ab44aSSzymon Dompke             "/xyz/openbmc_project/Telemetry/Triggers/TelemetryService")
227f19ab44aSSzymon Dompke         {
22862598e31SEd Tanous             BMCWEB_LOG_ERROR("Property Triggers contains invalid value: {}",
22962598e31SEd Tanous                              path.str);
230f19ab44aSSzymon Dompke             return std::nullopt;
231f19ab44aSSzymon Dompke         }
232f19ab44aSSzymon Dompke 
233f19ab44aSSzymon Dompke         std::string id = path.filename();
234f19ab44aSSzymon Dompke         if (id.empty())
235f19ab44aSSzymon Dompke         {
23662598e31SEd Tanous             BMCWEB_LOG_ERROR("Property Triggers contains invalid value: {}",
23762598e31SEd Tanous                              path.str);
238f19ab44aSSzymon Dompke             return std::nullopt;
239f19ab44aSSzymon Dompke         }
240f19ab44aSSzymon Dompke         nlohmann::json::object_t trigger;
241f19ab44aSSzymon Dompke         trigger["@odata.id"] =
242f19ab44aSSzymon Dompke             boost::urls::format("/redfish/v1/TelemetryService/Triggers/{}", id);
243f19ab44aSSzymon Dompke         triggers.emplace_back(std::move(trigger));
244f19ab44aSSzymon Dompke     }
245f19ab44aSSzymon Dompke 
246f19ab44aSSzymon Dompke     return triggers;
247f19ab44aSSzymon Dompke }
248f19ab44aSSzymon Dompke 
249bd79bce8SPatrick Williams inline void fillReportDefinition(
250bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id,
251479e899dSKrzysztof Grobelny     const dbus::utility::DBusPropertiesMap& properties)
252081ebf06SWludzik, Jozef {
253479e899dSKrzysztof Grobelny     std::vector<std::string> reportActions;
254479e899dSKrzysztof Grobelny     ReadingParameters readingParams;
255479e899dSKrzysztof Grobelny     std::string reportingType;
256479e899dSKrzysztof Grobelny     std::string reportUpdates;
257479e899dSKrzysztof Grobelny     std::string name;
258479e899dSKrzysztof Grobelny     uint64_t appendLimit = 0;
259479e899dSKrzysztof Grobelny     uint64_t interval = 0;
260479e899dSKrzysztof Grobelny     bool enabled = false;
261f19ab44aSSzymon Dompke     std::vector<sdbusplus::message::object_path> triggers;
26289474494SKrzysztof Grobelny 
26389474494SKrzysztof Grobelny     const bool success = sdbusplus::unpackPropertiesNoThrow(
264479e899dSKrzysztof Grobelny         dbus_utils::UnpackErrorPrinter(), properties, "ReportingType",
265479e899dSKrzysztof Grobelny         reportingType, "Interval", interval, "ReportActions", reportActions,
266479e899dSKrzysztof Grobelny         "ReportUpdates", reportUpdates, "AppendLimit", appendLimit,
267f19ab44aSSzymon Dompke         "ReadingParameters", readingParams, "Name", name, "Enabled", enabled,
268f19ab44aSSzymon Dompke         "Triggers", triggers);
26989474494SKrzysztof Grobelny 
27089474494SKrzysztof Grobelny     if (!success)
271081ebf06SWludzik, Jozef     {
272081ebf06SWludzik, Jozef         messages::internalError(asyncResp->res);
273081ebf06SWludzik, Jozef         return;
274081ebf06SWludzik, Jozef     }
275081ebf06SWludzik, Jozef 
276479e899dSKrzysztof Grobelny     metric_report_definition::MetricReportDefinitionType redfishReportingType =
277479e899dSKrzysztof Grobelny         toRedfishReportingType(reportingType);
278479e899dSKrzysztof Grobelny     if (redfishReportingType ==
279479e899dSKrzysztof Grobelny         metric_report_definition::MetricReportDefinitionType::Invalid)
280081ebf06SWludzik, Jozef     {
281479e899dSKrzysztof Grobelny         messages::internalError(asyncResp->res);
282479e899dSKrzysztof Grobelny         return;
283081ebf06SWludzik, Jozef     }
28489474494SKrzysztof Grobelny 
285479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["MetricReportDefinitionType"] =
286479e899dSKrzysztof Grobelny         redfishReportingType;
287479e899dSKrzysztof Grobelny 
288f19ab44aSSzymon Dompke     std::optional<nlohmann::json::array_t> linkedTriggers =
289f19ab44aSSzymon Dompke         getLinkedTriggers(triggers);
290f19ab44aSSzymon Dompke     if (!linkedTriggers)
291f19ab44aSSzymon Dompke     {
292f19ab44aSSzymon Dompke         messages::internalError(asyncResp->res);
293f19ab44aSSzymon Dompke         return;
294f19ab44aSSzymon Dompke     }
295f19ab44aSSzymon Dompke 
296f19ab44aSSzymon Dompke     asyncResp->res.jsonValue["Links"]["Triggers"] = std::move(*linkedTriggers);
297f19ab44aSSzymon Dompke 
298479e899dSKrzysztof Grobelny     nlohmann::json::array_t redfishReportActions;
299479e899dSKrzysztof Grobelny     for (const std::string& action : reportActions)
300081ebf06SWludzik, Jozef     {
301479e899dSKrzysztof Grobelny         metric_report_definition::ReportActionsEnum redfishAction =
302479e899dSKrzysztof Grobelny             toRedfishReportAction(action);
303479e899dSKrzysztof Grobelny         if (redfishAction ==
304479e899dSKrzysztof Grobelny             metric_report_definition::ReportActionsEnum::Invalid)
305479e899dSKrzysztof Grobelny         {
306479e899dSKrzysztof Grobelny             messages::internalError(asyncResp->res);
307479e899dSKrzysztof Grobelny             return;
308081ebf06SWludzik, Jozef         }
309081ebf06SWludzik, Jozef 
310479e899dSKrzysztof Grobelny         redfishReportActions.emplace_back(redfishAction);
311479e899dSKrzysztof Grobelny     }
312479e899dSKrzysztof Grobelny 
313479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["ReportActions"] = std::move(redfishReportActions);
314479e899dSKrzysztof Grobelny 
315479e899dSKrzysztof Grobelny     nlohmann::json::array_t metrics = nlohmann::json::array();
316479e899dSKrzysztof Grobelny     for (const auto& [sensorData, collectionFunction, collectionTimeScope,
317479e899dSKrzysztof Grobelny                       collectionDuration] : readingParams)
31889474494SKrzysztof Grobelny     {
319479e899dSKrzysztof Grobelny         nlohmann::json::array_t metricProperties;
320479e899dSKrzysztof Grobelny 
321479e899dSKrzysztof Grobelny         for (const auto& [sensorPath, sensorMetadata] : sensorData)
322081ebf06SWludzik, Jozef         {
323479e899dSKrzysztof Grobelny             metricProperties.emplace_back(sensorMetadata);
324479e899dSKrzysztof Grobelny         }
325479e899dSKrzysztof Grobelny 
326613dabeaSEd Tanous         nlohmann::json::object_t metric;
327479e899dSKrzysztof Grobelny 
328479e899dSKrzysztof Grobelny         metric_report_definition::CalculationAlgorithmEnum
329479e899dSKrzysztof Grobelny             redfishCollectionFunction =
330479e899dSKrzysztof Grobelny                 telemetry::toRedfishCollectionFunction(collectionFunction);
331479e899dSKrzysztof Grobelny         if (redfishCollectionFunction ==
332479e899dSKrzysztof Grobelny             metric_report_definition::CalculationAlgorithmEnum::Invalid)
333479e899dSKrzysztof Grobelny         {
334479e899dSKrzysztof Grobelny             messages::internalError(asyncResp->res);
335479e899dSKrzysztof Grobelny             return;
336479e899dSKrzysztof Grobelny         }
337479e899dSKrzysztof Grobelny         metric["CollectionFunction"] = redfishCollectionFunction;
338479e899dSKrzysztof Grobelny 
339479e899dSKrzysztof Grobelny         metric_report_definition::CollectionTimeScope
340479e899dSKrzysztof Grobelny             redfishCollectionTimeScope =
341479e899dSKrzysztof Grobelny                 toRedfishCollectionTimeScope(collectionTimeScope);
342479e899dSKrzysztof Grobelny         if (redfishCollectionTimeScope ==
343479e899dSKrzysztof Grobelny             metric_report_definition::CollectionTimeScope::Invalid)
344479e899dSKrzysztof Grobelny         {
345479e899dSKrzysztof Grobelny             messages::internalError(asyncResp->res);
346479e899dSKrzysztof Grobelny             return;
347479e899dSKrzysztof Grobelny         }
348479e899dSKrzysztof Grobelny         metric["CollectionTimeScope"] = redfishCollectionTimeScope;
349479e899dSKrzysztof Grobelny 
350479e899dSKrzysztof Grobelny         metric["MetricProperties"] = std::move(metricProperties);
351479e899dSKrzysztof Grobelny         metric["CollectionDuration"] = time_utils::toDurationString(
352479e899dSKrzysztof Grobelny             std::chrono::milliseconds(collectionDuration));
353b2ba3072SPatrick Williams         metrics.emplace_back(std::move(metric));
354081ebf06SWludzik, Jozef     }
355479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["Metrics"] = std::move(metrics);
356479e899dSKrzysztof Grobelny 
357479e899dSKrzysztof Grobelny     if (enabled)
358479e899dSKrzysztof Grobelny     {
359539d8c6bSEd Tanous         asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
360479e899dSKrzysztof Grobelny     }
361479e899dSKrzysztof Grobelny     else
362479e899dSKrzysztof Grobelny     {
363539d8c6bSEd Tanous         asyncResp->res.jsonValue["Status"]["State"] = resource::State::Disabled;
36489474494SKrzysztof Grobelny     }
36589474494SKrzysztof Grobelny 
366479e899dSKrzysztof Grobelny     metric_report_definition::ReportUpdatesEnum redfishReportUpdates =
367479e899dSKrzysztof Grobelny         toRedfishReportUpdates(reportUpdates);
368479e899dSKrzysztof Grobelny     if (redfishReportUpdates ==
369479e899dSKrzysztof Grobelny         metric_report_definition::ReportUpdatesEnum::Invalid)
37089474494SKrzysztof Grobelny     {
371479e899dSKrzysztof Grobelny         messages::internalError(asyncResp->res);
372479e899dSKrzysztof Grobelny         return;
37389474494SKrzysztof Grobelny     }
374479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["ReportUpdates"] = redfishReportUpdates;
37589474494SKrzysztof Grobelny 
376479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["MetricReportDefinitionEnabled"] = enabled;
377479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["AppendLimit"] = appendLimit;
378479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["Name"] = name;
379081ebf06SWludzik, Jozef     asyncResp->res.jsonValue["Schedule"]["RecurrenceInterval"] =
380479e899dSKrzysztof Grobelny         time_utils::toDurationString(std::chrono::milliseconds(interval));
381479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["@odata.type"] =
382479e899dSKrzysztof Grobelny         "#MetricReportDefinition.v1_3_0.MetricReportDefinition";
383479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
384479e899dSKrzysztof Grobelny         "/redfish/v1/TelemetryService/MetricReportDefinitions/{}", id);
385479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["Id"] = id;
386479e899dSKrzysztof Grobelny     asyncResp->res.jsonValue["MetricReport"]["@odata.id"] = boost::urls::format(
387479e899dSKrzysztof Grobelny         "/redfish/v1/TelemetryService/MetricReports/{}", id);
38889474494SKrzysztof Grobelny }
38989474494SKrzysztof Grobelny 
3904dbb8aeaSWludzik, Jozef struct AddReportArgs
3914dbb8aeaSWludzik, Jozef {
392479e899dSKrzysztof Grobelny     struct MetricArgs
393479e899dSKrzysztof Grobelny     {
394479e899dSKrzysztof Grobelny         std::vector<std::string> uris;
395479e899dSKrzysztof Grobelny         std::string collectionFunction;
396479e899dSKrzysztof Grobelny         std::string collectionTimeScope;
397479e899dSKrzysztof Grobelny         uint64_t collectionDuration = 0;
398479e899dSKrzysztof Grobelny     };
399479e899dSKrzysztof Grobelny 
400479e899dSKrzysztof Grobelny     std::string id;
4014dbb8aeaSWludzik, Jozef     std::string name;
4024dbb8aeaSWludzik, Jozef     std::string reportingType;
403479e899dSKrzysztof Grobelny     std::string reportUpdates;
404479e899dSKrzysztof Grobelny     uint64_t appendLimit = std::numeric_limits<uint64_t>::max();
405479e899dSKrzysztof Grobelny     std::vector<std::string> reportActions;
406479e899dSKrzysztof Grobelny     uint64_t interval = std::numeric_limits<uint64_t>::max();
407479e899dSKrzysztof Grobelny     std::vector<MetricArgs> metrics;
408479e899dSKrzysztof Grobelny     bool metricReportDefinitionEnabled = true;
4094dbb8aeaSWludzik, Jozef };
4104dbb8aeaSWludzik, Jozef 
4114dbb8aeaSWludzik, Jozef inline bool toDbusReportActions(crow::Response& res,
412479e899dSKrzysztof Grobelny                                 const std::vector<std::string>& actions,
4139e6c388aSLukasz Kazmierczak                                 std::vector<std::string>& outReportActions)
4144dbb8aeaSWludzik, Jozef {
4154dbb8aeaSWludzik, Jozef     size_t index = 0;
416479e899dSKrzysztof Grobelny     for (const std::string& action : actions)
4174dbb8aeaSWludzik, Jozef     {
418479e899dSKrzysztof Grobelny         std::string dbusReportAction = toDbusReportAction(action);
419479e899dSKrzysztof Grobelny         if (dbusReportAction.empty())
4204dbb8aeaSWludzik, Jozef         {
4219e6c388aSLukasz Kazmierczak             messages::propertyValueNotInList(
4229e6c388aSLukasz Kazmierczak                 res, action, "ReportActions/" + std::to_string(index));
4234dbb8aeaSWludzik, Jozef             return false;
4244dbb8aeaSWludzik, Jozef         }
425479e899dSKrzysztof Grobelny 
4269e6c388aSLukasz Kazmierczak         outReportActions.emplace_back(std::move(dbusReportAction));
4274dbb8aeaSWludzik, Jozef         index++;
4284dbb8aeaSWludzik, Jozef     }
4294dbb8aeaSWludzik, Jozef     return true;
4304dbb8aeaSWludzik, Jozef }
4314dbb8aeaSWludzik, Jozef 
432b14f357fSEd Tanous inline bool getUserMetric(crow::Response& res, nlohmann::json::object_t& metric,
433479e899dSKrzysztof Grobelny                           AddReportArgs::MetricArgs& metricArgs)
434479e899dSKrzysztof Grobelny {
435479e899dSKrzysztof Grobelny     std::optional<std::vector<std::string>> uris;
436479e899dSKrzysztof Grobelny     std::optional<std::string> collectionDurationStr;
437479e899dSKrzysztof Grobelny     std::optional<std::string> collectionFunction;
438479e899dSKrzysztof Grobelny     std::optional<std::string> collectionTimeScopeStr;
439479e899dSKrzysztof Grobelny 
440b14f357fSEd Tanous     if (!json_util::readJsonObject(
441b14f357fSEd Tanous             metric, res, "MetricProperties", uris, "CollectionFunction",
442b14f357fSEd Tanous             collectionFunction, "CollectionTimeScope", collectionTimeScopeStr,
443479e899dSKrzysztof Grobelny             "CollectionDuration", collectionDurationStr))
444479e899dSKrzysztof Grobelny     {
445479e899dSKrzysztof Grobelny         return false;
446479e899dSKrzysztof Grobelny     }
447479e899dSKrzysztof Grobelny 
448479e899dSKrzysztof Grobelny     if (uris)
449479e899dSKrzysztof Grobelny     {
450479e899dSKrzysztof Grobelny         metricArgs.uris = std::move(*uris);
451479e899dSKrzysztof Grobelny     }
452479e899dSKrzysztof Grobelny 
453479e899dSKrzysztof Grobelny     if (collectionFunction)
454479e899dSKrzysztof Grobelny     {
455479e899dSKrzysztof Grobelny         std::string dbusCollectionFunction =
456479e899dSKrzysztof Grobelny             telemetry::toDbusCollectionFunction(*collectionFunction);
457479e899dSKrzysztof Grobelny         if (dbusCollectionFunction.empty())
458479e899dSKrzysztof Grobelny         {
459479e899dSKrzysztof Grobelny             messages::propertyValueIncorrect(res, "CollectionFunction",
460479e899dSKrzysztof Grobelny                                              *collectionFunction);
461479e899dSKrzysztof Grobelny             return false;
462479e899dSKrzysztof Grobelny         }
463479e899dSKrzysztof Grobelny         metricArgs.collectionFunction = std::move(dbusCollectionFunction);
464479e899dSKrzysztof Grobelny     }
465479e899dSKrzysztof Grobelny 
466479e899dSKrzysztof Grobelny     if (collectionTimeScopeStr)
467479e899dSKrzysztof Grobelny     {
468479e899dSKrzysztof Grobelny         std::string dbusCollectionTimeScope =
469479e899dSKrzysztof Grobelny             toDbusCollectionTimeScope(*collectionTimeScopeStr);
470479e899dSKrzysztof Grobelny         if (dbusCollectionTimeScope.empty())
471479e899dSKrzysztof Grobelny         {
472479e899dSKrzysztof Grobelny             messages::propertyValueIncorrect(res, "CollectionTimeScope",
473479e899dSKrzysztof Grobelny                                              *collectionTimeScopeStr);
474479e899dSKrzysztof Grobelny             return false;
475479e899dSKrzysztof Grobelny         }
476479e899dSKrzysztof Grobelny         metricArgs.collectionTimeScope = std::move(dbusCollectionTimeScope);
477479e899dSKrzysztof Grobelny     }
478479e899dSKrzysztof Grobelny 
479479e899dSKrzysztof Grobelny     if (collectionDurationStr)
480479e899dSKrzysztof Grobelny     {
481479e899dSKrzysztof Grobelny         std::optional<std::chrono::milliseconds> duration =
482479e899dSKrzysztof Grobelny             time_utils::fromDurationString(*collectionDurationStr);
483479e899dSKrzysztof Grobelny 
484479e899dSKrzysztof Grobelny         if (!duration || duration->count() < 0)
485479e899dSKrzysztof Grobelny         {
486479e899dSKrzysztof Grobelny             messages::propertyValueIncorrect(res, "CollectionDuration",
487479e899dSKrzysztof Grobelny                                              *collectionDurationStr);
488479e899dSKrzysztof Grobelny             return false;
489479e899dSKrzysztof Grobelny         }
490479e899dSKrzysztof Grobelny 
491479e899dSKrzysztof Grobelny         metricArgs.collectionDuration =
492479e899dSKrzysztof Grobelny             static_cast<uint64_t>(duration->count());
493479e899dSKrzysztof Grobelny     }
494479e899dSKrzysztof Grobelny 
495479e899dSKrzysztof Grobelny     return true;
496479e899dSKrzysztof Grobelny }
497479e899dSKrzysztof Grobelny 
498479e899dSKrzysztof Grobelny inline bool getUserMetrics(crow::Response& res,
499b14f357fSEd Tanous                            std::span<nlohmann::json::object_t> metrics,
500479e899dSKrzysztof Grobelny                            std::vector<AddReportArgs::MetricArgs>& result)
501479e899dSKrzysztof Grobelny {
502479e899dSKrzysztof Grobelny     result.reserve(metrics.size());
503479e899dSKrzysztof Grobelny 
504b14f357fSEd Tanous     for (nlohmann::json::object_t& m : metrics)
505479e899dSKrzysztof Grobelny     {
506479e899dSKrzysztof Grobelny         AddReportArgs::MetricArgs metricArgs;
507479e899dSKrzysztof Grobelny 
508479e899dSKrzysztof Grobelny         if (!getUserMetric(res, m, metricArgs))
509479e899dSKrzysztof Grobelny         {
510479e899dSKrzysztof Grobelny             return false;
511479e899dSKrzysztof Grobelny         }
512479e899dSKrzysztof Grobelny 
513479e899dSKrzysztof Grobelny         result.emplace_back(std::move(metricArgs));
514479e899dSKrzysztof Grobelny     }
515479e899dSKrzysztof Grobelny 
516479e899dSKrzysztof Grobelny     return true;
517479e899dSKrzysztof Grobelny }
518479e899dSKrzysztof Grobelny 
5194dbb8aeaSWludzik, Jozef inline bool getUserParameters(crow::Response& res, const crow::Request& req,
5204dbb8aeaSWludzik, Jozef                               AddReportArgs& args)
5214dbb8aeaSWludzik, Jozef {
522479e899dSKrzysztof Grobelny     std::optional<std::string> id;
523479e899dSKrzysztof Grobelny     std::optional<std::string> name;
524479e899dSKrzysztof Grobelny     std::optional<std::string> reportingTypeStr;
525479e899dSKrzysztof Grobelny     std::optional<std::string> reportUpdatesStr;
526479e899dSKrzysztof Grobelny     std::optional<uint64_t> appendLimit;
527479e899dSKrzysztof Grobelny     std::optional<bool> metricReportDefinitionEnabled;
528b14f357fSEd Tanous     std::optional<std::vector<nlohmann::json::object_t>> metrics;
529479e899dSKrzysztof Grobelny     std::optional<std::vector<std::string>> reportActionsStr;
530b14f357fSEd Tanous     std::optional<std::string> scheduleDurationStr;
531479e899dSKrzysztof Grobelny 
532479e899dSKrzysztof Grobelny     if (!json_util::readJsonPatch(
533479e899dSKrzysztof Grobelny             req, res, "Id", id, "Name", name, "Metrics", metrics,
534479e899dSKrzysztof Grobelny             "MetricReportDefinitionType", reportingTypeStr, "ReportUpdates",
535479e899dSKrzysztof Grobelny             reportUpdatesStr, "AppendLimit", appendLimit, "ReportActions",
536b14f357fSEd Tanous             reportActionsStr, "Schedule/RecurrenceInterval",
537b14f357fSEd Tanous             scheduleDurationStr, "MetricReportDefinitionEnabled",
538b14f357fSEd Tanous             metricReportDefinitionEnabled))
5394dbb8aeaSWludzik, Jozef     {
5404dbb8aeaSWludzik, Jozef         return false;
5414dbb8aeaSWludzik, Jozef     }
5424dbb8aeaSWludzik, Jozef 
543479e899dSKrzysztof Grobelny     if (id)
544479e899dSKrzysztof Grobelny     {
545479e899dSKrzysztof Grobelny         constexpr const char* allowedCharactersInId =
5464dbb8aeaSWludzik, Jozef             "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
547479e899dSKrzysztof Grobelny         if (id->empty() ||
548479e899dSKrzysztof Grobelny             id->find_first_not_of(allowedCharactersInId) != std::string::npos)
5494dbb8aeaSWludzik, Jozef         {
550479e899dSKrzysztof Grobelny             messages::propertyValueIncorrect(res, "Id", *id);
5514dbb8aeaSWludzik, Jozef             return false;
5524dbb8aeaSWludzik, Jozef         }
553479e899dSKrzysztof Grobelny         args.id = *id;
554479e899dSKrzysztof Grobelny     }
5554dbb8aeaSWludzik, Jozef 
556479e899dSKrzysztof Grobelny     if (name)
5574dbb8aeaSWludzik, Jozef     {
558479e899dSKrzysztof Grobelny         args.name = *name;
559479e899dSKrzysztof Grobelny     }
560479e899dSKrzysztof Grobelny 
561479e899dSKrzysztof Grobelny     if (reportingTypeStr)
562479e899dSKrzysztof Grobelny     {
563479e899dSKrzysztof Grobelny         std::string dbusReportingType = toDbusReportingType(*reportingTypeStr);
564479e899dSKrzysztof Grobelny         if (dbusReportingType.empty())
565479e899dSKrzysztof Grobelny         {
566479e899dSKrzysztof Grobelny             messages::propertyValueNotInList(res, *reportingTypeStr,
5674dbb8aeaSWludzik, Jozef                                              "MetricReportDefinitionType");
5684dbb8aeaSWludzik, Jozef             return false;
5694dbb8aeaSWludzik, Jozef         }
570479e899dSKrzysztof Grobelny         args.reportingType = dbusReportingType;
571479e899dSKrzysztof Grobelny     }
5724dbb8aeaSWludzik, Jozef 
573479e899dSKrzysztof Grobelny     if (reportUpdatesStr)
574479e899dSKrzysztof Grobelny     {
575479e899dSKrzysztof Grobelny         std::string dbusReportUpdates = toDbusReportUpdates(*reportUpdatesStr);
576479e899dSKrzysztof Grobelny         if (dbusReportUpdates.empty())
577479e899dSKrzysztof Grobelny         {
578479e899dSKrzysztof Grobelny             messages::propertyValueNotInList(res, *reportUpdatesStr,
579479e899dSKrzysztof Grobelny                                              "ReportUpdates");
580479e899dSKrzysztof Grobelny             return false;
581479e899dSKrzysztof Grobelny         }
582479e899dSKrzysztof Grobelny         args.reportUpdates = dbusReportUpdates;
583479e899dSKrzysztof Grobelny     }
584479e899dSKrzysztof Grobelny 
585479e899dSKrzysztof Grobelny     if (appendLimit)
586479e899dSKrzysztof Grobelny     {
587479e899dSKrzysztof Grobelny         args.appendLimit = *appendLimit;
588479e899dSKrzysztof Grobelny     }
589479e899dSKrzysztof Grobelny 
590479e899dSKrzysztof Grobelny     if (metricReportDefinitionEnabled)
591479e899dSKrzysztof Grobelny     {
592479e899dSKrzysztof Grobelny         args.metricReportDefinitionEnabled = *metricReportDefinitionEnabled;
593479e899dSKrzysztof Grobelny     }
594479e899dSKrzysztof Grobelny 
595479e899dSKrzysztof Grobelny     if (reportActionsStr)
596479e899dSKrzysztof Grobelny     {
5979e6c388aSLukasz Kazmierczak         if (!toDbusReportActions(res, *reportActionsStr, args.reportActions))
5984dbb8aeaSWludzik, Jozef         {
5994dbb8aeaSWludzik, Jozef             return false;
6004dbb8aeaSWludzik, Jozef         }
601479e899dSKrzysztof Grobelny     }
6024dbb8aeaSWludzik, Jozef 
603479e899dSKrzysztof Grobelny     if (reportingTypeStr == "Periodic")
6044dbb8aeaSWludzik, Jozef     {
605b14f357fSEd Tanous         if (!scheduleDurationStr)
6064dbb8aeaSWludzik, Jozef         {
6074dbb8aeaSWludzik, Jozef             messages::createFailedMissingReqProperties(res, "Schedule");
6084dbb8aeaSWludzik, Jozef             return false;
6094dbb8aeaSWludzik, Jozef         }
6104dbb8aeaSWludzik, Jozef 
6114dbb8aeaSWludzik, Jozef         std::optional<std::chrono::milliseconds> durationNum =
612b14f357fSEd Tanous             time_utils::fromDurationString(*scheduleDurationStr);
613479e899dSKrzysztof Grobelny         if (!durationNum || durationNum->count() < 0)
6144dbb8aeaSWludzik, Jozef         {
6154dbb8aeaSWludzik, Jozef             messages::propertyValueIncorrect(res, "RecurrenceInterval",
616b14f357fSEd Tanous                                              *scheduleDurationStr);
6174dbb8aeaSWludzik, Jozef             return false;
6184dbb8aeaSWludzik, Jozef         }
6194dbb8aeaSWludzik, Jozef         args.interval = static_cast<uint64_t>(durationNum->count());
6204dbb8aeaSWludzik, Jozef     }
6214dbb8aeaSWludzik, Jozef 
622479e899dSKrzysztof Grobelny     if (metrics)
6234dbb8aeaSWludzik, Jozef     {
624479e899dSKrzysztof Grobelny         if (!getUserMetrics(res, *metrics, args.metrics))
6254dbb8aeaSWludzik, Jozef         {
6264dbb8aeaSWludzik, Jozef             return false;
6274dbb8aeaSWludzik, Jozef         }
6284dbb8aeaSWludzik, Jozef     }
6294dbb8aeaSWludzik, Jozef 
6304dbb8aeaSWludzik, Jozef     return true;
6314dbb8aeaSWludzik, Jozef }
6324dbb8aeaSWludzik, Jozef 
633ca1600c1SSzymon Dompke inline bool getChassisSensorNodeFromMetrics(
6348d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
635479e899dSKrzysztof Grobelny     std::span<const AddReportArgs::MetricArgs> metrics,
6364dbb8aeaSWludzik, Jozef     boost::container::flat_set<std::pair<std::string, std::string>>& matched)
6374dbb8aeaSWludzik, Jozef {
638ca1600c1SSzymon Dompke     for (const auto& metric : metrics)
6394dbb8aeaSWludzik, Jozef     {
640479e899dSKrzysztof Grobelny         std::optional<IncorrectMetricUri> error =
641479e899dSKrzysztof Grobelny             getChassisSensorNode(metric.uris, matched);
642ca1600c1SSzymon Dompke         if (error)
6434dbb8aeaSWludzik, Jozef         {
644bd79bce8SPatrick Williams             messages::propertyValueIncorrect(
645bd79bce8SPatrick Williams                 asyncResp->res, error->uri,
646bd79bce8SPatrick Williams                 "MetricProperties/" + std::to_string(error->index));
6474dbb8aeaSWludzik, Jozef             return false;
6484dbb8aeaSWludzik, Jozef         }
6494dbb8aeaSWludzik, Jozef     }
6504dbb8aeaSWludzik, Jozef     return true;
6514dbb8aeaSWludzik, Jozef }
6524dbb8aeaSWludzik, Jozef 
6534dbb8aeaSWludzik, Jozef class AddReport
6544dbb8aeaSWludzik, Jozef {
6554dbb8aeaSWludzik, Jozef   public:
656891eaa7cSEd Tanous     AddReport(AddReportArgs&& argsIn,
6578a592810SEd Tanous               const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) :
658bd79bce8SPatrick Williams         asyncResp(asyncRespIn), args(std::move(argsIn))
6594dbb8aeaSWludzik, Jozef     {}
660479e899dSKrzysztof Grobelny 
6614dbb8aeaSWludzik, Jozef     ~AddReport()
6624dbb8aeaSWludzik, Jozef     {
663479e899dSKrzysztof Grobelny         boost::asio::post(crow::connections::systemBus->get_io_context(),
664479e899dSKrzysztof Grobelny                           std::bind_front(&performAddReport, asyncResp, args,
665479e899dSKrzysztof Grobelny                                           std::move(uriToDbus)));
666479e899dSKrzysztof Grobelny     }
667479e899dSKrzysztof Grobelny 
668479e899dSKrzysztof Grobelny     static void performAddReport(
669479e899dSKrzysztof Grobelny         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
670479e899dSKrzysztof Grobelny         const AddReportArgs& args,
671479e899dSKrzysztof Grobelny         const boost::container::flat_map<std::string, std::string>& uriToDbus)
672479e899dSKrzysztof Grobelny     {
6734dbb8aeaSWludzik, Jozef         if (asyncResp->res.result() != boost::beast::http::status::ok)
6744dbb8aeaSWludzik, Jozef         {
6754dbb8aeaSWludzik, Jozef             return;
6764dbb8aeaSWludzik, Jozef         }
6774dbb8aeaSWludzik, Jozef 
6784dbb8aeaSWludzik, Jozef         telemetry::ReadingParameters readingParams;
6794dbb8aeaSWludzik, Jozef         readingParams.reserve(args.metrics.size());
6804dbb8aeaSWludzik, Jozef 
681479e899dSKrzysztof Grobelny         for (const auto& metric : args.metrics)
6824dbb8aeaSWludzik, Jozef         {
683479e899dSKrzysztof Grobelny             std::vector<
684479e899dSKrzysztof Grobelny                 std::tuple<sdbusplus::message::object_path, std::string>>
685479e899dSKrzysztof Grobelny                 sensorParams;
686479e899dSKrzysztof Grobelny             sensorParams.reserve(metric.uris.size());
687479e899dSKrzysztof Grobelny 
688479e899dSKrzysztof Grobelny             for (size_t i = 0; i < metric.uris.size(); i++)
6894dbb8aeaSWludzik, Jozef             {
690479e899dSKrzysztof Grobelny                 const std::string& uri = metric.uris[i];
6914dbb8aeaSWludzik, Jozef                 auto el = uriToDbus.find(uri);
6924dbb8aeaSWludzik, Jozef                 if (el == uriToDbus.end())
6934dbb8aeaSWludzik, Jozef                 {
69462598e31SEd Tanous                     BMCWEB_LOG_ERROR(
69562598e31SEd Tanous                         "Failed to find DBus sensor corresponding to URI {}",
69662598e31SEd Tanous                         uri);
697bd79bce8SPatrick Williams                     messages::propertyValueNotInList(
698bd79bce8SPatrick Williams                         asyncResp->res, uri,
699bd79bce8SPatrick Williams                         "MetricProperties/" + std::to_string(i));
7004dbb8aeaSWludzik, Jozef                     return;
7014dbb8aeaSWludzik, Jozef                 }
7024dbb8aeaSWludzik, Jozef 
7034dbb8aeaSWludzik, Jozef                 const std::string& dbusPath = el->second;
704479e899dSKrzysztof Grobelny                 sensorParams.emplace_back(dbusPath, uri);
7054dbb8aeaSWludzik, Jozef             }
706479e899dSKrzysztof Grobelny 
707479e899dSKrzysztof Grobelny             readingParams.emplace_back(
708479e899dSKrzysztof Grobelny                 std::move(sensorParams), metric.collectionFunction,
709479e899dSKrzysztof Grobelny                 metric.collectionTimeScope, metric.collectionDuration);
7104dbb8aeaSWludzik, Jozef         }
711479e899dSKrzysztof Grobelny 
7124dbb8aeaSWludzik, Jozef         crow::connections::systemBus->async_method_call(
713479e899dSKrzysztof Grobelny             [asyncResp, id = args.id, uriToDbus](
7145e7e2dc5SEd Tanous                 const boost::system::error_code& ec, const std::string&) {
7154dbb8aeaSWludzik, Jozef                 if (ec == boost::system::errc::file_exists)
7164dbb8aeaSWludzik, Jozef                 {
7174dbb8aeaSWludzik, Jozef                     messages::resourceAlreadyExists(
718479e899dSKrzysztof Grobelny                         asyncResp->res, "MetricReportDefinition", "Id", id);
7194dbb8aeaSWludzik, Jozef                     return;
7204dbb8aeaSWludzik, Jozef                 }
7214dbb8aeaSWludzik, Jozef                 if (ec == boost::system::errc::too_many_files_open)
7224dbb8aeaSWludzik, Jozef                 {
723479e899dSKrzysztof Grobelny                     messages::createLimitReachedForResource(asyncResp->res);
7244dbb8aeaSWludzik, Jozef                     return;
7254dbb8aeaSWludzik, Jozef                 }
7264dbb8aeaSWludzik, Jozef                 if (ec == boost::system::errc::argument_list_too_long)
7274dbb8aeaSWludzik, Jozef                 {
7284dbb8aeaSWludzik, Jozef                     nlohmann::json metricProperties = nlohmann::json::array();
7294dbb8aeaSWludzik, Jozef                     for (const auto& [uri, _] : uriToDbus)
7304dbb8aeaSWludzik, Jozef                     {
7314dbb8aeaSWludzik, Jozef                         metricProperties.emplace_back(uri);
7324dbb8aeaSWludzik, Jozef                     }
73314fbced6SEd Tanous                     messages::propertyValueIncorrect(
734367b3dceSGinu George                         asyncResp->res, "MetricProperties", metricProperties);
7354dbb8aeaSWludzik, Jozef                     return;
7364dbb8aeaSWludzik, Jozef                 }
7374dbb8aeaSWludzik, Jozef                 if (ec)
7384dbb8aeaSWludzik, Jozef                 {
739479e899dSKrzysztof Grobelny                     messages::internalError(asyncResp->res);
74062598e31SEd Tanous                     BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
7414dbb8aeaSWludzik, Jozef                     return;
7424dbb8aeaSWludzik, Jozef                 }
7434dbb8aeaSWludzik, Jozef 
744479e899dSKrzysztof Grobelny                 messages::created(asyncResp->res);
7454dbb8aeaSWludzik, Jozef             },
7464dbb8aeaSWludzik, Jozef             telemetry::service, "/xyz/openbmc_project/Telemetry/Reports",
7474dbb8aeaSWludzik, Jozef             "xyz.openbmc_project.Telemetry.ReportManager", "AddReport",
748479e899dSKrzysztof Grobelny             "TelemetryService/" + args.id, args.name, args.reportingType,
749479e899dSKrzysztof Grobelny             args.reportUpdates, args.appendLimit, args.reportActions,
750479e899dSKrzysztof Grobelny             args.interval, readingParams, args.metricReportDefinitionEnabled);
7514dbb8aeaSWludzik, Jozef     }
7524dbb8aeaSWludzik, Jozef 
753ecd6a3a2SEd Tanous     AddReport(const AddReport&) = delete;
754ecd6a3a2SEd Tanous     AddReport(AddReport&&) = delete;
755ecd6a3a2SEd Tanous     AddReport& operator=(const AddReport&) = delete;
756ecd6a3a2SEd Tanous     AddReport& operator=(AddReport&&) = delete;
757ecd6a3a2SEd Tanous 
758fe04d49cSNan Zhou     void insert(const std::map<std::string, std::string>& el)
7594dbb8aeaSWludzik, Jozef     {
7604dbb8aeaSWludzik, Jozef         uriToDbus.insert(el.begin(), el.end());
7614dbb8aeaSWludzik, Jozef     }
7624dbb8aeaSWludzik, Jozef 
7634dbb8aeaSWludzik, Jozef   private:
764479e899dSKrzysztof Grobelny     std::shared_ptr<bmcweb::AsyncResp> asyncResp;
7654dbb8aeaSWludzik, Jozef     AddReportArgs args;
76647f2934cSEd Tanous     boost::container::flat_map<std::string, std::string> uriToDbus;
7674dbb8aeaSWludzik, Jozef };
7689e6c388aSLukasz Kazmierczak 
7699e6c388aSLukasz Kazmierczak class UpdateMetrics
7709e6c388aSLukasz Kazmierczak {
7719e6c388aSLukasz Kazmierczak   public:
7729e6c388aSLukasz Kazmierczak     UpdateMetrics(std::string_view idIn,
7739e6c388aSLukasz Kazmierczak                   const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) :
774bd79bce8SPatrick Williams         id(idIn), asyncResp(asyncRespIn)
7759e6c388aSLukasz Kazmierczak     {}
7769e6c388aSLukasz Kazmierczak 
7779e6c388aSLukasz Kazmierczak     ~UpdateMetrics()
7789e6c388aSLukasz Kazmierczak     {
7799e6c388aSLukasz Kazmierczak         try
7809e6c388aSLukasz Kazmierczak         {
7819e6c388aSLukasz Kazmierczak             setReadingParams();
7829e6c388aSLukasz Kazmierczak         }
7839e6c388aSLukasz Kazmierczak         catch (const std::exception& e)
7849e6c388aSLukasz Kazmierczak         {
7859e6c388aSLukasz Kazmierczak             BMCWEB_LOG_ERROR("{}", e.what());
7869e6c388aSLukasz Kazmierczak         }
7879e6c388aSLukasz Kazmierczak         catch (...)
7889e6c388aSLukasz Kazmierczak         {
7899e6c388aSLukasz Kazmierczak             BMCWEB_LOG_ERROR("Unknown error");
7909e6c388aSLukasz Kazmierczak         }
7919e6c388aSLukasz Kazmierczak     }
7929e6c388aSLukasz Kazmierczak 
7939e6c388aSLukasz Kazmierczak     UpdateMetrics(const UpdateMetrics&) = delete;
7949e6c388aSLukasz Kazmierczak     UpdateMetrics(UpdateMetrics&&) = delete;
7959e6c388aSLukasz Kazmierczak     UpdateMetrics& operator=(const UpdateMetrics&) = delete;
7969e6c388aSLukasz Kazmierczak     UpdateMetrics& operator=(UpdateMetrics&&) = delete;
7979e6c388aSLukasz Kazmierczak 
7989e6c388aSLukasz Kazmierczak     std::string id;
7999e6c388aSLukasz Kazmierczak     std::map<std::string, std::string> metricPropertyToDbusPaths;
8009e6c388aSLukasz Kazmierczak 
8019e6c388aSLukasz Kazmierczak     void insert(const std::map<std::string, std::string>&
8029e6c388aSLukasz Kazmierczak                     additionalMetricPropertyToDbusPaths)
8039e6c388aSLukasz Kazmierczak     {
8049e6c388aSLukasz Kazmierczak         metricPropertyToDbusPaths.insert(
8059e6c388aSLukasz Kazmierczak             additionalMetricPropertyToDbusPaths.begin(),
8069e6c388aSLukasz Kazmierczak             additionalMetricPropertyToDbusPaths.end());
8079e6c388aSLukasz Kazmierczak     }
8089e6c388aSLukasz Kazmierczak 
809bd79bce8SPatrick Williams     void emplace(
810bd79bce8SPatrick Williams         std::span<
811bd79bce8SPatrick Williams             const std::tuple<sdbusplus::message::object_path, std::string>>
8129e6c388aSLukasz Kazmierczak             pathAndUri,
8139e6c388aSLukasz Kazmierczak         const AddReportArgs::MetricArgs& metricArgs)
8149e6c388aSLukasz Kazmierczak     {
8159e6c388aSLukasz Kazmierczak         readingParamsUris.emplace_back(metricArgs.uris);
8169e6c388aSLukasz Kazmierczak         readingParams.emplace_back(
8179e6c388aSLukasz Kazmierczak             std::vector(pathAndUri.begin(), pathAndUri.end()),
8189e6c388aSLukasz Kazmierczak             metricArgs.collectionFunction, metricArgs.collectionTimeScope,
8199e6c388aSLukasz Kazmierczak             metricArgs.collectionDuration);
8209e6c388aSLukasz Kazmierczak     }
8219e6c388aSLukasz Kazmierczak 
8229e6c388aSLukasz Kazmierczak     void setReadingParams()
8239e6c388aSLukasz Kazmierczak     {
8249e6c388aSLukasz Kazmierczak         if (asyncResp->res.result() != boost::beast::http::status::ok)
8259e6c388aSLukasz Kazmierczak         {
8269e6c388aSLukasz Kazmierczak             return;
8279e6c388aSLukasz Kazmierczak         }
8289e6c388aSLukasz Kazmierczak 
8299e6c388aSLukasz Kazmierczak         for (size_t index = 0; index < readingParamsUris.size(); ++index)
8309e6c388aSLukasz Kazmierczak         {
8319e6c388aSLukasz Kazmierczak             std::span<const std::string> newUris = readingParamsUris[index];
8329e6c388aSLukasz Kazmierczak 
8339e6c388aSLukasz Kazmierczak             const std::optional<std::vector<
8349e6c388aSLukasz Kazmierczak                 std::tuple<sdbusplus::message::object_path, std::string>>>
8359e6c388aSLukasz Kazmierczak                 readingParam = sensorPathToUri(newUris);
8369e6c388aSLukasz Kazmierczak 
8379e6c388aSLukasz Kazmierczak             if (!readingParam)
8389e6c388aSLukasz Kazmierczak             {
8399e6c388aSLukasz Kazmierczak                 return;
8409e6c388aSLukasz Kazmierczak             }
8419e6c388aSLukasz Kazmierczak 
8429e6c388aSLukasz Kazmierczak             std::get<0>(readingParams[index]) = *readingParam;
8439e6c388aSLukasz Kazmierczak         }
8449e6c388aSLukasz Kazmierczak 
8459e6c388aSLukasz Kazmierczak         crow::connections::systemBus->async_method_call(
8469e6c388aSLukasz Kazmierczak             [asyncResp(this->asyncResp),
8479e6c388aSLukasz Kazmierczak              reportId = id](const boost::system::error_code& ec) {
8489e6c388aSLukasz Kazmierczak                 if (!verifyCommonErrors(asyncResp->res, reportId, ec))
8499e6c388aSLukasz Kazmierczak                 {
8509e6c388aSLukasz Kazmierczak                     return;
8519e6c388aSLukasz Kazmierczak                 }
8529e6c388aSLukasz Kazmierczak             },
8539e6c388aSLukasz Kazmierczak             "xyz.openbmc_project.Telemetry", getDbusReportPath(id),
8549e6c388aSLukasz Kazmierczak             "org.freedesktop.DBus.Properties", "Set",
8559e6c388aSLukasz Kazmierczak             "xyz.openbmc_project.Telemetry.Report", "ReadingParameters",
8569e6c388aSLukasz Kazmierczak             dbus::utility::DbusVariantType{readingParams});
8579e6c388aSLukasz Kazmierczak     }
8589e6c388aSLukasz Kazmierczak 
8599e6c388aSLukasz Kazmierczak   private:
8609e6c388aSLukasz Kazmierczak     std::optional<
8619e6c388aSLukasz Kazmierczak         std::vector<std::tuple<sdbusplus::message::object_path, std::string>>>
8629e6c388aSLukasz Kazmierczak         sensorPathToUri(std::span<const std::string> uris) const
8639e6c388aSLukasz Kazmierczak     {
8649e6c388aSLukasz Kazmierczak         std::vector<std::tuple<sdbusplus::message::object_path, std::string>>
8659e6c388aSLukasz Kazmierczak             result;
8669e6c388aSLukasz Kazmierczak 
8679e6c388aSLukasz Kazmierczak         for (const std::string& uri : uris)
8689e6c388aSLukasz Kazmierczak         {
8699e6c388aSLukasz Kazmierczak             auto it = metricPropertyToDbusPaths.find(uri);
8709e6c388aSLukasz Kazmierczak             if (it == metricPropertyToDbusPaths.end())
8719e6c388aSLukasz Kazmierczak             {
8729e6c388aSLukasz Kazmierczak                 messages::propertyValueNotInList(asyncResp->res, uri,
8739e6c388aSLukasz Kazmierczak                                                  "MetricProperties");
8749e6c388aSLukasz Kazmierczak                 return {};
8759e6c388aSLukasz Kazmierczak             }
8769e6c388aSLukasz Kazmierczak             result.emplace_back(it->second, uri);
8779e6c388aSLukasz Kazmierczak         }
8789e6c388aSLukasz Kazmierczak 
8799e6c388aSLukasz Kazmierczak         return result;
8809e6c388aSLukasz Kazmierczak     }
8819e6c388aSLukasz Kazmierczak 
8829e6c388aSLukasz Kazmierczak     const std::shared_ptr<bmcweb::AsyncResp> asyncResp;
8839e6c388aSLukasz Kazmierczak     std::vector<std::vector<std::string>> readingParamsUris;
88447f2934cSEd Tanous     ReadingParameters readingParams;
8859e6c388aSLukasz Kazmierczak };
8869e6c388aSLukasz Kazmierczak 
8879e6c388aSLukasz Kazmierczak inline void
8889e6c388aSLukasz Kazmierczak     setReportEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
8899e6c388aSLukasz Kazmierczak                      std::string_view id, bool enabled)
8909e6c388aSLukasz Kazmierczak {
8919e6c388aSLukasz Kazmierczak     crow::connections::systemBus->async_method_call(
8929e6c388aSLukasz Kazmierczak         [asyncResp, id = std::string(id)](const boost::system::error_code& ec) {
8939e6c388aSLukasz Kazmierczak             if (!verifyCommonErrors(asyncResp->res, id, ec))
8949e6c388aSLukasz Kazmierczak             {
8959e6c388aSLukasz Kazmierczak                 return;
8969e6c388aSLukasz Kazmierczak             }
8979e6c388aSLukasz Kazmierczak         },
8989e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry", getDbusReportPath(id),
8999e6c388aSLukasz Kazmierczak         "org.freedesktop.DBus.Properties", "Set",
9009e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry.Report", "Enabled",
9019e6c388aSLukasz Kazmierczak         dbus::utility::DbusVariantType{enabled});
9029e6c388aSLukasz Kazmierczak }
9039e6c388aSLukasz Kazmierczak 
9049e6c388aSLukasz Kazmierczak inline void setReportTypeAndInterval(
9059e6c388aSLukasz Kazmierczak     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string_view id,
906*b4361d63SEd Tanous     const std::optional<std::string>& reportingType,
907*b4361d63SEd Tanous     const std::optional<std::string>& recurrenceIntervalStr)
9089e6c388aSLukasz Kazmierczak {
909*b4361d63SEd Tanous     std::string dbusReportingType;
910*b4361d63SEd Tanous     if (reportingType)
911*b4361d63SEd Tanous     {
912*b4361d63SEd Tanous         dbusReportingType = toDbusReportingType(*reportingType);
913*b4361d63SEd Tanous         if (dbusReportingType.empty())
914*b4361d63SEd Tanous         {
915*b4361d63SEd Tanous             messages::propertyValueNotInList(asyncResp->res, *reportingType,
916*b4361d63SEd Tanous                                              "MetricReportDefinitionType");
917*b4361d63SEd Tanous             return;
918*b4361d63SEd Tanous         }
919*b4361d63SEd Tanous     }
920*b4361d63SEd Tanous 
921*b4361d63SEd Tanous     uint64_t recurrenceInterval = std::numeric_limits<uint64_t>::max();
922*b4361d63SEd Tanous     if (recurrenceIntervalStr)
923*b4361d63SEd Tanous     {
924*b4361d63SEd Tanous         std::optional<std::chrono::milliseconds> durationNum =
925*b4361d63SEd Tanous             time_utils::fromDurationString(*recurrenceIntervalStr);
926*b4361d63SEd Tanous         if (!durationNum || durationNum->count() < 0)
927*b4361d63SEd Tanous         {
928*b4361d63SEd Tanous             messages::propertyValueIncorrect(
929*b4361d63SEd Tanous                 asyncResp->res, "RecurrenceInterval", *recurrenceIntervalStr);
930*b4361d63SEd Tanous             return;
931*b4361d63SEd Tanous         }
932*b4361d63SEd Tanous 
933*b4361d63SEd Tanous         recurrenceInterval = static_cast<uint64_t>(durationNum->count());
934*b4361d63SEd Tanous     }
935*b4361d63SEd Tanous 
9369e6c388aSLukasz Kazmierczak     crow::connections::systemBus->async_method_call(
9379e6c388aSLukasz Kazmierczak         [asyncResp, id = std::string(id)](const boost::system::error_code& ec) {
9389e6c388aSLukasz Kazmierczak             if (!verifyCommonErrors(asyncResp->res, id, ec))
9399e6c388aSLukasz Kazmierczak             {
9409e6c388aSLukasz Kazmierczak                 return;
9419e6c388aSLukasz Kazmierczak             }
9429e6c388aSLukasz Kazmierczak         },
9439e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry", getDbusReportPath(id),
9449e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry.Report", "SetReportingProperties",
945*b4361d63SEd Tanous         dbusReportingType, recurrenceInterval);
9469e6c388aSLukasz Kazmierczak }
9479e6c388aSLukasz Kazmierczak 
9489e6c388aSLukasz Kazmierczak inline void
9499e6c388aSLukasz Kazmierczak     setReportUpdates(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
9509e6c388aSLukasz Kazmierczak                      std::string_view id, const std::string& reportUpdates)
9519e6c388aSLukasz Kazmierczak {
952*b4361d63SEd Tanous     std::string dbusReportUpdates = toDbusReportUpdates(reportUpdates);
953*b4361d63SEd Tanous     if (dbusReportUpdates.empty())
954*b4361d63SEd Tanous     {
955*b4361d63SEd Tanous         messages::propertyValueNotInList(asyncResp->res, reportUpdates,
956*b4361d63SEd Tanous                                          "ReportUpdates");
957*b4361d63SEd Tanous         return;
958*b4361d63SEd Tanous     }
9599e6c388aSLukasz Kazmierczak     crow::connections::systemBus->async_method_call(
9609e6c388aSLukasz Kazmierczak         [asyncResp, id = std::string(id)](const boost::system::error_code& ec) {
9619e6c388aSLukasz Kazmierczak             if (!verifyCommonErrors(asyncResp->res, id, ec))
9629e6c388aSLukasz Kazmierczak             {
9639e6c388aSLukasz Kazmierczak                 return;
9649e6c388aSLukasz Kazmierczak             }
9659e6c388aSLukasz Kazmierczak         },
9669e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry", getDbusReportPath(id),
9679e6c388aSLukasz Kazmierczak         "org.freedesktop.DBus.Properties", "Set",
9689e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry.Report", "ReportUpdates",
9699e6c388aSLukasz Kazmierczak         dbus::utility::DbusVariantType{reportUpdates});
9709e6c388aSLukasz Kazmierczak }
9719e6c388aSLukasz Kazmierczak 
972bd79bce8SPatrick Williams inline void setReportActions(
973bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string_view id,
974*b4361d63SEd Tanous     const std::vector<std::string>& reportActions)
9759e6c388aSLukasz Kazmierczak {
976*b4361d63SEd Tanous     std::vector<std::string> dbusReportActions;
977*b4361d63SEd Tanous     if (!toDbusReportActions(asyncResp->res, reportActions, dbusReportActions))
978*b4361d63SEd Tanous     {
979*b4361d63SEd Tanous         return;
980*b4361d63SEd Tanous     }
981*b4361d63SEd Tanous 
9829e6c388aSLukasz Kazmierczak     crow::connections::systemBus->async_method_call(
9839e6c388aSLukasz Kazmierczak         [asyncResp, id = std::string(id)](const boost::system::error_code& ec) {
9849e6c388aSLukasz Kazmierczak             if (!verifyCommonErrors(asyncResp->res, id, ec))
9859e6c388aSLukasz Kazmierczak             {
9869e6c388aSLukasz Kazmierczak                 return;
9879e6c388aSLukasz Kazmierczak             }
9889e6c388aSLukasz Kazmierczak         },
9899e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry", getDbusReportPath(id),
9909e6c388aSLukasz Kazmierczak         "org.freedesktop.DBus.Properties", "Set",
9919e6c388aSLukasz Kazmierczak         "xyz.openbmc_project.Telemetry.Report", "ReportActions",
9929e6c388aSLukasz Kazmierczak         dbus::utility::DbusVariantType{dbusReportActions});
9939e6c388aSLukasz Kazmierczak }
9949e6c388aSLukasz Kazmierczak 
995bd79bce8SPatrick Williams inline void setReportMetrics(
996bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string_view id,
997b14f357fSEd Tanous     std::span<nlohmann::json::object_t> metrics)
9989e6c388aSLukasz Kazmierczak {
9999e6c388aSLukasz Kazmierczak     sdbusplus::asio::getAllProperties(
10009e6c388aSLukasz Kazmierczak         *crow::connections::systemBus, telemetry::service,
10019e6c388aSLukasz Kazmierczak         telemetry::getDbusReportPath(id), telemetry::reportInterface,
10029e6c388aSLukasz Kazmierczak         [asyncResp, id = std::string(id),
1003bd79bce8SPatrick Williams          redfishMetrics = std::vector<nlohmann::json::object_t>(
1004bd79bce8SPatrick Williams              metrics.begin(), metrics.end())](
10059e6c388aSLukasz Kazmierczak             boost::system::error_code ec,
10069e6c388aSLukasz Kazmierczak             const dbus::utility::DBusPropertiesMap& properties) mutable {
10079e6c388aSLukasz Kazmierczak             if (!redfish::telemetry::verifyCommonErrors(asyncResp->res, id, ec))
10089e6c388aSLukasz Kazmierczak             {
10099e6c388aSLukasz Kazmierczak                 return;
10109e6c388aSLukasz Kazmierczak             }
10119e6c388aSLukasz Kazmierczak 
10129e6c388aSLukasz Kazmierczak             ReadingParameters readingParams;
10139e6c388aSLukasz Kazmierczak 
10149e6c388aSLukasz Kazmierczak             const bool success = sdbusplus::unpackPropertiesNoThrow(
1015bd79bce8SPatrick Williams                 dbus_utils::UnpackErrorPrinter(), properties,
1016bd79bce8SPatrick Williams                 "ReadingParameters", readingParams);
10179e6c388aSLukasz Kazmierczak 
10189e6c388aSLukasz Kazmierczak             if (!success)
10199e6c388aSLukasz Kazmierczak             {
10209e6c388aSLukasz Kazmierczak                 messages::internalError(asyncResp->res);
10219e6c388aSLukasz Kazmierczak                 return;
10229e6c388aSLukasz Kazmierczak             }
10239e6c388aSLukasz Kazmierczak 
1024bd79bce8SPatrick Williams             auto updateMetricsReq =
1025bd79bce8SPatrick Williams                 std::make_shared<UpdateMetrics>(id, asyncResp);
10269e6c388aSLukasz Kazmierczak 
10279e6c388aSLukasz Kazmierczak             boost::container::flat_set<std::pair<std::string, std::string>>
10289e6c388aSLukasz Kazmierczak                 chassisSensors;
10299e6c388aSLukasz Kazmierczak 
10309e6c388aSLukasz Kazmierczak             size_t index = 0;
1031b14f357fSEd Tanous             for (nlohmann::json::object_t& metric : redfishMetrics)
10329e6c388aSLukasz Kazmierczak             {
10339e6c388aSLukasz Kazmierczak                 AddReportArgs::MetricArgs metricArgs;
10349e6c388aSLukasz Kazmierczak                 std::vector<
10359e6c388aSLukasz Kazmierczak                     std::tuple<sdbusplus::message::object_path, std::string>>
10369e6c388aSLukasz Kazmierczak                     pathAndUri;
10379e6c388aSLukasz Kazmierczak 
10389e6c388aSLukasz Kazmierczak                 if (index < readingParams.size())
10399e6c388aSLukasz Kazmierczak                 {
10409e6c388aSLukasz Kazmierczak                     const ReadingParameters::value_type& existing =
10419e6c388aSLukasz Kazmierczak                         readingParams[index];
10429e6c388aSLukasz Kazmierczak 
10439e6c388aSLukasz Kazmierczak                     pathAndUri = std::get<0>(existing);
10449e6c388aSLukasz Kazmierczak                     metricArgs.collectionFunction = std::get<1>(existing);
10459e6c388aSLukasz Kazmierczak                     metricArgs.collectionTimeScope = std::get<2>(existing);
10469e6c388aSLukasz Kazmierczak                     metricArgs.collectionDuration = std::get<3>(existing);
10479e6c388aSLukasz Kazmierczak                 }
10489e6c388aSLukasz Kazmierczak 
10499e6c388aSLukasz Kazmierczak                 if (!getUserMetric(asyncResp->res, metric, metricArgs))
10509e6c388aSLukasz Kazmierczak                 {
10519e6c388aSLukasz Kazmierczak                     return;
10529e6c388aSLukasz Kazmierczak                 }
10539e6c388aSLukasz Kazmierczak 
10549e6c388aSLukasz Kazmierczak                 std::optional<IncorrectMetricUri> error =
10559e6c388aSLukasz Kazmierczak                     getChassisSensorNode(metricArgs.uris, chassisSensors);
10569e6c388aSLukasz Kazmierczak 
10579e6c388aSLukasz Kazmierczak                 if (error)
10589e6c388aSLukasz Kazmierczak                 {
10599e6c388aSLukasz Kazmierczak                     messages::propertyValueIncorrect(
10609e6c388aSLukasz Kazmierczak                         asyncResp->res, error->uri,
10619e6c388aSLukasz Kazmierczak                         "MetricProperties/" + std::to_string(error->index));
10629e6c388aSLukasz Kazmierczak                     return;
10639e6c388aSLukasz Kazmierczak                 }
10649e6c388aSLukasz Kazmierczak 
10659e6c388aSLukasz Kazmierczak                 updateMetricsReq->emplace(pathAndUri, metricArgs);
10669e6c388aSLukasz Kazmierczak                 index++;
10679e6c388aSLukasz Kazmierczak             }
10689e6c388aSLukasz Kazmierczak 
10699e6c388aSLukasz Kazmierczak             for (const auto& [chassis, sensorType] : chassisSensors)
10709e6c388aSLukasz Kazmierczak             {
10719e6c388aSLukasz Kazmierczak                 retrieveUriToDbusMap(
10729e6c388aSLukasz Kazmierczak                     chassis, sensorType,
10739e6c388aSLukasz Kazmierczak                     [asyncResp, updateMetricsReq](
10749e6c388aSLukasz Kazmierczak                         const boost::beast::http::status status,
10759e6c388aSLukasz Kazmierczak                         const std::map<std::string, std::string>& uriToDbus) {
10769e6c388aSLukasz Kazmierczak                         if (status != boost::beast::http::status::ok)
10779e6c388aSLukasz Kazmierczak                         {
10789e6c388aSLukasz Kazmierczak                             BMCWEB_LOG_ERROR(
10799e6c388aSLukasz Kazmierczak                                 "Failed to retrieve URI to dbus sensors map with err {}",
10809e6c388aSLukasz Kazmierczak                                 static_cast<unsigned>(status));
10819e6c388aSLukasz Kazmierczak                             return;
10829e6c388aSLukasz Kazmierczak                         }
10839e6c388aSLukasz Kazmierczak                         updateMetricsReq->insert(uriToDbus);
10849e6c388aSLukasz Kazmierczak                     });
10859e6c388aSLukasz Kazmierczak             }
10869e6c388aSLukasz Kazmierczak         });
10879e6c388aSLukasz Kazmierczak }
1088081ebf06SWludzik, Jozef 
10894220be3bSEd Tanous inline void handleMetricReportDefinitionCollectionHead(
10904220be3bSEd Tanous     App& app, const crow::Request& req,
10914220be3bSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
10924220be3bSEd Tanous {
10934220be3bSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
10944220be3bSEd Tanous     {
10954220be3bSEd Tanous         return;
10964220be3bSEd Tanous     }
10974220be3bSEd Tanous     asyncResp->res.addHeader(
10984220be3bSEd Tanous         boost::beast::http::field::link,
10994220be3bSEd Tanous         "</redfish/v1/JsonSchemas/MetricReportDefinitionCollection/MetricReportDefinitionCollection.json>; rel=describedby");
11004220be3bSEd Tanous }
11014220be3bSEd Tanous 
11024220be3bSEd Tanous inline void handleMetricReportDefinitionCollectionGet(
1103fc0edbe3SEd Tanous     App& app, const crow::Request& req,
1104fc0edbe3SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1105fc0edbe3SEd Tanous {
1106fc0edbe3SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1107fc0edbe3SEd Tanous     {
1108fc0edbe3SEd Tanous         return;
1109fc0edbe3SEd Tanous     }
11109e6c388aSLukasz Kazmierczak     asyncResp->res.addHeader(
11119e6c388aSLukasz Kazmierczak         boost::beast::http::field::link,
11129e6c388aSLukasz Kazmierczak         "</redfish/v1/JsonSchemas/MetricReportDefinition/MetricReportDefinition.json>; rel=describedby");
1113fc0edbe3SEd Tanous 
1114fc0edbe3SEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
1115fc0edbe3SEd Tanous         "#MetricReportDefinitionCollection."
1116fc0edbe3SEd Tanous         "MetricReportDefinitionCollection";
1117fc0edbe3SEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
1118fc0edbe3SEd Tanous         "/redfish/v1/TelemetryService/MetricReportDefinitions";
1119fc0edbe3SEd Tanous     asyncResp->res.jsonValue["Name"] = "Metric Definition Collection";
1120fc0edbe3SEd Tanous     constexpr std::array<std::string_view, 1> interfaces{
1121fc0edbe3SEd Tanous         telemetry::reportInterface};
1122fc0edbe3SEd Tanous     collection_util::getCollectionMembers(
1123fc0edbe3SEd Tanous         asyncResp,
1124fc0edbe3SEd Tanous         boost::urls::url(
1125fc0edbe3SEd Tanous             "/redfish/v1/TelemetryService/MetricReportDefinitions"),
1126fc0edbe3SEd Tanous         interfaces, "/xyz/openbmc_project/Telemetry/Reports/TelemetryService");
1127fc0edbe3SEd Tanous }
1128fc0edbe3SEd Tanous 
1129bd79bce8SPatrick Williams inline void handleReportPatch(
1130bd79bce8SPatrick Williams     App& app, const crow::Request& req,
1131bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string_view id)
11329e6c388aSLukasz Kazmierczak {
11339e6c388aSLukasz Kazmierczak     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
11349e6c388aSLukasz Kazmierczak     {
11359e6c388aSLukasz Kazmierczak         return;
11369e6c388aSLukasz Kazmierczak     }
11379e6c388aSLukasz Kazmierczak 
11389e6c388aSLukasz Kazmierczak     std::optional<std::string> reportingTypeStr;
11399e6c388aSLukasz Kazmierczak     std::optional<std::string> reportUpdatesStr;
11409e6c388aSLukasz Kazmierczak     std::optional<bool> metricReportDefinitionEnabled;
1141b14f357fSEd Tanous     std::optional<std::vector<nlohmann::json::object_t>> metrics;
11429e6c388aSLukasz Kazmierczak     std::optional<std::vector<std::string>> reportActionsStr;
1143b14f357fSEd Tanous     std::optional<std::string> scheduleDurationStr;
11449e6c388aSLukasz Kazmierczak 
11459e6c388aSLukasz Kazmierczak     if (!json_util::readJsonPatch(
11469e6c388aSLukasz Kazmierczak             req, asyncResp->res, "Metrics", metrics,
11479e6c388aSLukasz Kazmierczak             "MetricReportDefinitionType", reportingTypeStr, "ReportUpdates",
1148b14f357fSEd Tanous             reportUpdatesStr, "ReportActions", reportActionsStr,
1149b14f357fSEd Tanous             "Schedule/RecurrenceInterval", scheduleDurationStr,
1150b14f357fSEd Tanous             "MetricReportDefinitionEnabled", metricReportDefinitionEnabled))
11519e6c388aSLukasz Kazmierczak     {
11529e6c388aSLukasz Kazmierczak         return;
11539e6c388aSLukasz Kazmierczak     }
11549e6c388aSLukasz Kazmierczak 
11559e6c388aSLukasz Kazmierczak     if (metricReportDefinitionEnabled)
11569e6c388aSLukasz Kazmierczak     {
11579e6c388aSLukasz Kazmierczak         setReportEnabled(asyncResp, id, *metricReportDefinitionEnabled);
11589e6c388aSLukasz Kazmierczak     }
11599e6c388aSLukasz Kazmierczak 
11609e6c388aSLukasz Kazmierczak     if (reportUpdatesStr)
11619e6c388aSLukasz Kazmierczak     {
1162*b4361d63SEd Tanous         setReportUpdates(asyncResp, id, *reportUpdatesStr);
11639e6c388aSLukasz Kazmierczak     }
11649e6c388aSLukasz Kazmierczak 
11659e6c388aSLukasz Kazmierczak     if (reportActionsStr)
11669e6c388aSLukasz Kazmierczak     {
1167*b4361d63SEd Tanous         setReportActions(asyncResp, id, *reportActionsStr);
11689e6c388aSLukasz Kazmierczak     }
11699e6c388aSLukasz Kazmierczak 
1170b14f357fSEd Tanous     if (reportingTypeStr || scheduleDurationStr)
11719e6c388aSLukasz Kazmierczak     {
1172*b4361d63SEd Tanous         setReportTypeAndInterval(asyncResp, id, reportingTypeStr,
1173*b4361d63SEd Tanous                                  scheduleDurationStr);
11749e6c388aSLukasz Kazmierczak     }
11759e6c388aSLukasz Kazmierczak 
11769e6c388aSLukasz Kazmierczak     if (metrics)
11779e6c388aSLukasz Kazmierczak     {
11789e6c388aSLukasz Kazmierczak         setReportMetrics(asyncResp, id, *metrics);
11799e6c388aSLukasz Kazmierczak     }
11809e6c388aSLukasz Kazmierczak }
11819e6c388aSLukasz Kazmierczak 
1182bd79bce8SPatrick Williams inline void handleReportDelete(
1183bd79bce8SPatrick Williams     App& app, const crow::Request& req,
1184bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, std::string_view id)
11859e6c388aSLukasz Kazmierczak {
11869e6c388aSLukasz Kazmierczak     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
11879e6c388aSLukasz Kazmierczak     {
11889e6c388aSLukasz Kazmierczak         return;
11899e6c388aSLukasz Kazmierczak     }
11909e6c388aSLukasz Kazmierczak 
11919e6c388aSLukasz Kazmierczak     const std::string reportPath = getDbusReportPath(id);
11929e6c388aSLukasz Kazmierczak 
11939e6c388aSLukasz Kazmierczak     crow::connections::systemBus->async_method_call(
11949e6c388aSLukasz Kazmierczak         [asyncResp,
11959e6c388aSLukasz Kazmierczak          reportId = std::string(id)](const boost::system::error_code& ec) {
11969e6c388aSLukasz Kazmierczak             if (!verifyCommonErrors(asyncResp->res, reportId, ec))
11979e6c388aSLukasz Kazmierczak             {
11989e6c388aSLukasz Kazmierczak                 return;
11999e6c388aSLukasz Kazmierczak             }
12009e6c388aSLukasz Kazmierczak             asyncResp->res.result(boost::beast::http::status::no_content);
12019e6c388aSLukasz Kazmierczak         },
12029e6c388aSLukasz Kazmierczak         service, reportPath, "xyz.openbmc_project.Object.Delete", "Delete");
12039e6c388aSLukasz Kazmierczak }
12049e6c388aSLukasz Kazmierczak } // namespace telemetry
12059e6c388aSLukasz Kazmierczak 
120695bdb5f0SEd Tanous inline void afterRetrieveUriToDbusMap(
120795bdb5f0SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
120895bdb5f0SEd Tanous     const std::shared_ptr<telemetry::AddReport>& addReportReq,
120995bdb5f0SEd Tanous     const boost::beast::http::status status,
121095bdb5f0SEd Tanous     const std::map<std::string, std::string>& uriToDbus)
121195bdb5f0SEd Tanous {
121295bdb5f0SEd Tanous     if (status != boost::beast::http::status::ok)
121395bdb5f0SEd Tanous     {
121495bdb5f0SEd Tanous         BMCWEB_LOG_ERROR(
121595bdb5f0SEd Tanous             "Failed to retrieve URI to dbus sensors map with err {}",
121695bdb5f0SEd Tanous             static_cast<unsigned>(status));
121795bdb5f0SEd Tanous         return;
121895bdb5f0SEd Tanous     }
121995bdb5f0SEd Tanous     addReportReq->insert(uriToDbus);
122095bdb5f0SEd Tanous }
122195bdb5f0SEd Tanous 
12229e6c388aSLukasz Kazmierczak inline void handleMetricReportDefinitionsPost(
12239e6c388aSLukasz Kazmierczak     App& app, const crow::Request& req,
12249e6c388aSLukasz Kazmierczak     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
12259e6c388aSLukasz Kazmierczak {
12269e6c388aSLukasz Kazmierczak     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
12279e6c388aSLukasz Kazmierczak     {
12289e6c388aSLukasz Kazmierczak         return;
12299e6c388aSLukasz Kazmierczak     }
12309e6c388aSLukasz Kazmierczak 
12319e6c388aSLukasz Kazmierczak     telemetry::AddReportArgs args;
12329e6c388aSLukasz Kazmierczak     if (!telemetry::getUserParameters(asyncResp->res, req, args))
12339e6c388aSLukasz Kazmierczak     {
12349e6c388aSLukasz Kazmierczak         return;
12359e6c388aSLukasz Kazmierczak     }
12369e6c388aSLukasz Kazmierczak 
12379e6c388aSLukasz Kazmierczak     boost::container::flat_set<std::pair<std::string, std::string>>
12389e6c388aSLukasz Kazmierczak         chassisSensors;
12399e6c388aSLukasz Kazmierczak     if (!telemetry::getChassisSensorNodeFromMetrics(asyncResp, args.metrics,
12409e6c388aSLukasz Kazmierczak                                                     chassisSensors))
12419e6c388aSLukasz Kazmierczak     {
12429e6c388aSLukasz Kazmierczak         return;
12439e6c388aSLukasz Kazmierczak     }
12449e6c388aSLukasz Kazmierczak 
1245bd79bce8SPatrick Williams     auto addReportReq =
1246bd79bce8SPatrick Williams         std::make_shared<telemetry::AddReport>(std::move(args), asyncResp);
12479e6c388aSLukasz Kazmierczak     for (const auto& [chassis, sensorType] : chassisSensors)
12489e6c388aSLukasz Kazmierczak     {
124995bdb5f0SEd Tanous         retrieveUriToDbusMap(chassis, sensorType,
125095bdb5f0SEd Tanous                              std::bind_front(afterRetrieveUriToDbusMap,
125195bdb5f0SEd Tanous                                              asyncResp, addReportReq));
12529e6c388aSLukasz Kazmierczak     }
12539e6c388aSLukasz Kazmierczak }
12549e6c388aSLukasz Kazmierczak 
12559e6c388aSLukasz Kazmierczak inline void
12564220be3bSEd Tanous     handleMetricReportHead(App& app, const crow::Request& req,
12574220be3bSEd Tanous                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
12584220be3bSEd Tanous                            const std::string& /*id*/)
12594220be3bSEd Tanous {
12604220be3bSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
12614220be3bSEd Tanous     {
12624220be3bSEd Tanous         return;
12634220be3bSEd Tanous     }
12644220be3bSEd Tanous     asyncResp->res.addHeader(
12654220be3bSEd Tanous         boost::beast::http::field::link,
12664220be3bSEd Tanous         "</redfish/v1/JsonSchemas/MetricReport/MetricReport.json>; rel=describedby");
12674220be3bSEd Tanous }
12684220be3bSEd Tanous 
1269bd79bce8SPatrick Williams inline void handleMetricReportGet(
1270bd79bce8SPatrick Williams     App& app, const crow::Request& req,
1271bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
127286a5ac98SEd Tanous {
127386a5ac98SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
127486a5ac98SEd Tanous     {
127586a5ac98SEd Tanous         return;
127686a5ac98SEd Tanous     }
12774220be3bSEd Tanous     asyncResp->res.addHeader(
12784220be3bSEd Tanous         boost::beast::http::field::link,
12794220be3bSEd Tanous         "</redfish/v1/JsonSchemas/MetricReport/MetricReport.json>; rel=describedby");
128086a5ac98SEd Tanous 
128186a5ac98SEd Tanous     sdbusplus::asio::getAllProperties(
128286a5ac98SEd Tanous         *crow::connections::systemBus, telemetry::service,
128386a5ac98SEd Tanous         telemetry::getDbusReportPath(id), telemetry::reportInterface,
128486a5ac98SEd Tanous         [asyncResp, id](const boost::system::error_code& ec,
128586a5ac98SEd Tanous                         const dbus::utility::DBusPropertiesMap& properties) {
12869e6c388aSLukasz Kazmierczak             if (!redfish::telemetry::verifyCommonErrors(asyncResp->res, id, ec))
128786a5ac98SEd Tanous             {
128886a5ac98SEd Tanous                 return;
128986a5ac98SEd Tanous             }
129086a5ac98SEd Tanous 
129186a5ac98SEd Tanous             telemetry::fillReportDefinition(asyncResp, id, properties);
129286a5ac98SEd Tanous         });
129386a5ac98SEd Tanous }
129486a5ac98SEd Tanous 
1295dd1c4a9cSSzymon Dompke inline void handleMetricReportDelete(
1296dd1c4a9cSSzymon Dompke     App& app, const crow::Request& req,
1297dd1c4a9cSSzymon Dompke     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
1298dd1c4a9cSSzymon Dompke 
1299dd1c4a9cSSzymon Dompke {
1300dd1c4a9cSSzymon Dompke     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1301dd1c4a9cSSzymon Dompke     {
1302dd1c4a9cSSzymon Dompke         return;
1303dd1c4a9cSSzymon Dompke     }
1304dd1c4a9cSSzymon Dompke 
1305dd1c4a9cSSzymon Dompke     const std::string reportPath = telemetry::getDbusReportPath(id);
1306dd1c4a9cSSzymon Dompke 
1307dd1c4a9cSSzymon Dompke     crow::connections::systemBus->async_method_call(
1308dd1c4a9cSSzymon Dompke         [asyncResp, id](const boost::system::error_code& ec) {
1309dd1c4a9cSSzymon Dompke             /*
1310dd1c4a9cSSzymon Dompke              * boost::system::errc and std::errc are missing value
1311dd1c4a9cSSzymon Dompke              * for EBADR error that is defined in Linux.
1312dd1c4a9cSSzymon Dompke              */
1313dd1c4a9cSSzymon Dompke             if (ec.value() == EBADR)
1314dd1c4a9cSSzymon Dompke             {
1315bd79bce8SPatrick Williams                 messages::resourceNotFound(asyncResp->res,
1316bd79bce8SPatrick Williams                                            "MetricReportDefinition", id);
1317dd1c4a9cSSzymon Dompke                 return;
1318dd1c4a9cSSzymon Dompke             }
1319dd1c4a9cSSzymon Dompke 
1320dd1c4a9cSSzymon Dompke             if (ec)
1321dd1c4a9cSSzymon Dompke             {
132262598e31SEd Tanous                 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
1323dd1c4a9cSSzymon Dompke                 messages::internalError(asyncResp->res);
1324dd1c4a9cSSzymon Dompke                 return;
1325dd1c4a9cSSzymon Dompke             }
1326dd1c4a9cSSzymon Dompke 
1327dd1c4a9cSSzymon Dompke             asyncResp->res.result(boost::beast::http::status::no_content);
1328dd1c4a9cSSzymon Dompke         },
1329dd1c4a9cSSzymon Dompke         telemetry::service, reportPath, "xyz.openbmc_project.Object.Delete",
1330dd1c4a9cSSzymon Dompke         "Delete");
1331dd1c4a9cSSzymon Dompke }
1332dd1c4a9cSSzymon Dompke 
13337e860f15SJohn Edward Broadbent inline void requestRoutesMetricReportDefinitionCollection(App& app)
1334081ebf06SWludzik, Jozef {
13357e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReportDefinitions/")
13364220be3bSEd Tanous         .privileges(redfish::privileges::headMetricReportDefinitionCollection)
13374220be3bSEd Tanous         .methods(boost::beast::http::verb::head)(std::bind_front(
13389e6c388aSLukasz Kazmierczak             telemetry::handleMetricReportDefinitionCollectionHead,
13399e6c388aSLukasz Kazmierczak             std::ref(app)));
13404220be3bSEd Tanous 
13414220be3bSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReportDefinitions/")
1342ed398213SEd Tanous         .privileges(redfish::privileges::getMetricReportDefinitionCollection)
13434220be3bSEd Tanous         .methods(boost::beast::http::verb::get)(std::bind_front(
13449e6c388aSLukasz Kazmierczak             telemetry::handleMetricReportDefinitionCollectionGet,
13459e6c388aSLukasz Kazmierczak             std::ref(app)));
13464dbb8aeaSWludzik, Jozef 
13477e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/MetricReportDefinitions/")
1348ed398213SEd Tanous         .privileges(redfish::privileges::postMetricReportDefinitionCollection)
1349002d39b4SEd Tanous         .methods(boost::beast::http::verb::post)(
13509e6c388aSLukasz Kazmierczak             std::bind_front(handleMetricReportDefinitionsPost, std::ref(app)));
1351081ebf06SWludzik, Jozef }
1352081ebf06SWludzik, Jozef 
13537e860f15SJohn Edward Broadbent inline void requestRoutesMetricReportDefinition(App& app)
1354081ebf06SWludzik, Jozef {
13557e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
13567e860f15SJohn Edward Broadbent                  "/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
1357ed398213SEd Tanous         .privileges(redfish::privileges::getMetricReportDefinition)
13584220be3bSEd Tanous         .methods(boost::beast::http::verb::head)(
13594220be3bSEd Tanous             std::bind_front(handleMetricReportHead, std::ref(app)));
13604220be3bSEd Tanous 
13614220be3bSEd Tanous     BMCWEB_ROUTE(app,
13624220be3bSEd Tanous                  "/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
13634220be3bSEd Tanous         .privileges(redfish::privileges::getMetricReportDefinition)
13647e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
136586a5ac98SEd Tanous             std::bind_front(handleMetricReportGet, std::ref(app)));
1366479e899dSKrzysztof Grobelny 
13677e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app,
13687e860f15SJohn Edward Broadbent                  "/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
13699e6c388aSLukasz Kazmierczak         .privileges(redfish::privileges::deleteMetricReportDefinition)
13707e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::delete_)(
1371dd1c4a9cSSzymon Dompke             std::bind_front(handleMetricReportDelete, std::ref(app)));
13729e6c388aSLukasz Kazmierczak 
13739e6c388aSLukasz Kazmierczak     BMCWEB_ROUTE(app,
13749e6c388aSLukasz Kazmierczak                  "/redfish/v1/TelemetryService/MetricReportDefinitions/<str>/")
13759e6c388aSLukasz Kazmierczak         .privileges(redfish::privileges::patchMetricReportDefinition)
13769e6c388aSLukasz Kazmierczak         .methods(boost::beast::http::verb::patch)(
13779e6c388aSLukasz Kazmierczak             std::bind_front(telemetry::handleReportPatch, std::ref(app)));
13784dbb8aeaSWludzik, Jozef }
1379081ebf06SWludzik, Jozef } // namespace redfish
1380