blob: c8559eb8f7ed6b3197de5f4167a47971accb6046 [file] [log] [blame]
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +02001#pragma once
2
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08003#include "app.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07004#include "generated/enums/metric_definition.hpp"
Szymon Dompkedd1c4a92022-03-04 13:11:38 +01005#include "generated/enums/resource.hpp"
6#include "generated/enums/triggers.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08007#include "query.hpp"
8#include "registries/privilege_registry.hpp"
Szymon Dompkedd1c4a92022-03-04 13:11:38 +01009#include "utility.hpp"
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020010#include "utils/collection.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080011#include "utils/dbus_utils.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070012#include "utils/json_utils.hpp"
Janet Adkins1516c212024-08-14 13:22:41 -050013#include "utils/sensor_utils.hpp"
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020014#include "utils/telemetry_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080015#include "utils/time_utils.hpp"
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020016
Ed Tanousef4c65b2023-04-24 15:28:50 -070017#include <boost/url/format.hpp>
Krzysztof Grobelny89474492022-09-06 16:30:38 +020018#include <sdbusplus/asio/property.hpp>
19#include <sdbusplus/unpack_properties.hpp>
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020020
George Liu7a1dbc42022-12-07 16:03:22 +080021#include <array>
22#include <string_view>
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020023#include <tuple>
24#include <variant>
25#include <vector>
26
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020027namespace redfish
28{
29namespace telemetry
30{
31constexpr const char* triggerInterface =
32 "xyz.openbmc_project.Telemetry.Trigger";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020033
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020034using NumericThresholdParams =
35 std::tuple<std::string, uint64_t, std::string, double>;
36
37using DiscreteThresholdParams =
38 std::tuple<std::string, std::string, uint64_t, std::string>;
39
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020040using TriggerSensorsParams =
41 std::vector<std::pair<sdbusplus::message::object_path, std::string>>;
42
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010043inline triggers::TriggerActionEnum
44 toRedfishTriggerAction(std::string_view dbusValue)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020045{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010046 if (dbusValue ==
47 "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.UpdateReport")
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020048 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010049 return triggers::TriggerActionEnum::RedfishMetricReport;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020050 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010051 if (dbusValue ==
52 "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToRedfishEventLog")
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020053 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010054 return triggers::TriggerActionEnum::RedfishEvent;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020055 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010056 if (dbusValue ==
57 "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToJournal")
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020058 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010059 return triggers::TriggerActionEnum::LogToLogService;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020060 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010061 return triggers::TriggerActionEnum::Invalid;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020062}
63
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010064inline std::string toDbusTriggerAction(std::string_view redfishValue)
65{
66 if (redfishValue == "RedfishMetricReport")
67 {
68 return "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.UpdateReport";
69 }
70 if (redfishValue == "RedfishEvent")
71 {
72 return "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToRedfishEventLog";
73 }
74 if (redfishValue == "LogToLogService")
75 {
76 return "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToJournal";
77 }
78 return "";
79}
80
81inline std::string toDbusSeverity(std::string_view redfishValue)
82{
83 if (redfishValue == "OK")
84 {
85 return "xyz.openbmc_project.Telemetry.Trigger.Severity.OK";
86 }
87 if (redfishValue == "Warning")
88 {
89 return "xyz.openbmc_project.Telemetry.Trigger.Severity.Warning";
90 }
91 if (redfishValue == "Critical")
92 {
93 return "xyz.openbmc_project.Telemetry.Trigger.Severity.Critical";
94 }
95 return "";
96}
97
98inline resource::Health toRedfishSeverity(std::string_view dbusValue)
99{
100 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Severity.OK")
101 {
102 return resource::Health::OK;
103 }
104 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Severity.Warning")
105 {
106 return resource::Health::Warning;
107 }
108 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Severity.Critical")
109 {
110 return resource::Health::Critical;
111 }
112 return resource::Health::Invalid;
113}
114
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100115inline std::string toRedfishThresholdName(std::string_view dbusValue)
116{
117 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.UpperCritical")
118 {
119 return "UpperCritical";
120 }
121
122 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.LowerCritical")
123 {
124 return "LowerCritical";
125 }
126
127 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.UpperWarning")
128 {
129 return "UpperWarning";
130 }
131
132 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.LowerWarning")
133 {
134 return "LowerWarning";
135 }
136
137 return "";
138}
139
140inline std::string toDbusActivation(std::string_view redfishValue)
141{
142 if (redfishValue == "Either")
143 {
144 return "xyz.openbmc_project.Telemetry.Trigger.Direction.Either";
145 }
146
147 if (redfishValue == "Decreasing")
148 {
149 return "xyz.openbmc_project.Telemetry.Trigger.Direction.Decreasing";
150 }
151
152 if (redfishValue == "Increasing")
153 {
154 return "xyz.openbmc_project.Telemetry.Trigger.Direction.Increasing";
155 }
156
157 return "";
158}
159
160inline triggers::ThresholdActivation
161 toRedfishActivation(std::string_view dbusValue)
162{
163 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Direction.Either")
164 {
165 return triggers::ThresholdActivation::Either;
166 }
167
168 if (dbusValue ==
169 "xyz.openbmc_project.Telemetry.Trigger.Direction.Decreasing")
170 {
171 return triggers::ThresholdActivation::Decreasing;
172 }
173
174 if (dbusValue ==
175 "xyz.openbmc_project.Telemetry.Trigger.Direction.Increasing")
176 {
177 return triggers::ThresholdActivation::Increasing;
178 }
179
180 return triggers::ThresholdActivation::Invalid;
181}
182
183enum class MetricType
184{
185 Discrete,
186 Numeric
187};
188
189enum class DiscreteCondition
190{
191 Specified,
192 Changed
193};
194
195struct Context
196{
197 std::string id;
198 std::string name;
199 std::vector<std::string> actions;
200 std::vector<std::pair<sdbusplus::message::object_path, std::string>>
201 sensors;
202 std::vector<sdbusplus::message::object_path> reports;
Ed Tanous58c71482024-10-19 14:35:07 -0700203 std::vector<NumericThresholdParams> numericThresholds;
204 std::vector<DiscreteThresholdParams> discreteThresholds;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100205 std::optional<DiscreteCondition> discreteCondition;
206 std::optional<MetricType> metricType;
207 std::optional<std::vector<std::string>> metricProperties;
208};
209
210inline std::optional<sdbusplus::message::object_path>
211 getReportPathFromReportDefinitionUri(const std::string& uri)
212{
Ed Tanous6fd29552023-10-04 09:40:14 -0700213 boost::system::result<boost::urls::url_view> parsed =
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100214 boost::urls::parse_relative_ref(uri);
215
216 if (!parsed)
217 {
218 return std::nullopt;
219 }
220
221 std::string id;
222 if (!crow::utility::readUrlSegments(
223 *parsed, "redfish", "v1", "TelemetryService",
224 "MetricReportDefinitions", std::ref(id)))
225 {
226 return std::nullopt;
227 }
228
229 return sdbusplus::message::object_path(
230 "/xyz/openbmc_project/Telemetry/Reports") /
231 "TelemetryService" / id;
232}
233
234inline std::optional<MetricType> getMetricType(const std::string& metricType)
235{
236 if (metricType == "Discrete")
237 {
238 return MetricType::Discrete;
239 }
240 if (metricType == "Numeric")
241 {
242 return MetricType::Numeric;
243 }
244 return std::nullopt;
245}
246
247inline std::optional<DiscreteCondition>
248 getDiscreteCondition(const std::string& discreteTriggerCondition)
249{
250 if (discreteTriggerCondition == "Specified")
251 {
252 return DiscreteCondition::Specified;
253 }
254 if (discreteTriggerCondition == "Changed")
255 {
256 return DiscreteCondition::Changed;
257 }
258 return std::nullopt;
259}
260
Ed Tanous2932dcb2024-03-06 12:04:47 -0800261inline bool parseThreshold(crow::Response& res,
262 nlohmann::json::object_t& threshold,
263 std::string_view dbusThresholdName,
264 std::vector<NumericThresholdParams>& parsedParams)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100265{
Ed Tanous2932dcb2024-03-06 12:04:47 -0800266 double reading = 0.0;
267 std::string activation;
268 std::string dwellTimeStr;
269
Myung Baeafc474a2024-10-09 00:53:29 -0700270 if (!json_util::readJsonObject( //
271 threshold, res, //
272 "Activation", activation, //
273 "DwellTime", dwellTimeStr, //
274 "Reading", reading //
275 ))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100276 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100277 return false;
278 }
279
Ed Tanous2932dcb2024-03-06 12:04:47 -0800280 std::string dbusActivation = toDbusActivation(activation);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100281
Ed Tanous2932dcb2024-03-06 12:04:47 -0800282 if (dbusActivation.empty())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100283 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800284 messages::propertyValueIncorrect(res, "Activation", activation);
285 return false;
286 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100287
Ed Tanous2932dcb2024-03-06 12:04:47 -0800288 std::optional<std::chrono::milliseconds> dwellTime =
289 time_utils::fromDurationString(dwellTimeStr);
290 if (!dwellTime)
291 {
292 messages::propertyValueIncorrect(res, "DwellTime", dwellTimeStr);
293 return false;
294 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100295
Ed Tanous2932dcb2024-03-06 12:04:47 -0800296 parsedParams.emplace_back(dbusThresholdName,
297 static_cast<uint64_t>(dwellTime->count()),
298 dbusActivation, reading);
299 return true;
300}
301
302struct NumericThresholds
303{
304 std::optional<nlohmann::json::object_t> upperCritical;
305 std::optional<nlohmann::json::object_t> upperWarning;
306 std::optional<nlohmann::json::object_t> lowerWarning;
307 std::optional<nlohmann::json::object_t> lowerCritical;
308
309 bool any() const
310 {
311 return upperCritical || upperWarning || lowerWarning || lowerCritical;
312 }
313};
314
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400315inline bool parseNumericThresholds(
316 crow::Response& res, NumericThresholds& numericThresholds, Context& ctx)
Ed Tanous2932dcb2024-03-06 12:04:47 -0800317{
318 std::vector<NumericThresholdParams> parsedParams;
319 if (numericThresholds.upperCritical)
320 {
321 if (!parseThreshold(
322 res, *numericThresholds.upperCritical,
323 "xyz.openbmc_project.Telemetry.Trigger.Type.UpperCritical",
324 parsedParams))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100325 {
326 return false;
327 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800328 }
329 if (numericThresholds.upperWarning)
330 {
331 if (!parseThreshold(
332 res, *numericThresholds.upperWarning,
333 "xyz.openbmc_project.Telemetry.Trigger.Type.UpperWarning",
334 parsedParams))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100335 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100336 return false;
337 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800338 }
339 if (numericThresholds.lowerWarning)
340 {
341 if (!parseThreshold(
342 res, *numericThresholds.lowerWarning,
343 "xyz.openbmc_project.Telemetry.Trigger.Type.LowerWarning",
344 parsedParams))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100345 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100346 return false;
347 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800348 }
349 if (numericThresholds.lowerCritical)
350 {
351 if (!parseThreshold(
352 res, *numericThresholds.lowerCritical,
353 "xyz.openbmc_project.Telemetry.Trigger.Type.LowerCritical",
354 parsedParams))
355 {
356 return false;
357 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100358 }
359
Ed Tanous58c71482024-10-19 14:35:07 -0700360 ctx.numericThresholds = std::move(parsedParams);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100361 return true;
362}
363
364inline bool parseDiscreteTriggers(
365 crow::Response& res,
Ed Tanous2932dcb2024-03-06 12:04:47 -0800366 std::optional<std::vector<nlohmann::json::object_t>>& discreteTriggers,
367 Context& ctx)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100368{
369 std::vector<DiscreteThresholdParams> parsedParams;
370 if (!discreteTriggers)
371 {
Ed Tanous58c71482024-10-19 14:35:07 -0700372 ctx.discreteThresholds = std::move(parsedParams);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100373 return true;
374 }
375
376 parsedParams.reserve(discreteTriggers->size());
Ed Tanous2932dcb2024-03-06 12:04:47 -0800377 for (nlohmann::json::object_t& thresholdInfo : *discreteTriggers)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100378 {
379 std::optional<std::string> name = "";
380 std::string value;
381 std::string dwellTimeStr;
382 std::string severity;
383
Myung Baeafc474a2024-10-09 00:53:29 -0700384 if (!json_util::readJsonObject( //
385 thresholdInfo, res, //
386 "DwellTime", dwellTimeStr, //
387 "Name", name, //
388 "Severity", severity, //
389 "Value", value //
390 ))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100391 {
392 return false;
393 }
394
395 std::optional<std::chrono::milliseconds> dwellTime =
396 time_utils::fromDurationString(dwellTimeStr);
397 if (!dwellTime)
398 {
399 messages::propertyValueIncorrect(res, "DwellTime", dwellTimeStr);
400 return false;
401 }
402
403 std::string dbusSeverity = toDbusSeverity(severity);
404 if (dbusSeverity.empty())
405 {
406 messages::propertyValueIncorrect(res, "Severity", severity);
407 return false;
408 }
409
410 parsedParams.emplace_back(*name, dbusSeverity,
411 static_cast<uint64_t>(dwellTime->count()),
412 value);
413 }
414
Ed Tanous58c71482024-10-19 14:35:07 -0700415 ctx.discreteThresholds = std::move(parsedParams);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100416 return true;
417}
418
419inline bool parseTriggerThresholds(
420 crow::Response& res,
Ed Tanous2932dcb2024-03-06 12:04:47 -0800421 std::optional<std::vector<nlohmann::json::object_t>>& discreteTriggers,
422 NumericThresholds& numericThresholds, Context& ctx)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100423{
Ed Tanous2932dcb2024-03-06 12:04:47 -0800424 if (discreteTriggers && numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100425 {
426 messages::propertyValueConflict(res, "DiscreteTriggers",
427 "NumericThresholds");
428 messages::propertyValueConflict(res, "NumericThresholds",
429 "DiscreteTriggers");
430 return false;
431 }
432
433 if (ctx.discreteCondition)
434 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800435 if (numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100436 {
437 messages::propertyValueConflict(res, "DiscreteTriggerCondition",
438 "NumericThresholds");
439 messages::propertyValueConflict(res, "NumericThresholds",
440 "DiscreteTriggerCondition");
441 return false;
442 }
443 }
444
445 if (ctx.metricType)
446 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800447 if (*ctx.metricType == MetricType::Discrete && numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100448 {
449 messages::propertyValueConflict(res, "NumericThresholds",
450 "MetricType");
451 return false;
452 }
453 if (*ctx.metricType == MetricType::Numeric && discreteTriggers)
454 {
455 messages::propertyValueConflict(res, "DiscreteTriggers",
456 "MetricType");
457 return false;
458 }
459 if (*ctx.metricType == MetricType::Numeric && ctx.discreteCondition)
460 {
461 messages::propertyValueConflict(res, "DiscreteTriggers",
462 "DiscreteTriggerCondition");
463 return false;
464 }
465 }
466
467 if (discreteTriggers || ctx.discreteCondition ||
468 (ctx.metricType && *ctx.metricType == MetricType::Discrete))
469 {
470 if (ctx.discreteCondition)
471 {
472 if (*ctx.discreteCondition == DiscreteCondition::Specified &&
473 !discreteTriggers)
474 {
475 messages::createFailedMissingReqProperties(res,
476 "DiscreteTriggers");
477 return false;
478 }
479 if (discreteTriggers &&
480 ((*ctx.discreteCondition == DiscreteCondition::Specified &&
481 discreteTriggers->empty()) ||
482 (*ctx.discreteCondition == DiscreteCondition::Changed &&
483 !discreteTriggers->empty())))
484 {
485 messages::propertyValueConflict(res, "DiscreteTriggers",
486 "DiscreteTriggerCondition");
487 return false;
488 }
489 }
490 if (!parseDiscreteTriggers(res, discreteTriggers, ctx))
491 {
492 return false;
493 }
494 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800495 else if (numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100496 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800497 if (!parseNumericThresholds(res, numericThresholds, ctx))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100498 {
499 return false;
500 }
501 }
502 else
503 {
504 messages::createFailedMissingReqProperties(
505 res, "'DiscreteTriggers', 'NumericThresholds', "
506 "'DiscreteTriggerCondition' or 'MetricType'");
507 return false;
508 }
509 return true;
510}
511
Ed Tanous2932dcb2024-03-06 12:04:47 -0800512inline bool parseLinks(crow::Response& res,
513 const std::vector<std::string>& metricReportDefinitions,
514 Context& ctx)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100515{
Ed Tanous2932dcb2024-03-06 12:04:47 -0800516 ctx.reports.reserve(metricReportDefinitions.size());
517 for (const std::string& reportDefinionUri : metricReportDefinitions)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100518 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800519 std::optional<sdbusplus::message::object_path> reportPath =
520 getReportPathFromReportDefinitionUri(reportDefinionUri);
521 if (!reportPath)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100522 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800523 messages::propertyValueIncorrect(res, "MetricReportDefinitions",
524 reportDefinionUri);
525 return false;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100526 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800527 ctx.reports.emplace_back(*reportPath);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100528 }
529 return true;
530}
531
532inline bool parseMetricProperties(crow::Response& res, Context& ctx)
533{
534 if (!ctx.metricProperties)
535 {
536 return true;
537 }
538
539 ctx.sensors.reserve(ctx.metricProperties->size());
540
541 size_t uriIdx = 0;
542 for (const std::string& uriStr : *ctx.metricProperties)
543 {
Ed Tanous4a7fbef2024-04-06 16:03:49 -0700544 boost::system::result<boost::urls::url> uri =
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100545 boost::urls::parse_relative_ref(uriStr);
546 if (!uri)
547 {
548 messages::propertyValueIncorrect(
549 res, "MetricProperties/" + std::to_string(uriIdx), uriStr);
550 return false;
551 }
552 std::string chassisName;
553 std::string sensorName;
554 if (!crow::utility::readUrlSegments(*uri, "redfish", "v1", "Chassis",
555 std::ref(chassisName), "Sensors",
556 std::ref(sensorName)))
557 {
558 messages::propertyValueIncorrect(
559 res, "MetricProperties/" + std::to_string(uriIdx), uriStr);
560 return false;
561 }
562
563 std::pair<std::string, std::string> split =
Janet Adkins1516c212024-08-14 13:22:41 -0500564 redfish::sensor_utils::splitSensorNameAndType(sensorName);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100565 if (split.first.empty() || split.second.empty())
566 {
567 messages::propertyValueIncorrect(
568 res, "MetricProperties/" + std::to_string(uriIdx), uriStr);
569 return false;
570 }
571
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400572 std::string sensorPath =
573 "/xyz/openbmc_project/sensors/" + split.first + '/' + split.second;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100574
575 ctx.sensors.emplace_back(sensorPath, uriStr);
576 uriIdx++;
577 }
578 return true;
579}
580
581inline bool parsePostTriggerParams(crow::Response& res,
582 const crow::Request& req, Context& ctx)
583{
584 std::optional<std::string> id = "";
585 std::optional<std::string> name = "";
586 std::optional<std::string> metricType;
587 std::optional<std::vector<std::string>> triggerActions;
588 std::optional<std::string> discreteTriggerCondition;
Ed Tanous2932dcb2024-03-06 12:04:47 -0800589 std::optional<std::vector<nlohmann::json::object_t>> discreteTriggers;
590 std::optional<std::vector<std::string>> metricReportDefinitions;
591 NumericThresholds thresholds;
Myung Baeafc474a2024-10-09 00:53:29 -0700592
593 if (!json_util::readJsonPatch( //
594 req, res, //
595 "Id", id, //
596 "DiscreteTriggerCondition", discreteTriggerCondition, //
597 "DiscreteTriggers", discreteTriggers, //
598 "Links/MetricReportDefinitions", metricReportDefinitions, //
599 "MetricProperties", ctx.metricProperties, //
600 "MetricType", metricType, //
601 "Name", name, //
602 "NumericThresholds/LowerCritical", thresholds.lowerCritical, //
603 "NumericThresholds/LowerWarning", thresholds.lowerWarning, //
604 "NumericThresholds/UpperCritical", thresholds.upperCritical, //
605 "NumericThresholds/UpperWarning", thresholds.upperWarning, //
606 "TriggerActions", triggerActions //
607 ))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100608 {
609 return false;
610 }
611
612 ctx.id = *id;
613 ctx.name = *name;
614
615 if (metricType)
616 {
Ed Tanousd5736ef2023-07-06 10:37:23 -0700617 ctx.metricType = getMetricType(*metricType);
618 if (!ctx.metricType)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100619 {
620 messages::propertyValueIncorrect(res, "MetricType", *metricType);
621 return false;
622 }
623 }
624
625 if (discreteTriggerCondition)
626 {
Ed Tanousd5736ef2023-07-06 10:37:23 -0700627 ctx.discreteCondition = getDiscreteCondition(*discreteTriggerCondition);
628 if (!ctx.discreteCondition)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100629 {
630 messages::propertyValueIncorrect(res, "DiscreteTriggerCondition",
631 *discreteTriggerCondition);
632 return false;
633 }
634 }
635
636 if (triggerActions)
637 {
638 ctx.actions.reserve(triggerActions->size());
639 for (const std::string& action : *triggerActions)
640 {
641 std::string dbusAction = toDbusTriggerAction(action);
642
643 if (dbusAction.empty())
644 {
645 messages::propertyValueNotInList(res, action, "TriggerActions");
646 return false;
647 }
648
649 ctx.actions.emplace_back(dbusAction);
650 }
651 }
652 if (!parseMetricProperties(res, ctx))
653 {
654 return false;
655 }
656
Ed Tanous2932dcb2024-03-06 12:04:47 -0800657 if (!parseTriggerThresholds(res, discreteTriggers, thresholds, ctx))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100658 {
659 return false;
660 }
661
Ed Tanous2932dcb2024-03-06 12:04:47 -0800662 if (metricReportDefinitions)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100663 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800664 if (!parseLinks(res, *metricReportDefinitions, ctx))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100665 {
666 return false;
667 }
668 }
669 return true;
670}
671
672inline void afterCreateTrigger(
673 const boost::system::error_code& ec, const std::string& dbusPath,
674 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
675{
676 if (ec == boost::system::errc::file_exists)
677 {
678 messages::resourceAlreadyExists(asyncResp->res, "Trigger", "Id", id);
679 return;
680 }
681 if (ec == boost::system::errc::too_many_files_open)
682 {
683 messages::createLimitReachedForResource(asyncResp->res);
684 return;
685 }
686 if (ec)
687 {
688 messages::internalError(asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -0700689 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100690 return;
691 }
692
693 const std::optional<std::string>& triggerId =
694 getTriggerIdFromDbusPath(dbusPath);
695 if (!triggerId)
696 {
697 messages::internalError(asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -0700698 BMCWEB_LOG_ERROR("Unknown data returned by "
699 "AddTrigger DBus method");
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100700 return;
701 }
702
703 messages::created(asyncResp->res);
704 boost::urls::url locationUrl = boost::urls::format(
705 "/redfish/v1/TelemetryService/Triggers/{}", *triggerId);
706 asyncResp->res.addHeader("Location", locationUrl.buffer());
707}
708
709inline std::optional<nlohmann::json::array_t>
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200710 getTriggerActions(const std::vector<std::string>& dbusActions)
711{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100712 nlohmann::json::array_t triggerActions;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200713 for (const std::string& dbusAction : dbusActions)
714 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100715 triggers::TriggerActionEnum redfishAction =
716 toRedfishTriggerAction(dbusAction);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200717
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100718 if (redfishAction == triggers::TriggerActionEnum::Invalid)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200719 {
720 return std::nullopt;
721 }
722
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100723 triggerActions.emplace_back(redfishAction);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200724 }
725
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100726 return triggerActions;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200727}
728
Ed Tanous58c71482024-10-19 14:35:07 -0700729inline std::optional<nlohmann::json::array_t> getDiscreteTriggers(
730 const std::vector<DiscreteThresholdParams>& discreteParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200731{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100732 nlohmann::json::array_t triggers;
Ed Tanous58c71482024-10-19 14:35:07 -0700733 for (const auto& [name, severity, dwellTime, value] : discreteParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200734 {
735 std::optional<std::string> duration =
736 time_utils::toDurationStringFromUint(dwellTime);
737
738 if (!duration)
739 {
740 return std::nullopt;
741 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700742 nlohmann::json::object_t trigger;
743 trigger["Name"] = name;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100744 trigger["Severity"] = toRedfishSeverity(severity);
Ed Tanous613dabe2022-07-09 11:17:36 -0700745 trigger["DwellTime"] = *duration;
746 trigger["Value"] = value;
Patrick Williamsad539542023-05-12 10:10:08 -0500747 triggers.emplace_back(std::move(trigger));
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200748 }
749
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100750 return triggers;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200751}
752
Ed Tanous58c71482024-10-19 14:35:07 -0700753inline std::optional<nlohmann::json::object_t> getNumericThresholds(
754 const std::vector<NumericThresholdParams>& numericParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200755{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100756 nlohmann::json::object_t thresholds;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200757
Ed Tanous58c71482024-10-19 14:35:07 -0700758 for (const auto& [type, dwellTime, activation, reading] : numericParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200759 {
760 std::optional<std::string> duration =
761 time_utils::toDurationStringFromUint(dwellTime);
762
763 if (!duration)
764 {
765 return std::nullopt;
766 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100767 nlohmann::json& threshold = thresholds[toRedfishThresholdName(type)];
Ed Tanous14766872022-03-15 10:44:42 -0700768 threshold["Reading"] = reading;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100769 threshold["Activation"] = toRedfishActivation(activation);
Ed Tanous14766872022-03-15 10:44:42 -0700770 threshold["DwellTime"] = *duration;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200771 }
772
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100773 return thresholds;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200774}
775
Szymon Dompke3f215c92022-02-22 13:58:00 +0100776inline std::optional<nlohmann::json> getMetricReportDefinitions(
777 const std::vector<sdbusplus::message::object_path>& reportPaths)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200778{
779 nlohmann::json reports = nlohmann::json::array();
Szymon Dompke3f215c92022-02-22 13:58:00 +0100780
781 for (const sdbusplus::message::object_path& path : reportPaths)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200782 {
Szymon Dompke3f215c92022-02-22 13:58:00 +0100783 std::string reportId = path.filename();
784 if (reportId.empty())
785 {
786 {
Ed Tanous62598e32023-07-17 17:06:25 -0700787 BMCWEB_LOG_ERROR("Property Reports contains invalid value: {}",
788 path.str);
Szymon Dompke3f215c92022-02-22 13:58:00 +0100789 return std::nullopt;
790 }
791 }
792
Ed Tanous14766872022-03-15 10:44:42 -0700793 nlohmann::json::object_t report;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700794 report["@odata.id"] = boost::urls::format(
795 "/redfish/v1/TelemetryService/MetricReportDefinitions/{}",
796 reportId);
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500797 reports.emplace_back(std::move(report));
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200798 }
799
Szymon Dompke3f215c92022-02-22 13:58:00 +0100800 return {std::move(reports)};
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200801}
802
803inline std::vector<std::string>
804 getMetricProperties(const TriggerSensorsParams& sensors)
805{
806 std::vector<std::string> metricProperties;
807 metricProperties.reserve(sensors.size());
808 for (const auto& [_, metadata] : sensors)
809 {
810 metricProperties.emplace_back(metadata);
811 }
812
813 return metricProperties;
814}
815
Ed Tanouse3648032024-10-16 18:06:39 -0700816inline bool fillTrigger(nlohmann::json& json, const std::string& id,
817 const dbus::utility::DBusPropertiesMap& properties)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200818{
819 const std::string* name = nullptr;
820 const bool* discrete = nullptr;
821 const TriggerSensorsParams* sensors = nullptr;
Szymon Dompke3f215c92022-02-22 13:58:00 +0100822 const std::vector<sdbusplus::message::object_path>* reports = nullptr;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200823 const std::vector<std::string>* triggerActions = nullptr;
Ed Tanous58c71482024-10-19 14:35:07 -0700824
825 const std::vector<DiscreteThresholdParams>* discreteThresholds = nullptr;
826 const std::vector<NumericThresholdParams>* numericThresholds = nullptr;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200827
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200828 const bool success = sdbusplus::unpackPropertiesNoThrow(
829 dbus_utils::UnpackErrorPrinter(), properties, "Name", name, "Discrete",
830 discrete, "Sensors", sensors, "Reports", reports, "TriggerActions",
Ed Tanous58c71482024-10-19 14:35:07 -0700831 triggerActions, "DiscreteThresholds", discreteThresholds,
832 "NumericThresholds", numericThresholds);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200833
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200834 if (!success)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200835 {
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200836 return false;
837 }
838
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200839 if (triggerActions != nullptr)
Szymon Dompke3f215c92022-02-22 13:58:00 +0100840 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100841 std::optional<nlohmann::json::array_t> redfishTriggerActions =
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200842 getTriggerActions(*triggerActions);
843 if (!redfishTriggerActions)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200844 {
Ed Tanous62598e32023-07-17 17:06:25 -0700845 BMCWEB_LOG_ERROR(
846 "Property TriggerActions is invalid in Trigger: {}", id);
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200847 return false;
848 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100849 json["TriggerActions"] = *redfishTriggerActions;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200850 }
851
852 if (reports != nullptr)
853 {
854 std::optional<nlohmann::json> linkedReports =
855 getMetricReportDefinitions(*reports);
856 if (!linkedReports)
857 {
Ed Tanous62598e32023-07-17 17:06:25 -0700858 BMCWEB_LOG_ERROR("Property Reports is invalid in Trigger: {}", id);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200859 return false;
860 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200861 json["Links"]["MetricReportDefinitions"] = *linkedReports;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200862 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200863
Ed Tanous58c71482024-10-19 14:35:07 -0700864 if (discreteThresholds != nullptr)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200865 {
Ed Tanous58c71482024-10-19 14:35:07 -0700866 std::optional<nlohmann::json::array_t> discreteTriggers =
867 getDiscreteTriggers(*discreteThresholds);
868
869 if (!discreteTriggers)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200870 {
Ed Tanous58c71482024-10-19 14:35:07 -0700871 BMCWEB_LOG_ERROR("Property Thresholds is invalid for discrete "
872 "triggers in Trigger: {}",
873 id);
874 return false;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200875 }
Ed Tanous58c71482024-10-19 14:35:07 -0700876
877 json["DiscreteTriggers"] = *discreteTriggers;
878 json["DiscreteTriggerCondition"] =
879 discreteTriggers->empty() ? "Changed" : "Specified";
880 json["MetricType"] = metric_definition::MetricType::Discrete;
881 }
882 if (numericThresholds != nullptr)
883 {
884 std::optional<nlohmann::json::object_t> jnumericThresholds =
885 getNumericThresholds(*numericThresholds);
886
887 if (!jnumericThresholds)
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200888 {
Ed Tanous58c71482024-10-19 14:35:07 -0700889 BMCWEB_LOG_ERROR("Property Thresholds is invalid for numeric "
890 "thresholds in Trigger: {}",
891 id);
892 return false;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200893 }
Ed Tanous58c71482024-10-19 14:35:07 -0700894
895 json["NumericThresholds"] = *jnumericThresholds;
896 json["MetricType"] = metric_definition::MetricType::Numeric;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200897 }
898
899 if (name != nullptr)
900 {
901 json["Name"] = *name;
902 }
903
904 if (sensors != nullptr)
905 {
906 json["MetricProperties"] = getMetricProperties(*sensors);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200907 }
908
Szymon Dompke3f215c92022-02-22 13:58:00 +0100909 json["@odata.type"] = "#Triggers.v1_2_0.Triggers";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700910 json["@odata.id"] =
911 boost::urls::format("/redfish/v1/TelemetryService/Triggers/{}", id);
Szymon Dompke3f215c92022-02-22 13:58:00 +0100912 json["Id"] = id;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200913
914 return true;
915}
916
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100917inline void handleTriggerCollectionPost(
918 App& app, const crow::Request& req,
919 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
920{
921 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
922 {
923 return;
924 }
925
926 telemetry::Context ctx;
927 if (!telemetry::parsePostTriggerParams(asyncResp->res, req, ctx))
928 {
929 return;
930 }
931
932 crow::connections::systemBus->async_method_call(
933 [asyncResp, id = ctx.id](const boost::system::error_code& ec,
934 const std::string& dbusPath) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400935 afterCreateTrigger(ec, dbusPath, asyncResp, id);
936 },
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100937 service, "/xyz/openbmc_project/Telemetry/Triggers",
938 "xyz.openbmc_project.Telemetry.TriggerManager", "AddTrigger",
939 "TelemetryService/" + ctx.id, ctx.name, ctx.actions, ctx.sensors,
Ed Tanous58c71482024-10-19 14:35:07 -0700940 ctx.reports, ctx.numericThresholds, ctx.discreteThresholds);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100941}
942
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +0200943} // namespace telemetry
944
945inline void requestRoutesTriggerCollection(App& app)
946{
947 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/")
948 .privileges(redfish::privileges::getTriggersCollection)
949 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700950 [&app](const crow::Request& req,
951 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400952 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
953 {
954 return;
955 }
956 asyncResp->res.jsonValue["@odata.type"] =
957 "#TriggersCollection.TriggersCollection";
958 asyncResp->res.jsonValue["@odata.id"] =
959 "/redfish/v1/TelemetryService/Triggers";
960 asyncResp->res.jsonValue["Name"] = "Triggers Collection";
961 constexpr std::array<std::string_view, 1> interfaces{
962 telemetry::triggerInterface};
963 collection_util::getCollectionMembers(
964 asyncResp,
965 boost::urls::url("/redfish/v1/TelemetryService/Triggers"),
966 interfaces,
967 "/xyz/openbmc_project/Telemetry/Triggers/TelemetryService");
968 });
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100969
970 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/")
971 .privileges(redfish::privileges::postTriggersCollection)
972 .methods(boost::beast::http::verb::post)(std::bind_front(
973 telemetry::handleTriggerCollectionPost, std::ref(app)));
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +0200974}
975
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200976inline void requestRoutesTrigger(App& app)
977{
978 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")
979 .privileges(redfish::privileges::getTriggers)
980 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700981 [&app](const crow::Request& req,
982 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
983 const std::string& id) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400984 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
985 {
986 return;
987 }
988 sdbusplus::asio::getAllProperties(
989 *crow::connections::systemBus, telemetry::service,
990 telemetry::getDbusTriggerPath(id),
991 telemetry::triggerInterface,
992 [asyncResp,
993 id](const boost::system::error_code& ec,
Ed Tanouse3648032024-10-16 18:06:39 -0700994 const dbus::utility::DBusPropertiesMap& ret) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400995 if (ec.value() == EBADR ||
996 ec == boost::system::errc::host_unreachable)
997 {
998 messages::resourceNotFound(asyncResp->res,
999 "Triggers", id);
1000 return;
1001 }
1002 if (ec)
1003 {
1004 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
1005 messages::internalError(asyncResp->res);
1006 return;
1007 }
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +02001008
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001009 if (!telemetry::fillTrigger(asyncResp->res.jsonValue,
1010 id, ret))
1011 {
1012 messages::internalError(asyncResp->res);
1013 }
1014 });
1015 });
Szymon Dompke163994a2021-08-12 17:30:23 +02001016
1017 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")
1018 .privileges(redfish::privileges::deleteTriggers)
1019 .methods(boost::beast::http::verb::delete_)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001020 [&app](const crow::Request& req,
1021 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1022 const std::string& id) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001023 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1024 {
1025 return;
1026 }
1027 const std::string triggerPath =
1028 telemetry::getDbusTriggerPath(id);
Szymon Dompke163994a2021-08-12 17:30:23 +02001029
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001030 crow::connections::systemBus->async_method_call(
1031 [asyncResp, id](const boost::system::error_code& ec) {
1032 if (ec.value() == EBADR)
1033 {
1034 messages::resourceNotFound(asyncResp->res,
1035 "Triggers", id);
1036 return;
1037 }
Szymon Dompke163994a2021-08-12 17:30:23 +02001038
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001039 if (ec)
1040 {
1041 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
1042 messages::internalError(asyncResp->res);
1043 return;
1044 }
Szymon Dompke163994a2021-08-12 17:30:23 +02001045
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001046 asyncResp->res.result(
1047 boost::beast::http::status::no_content);
1048 },
1049 telemetry::service, triggerPath,
1050 "xyz.openbmc_project.Object.Delete", "Delete");
1051 });
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +02001052}
1053
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +02001054} // namespace redfish