blob: 2d5fe13694a165a47ab50f99f9982fd238743bf2 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +02003#pragma once
4
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08005#include "app.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07006#include "generated/enums/metric_definition.hpp"
Szymon Dompkedd1c4a92022-03-04 13:11:38 +01007#include "generated/enums/resource.hpp"
8#include "generated/enums/triggers.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08009#include "query.hpp"
10#include "registries/privilege_registry.hpp"
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010011#include "utility.hpp"
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020012#include "utils/collection.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080013#include "utils/dbus_utils.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070014#include "utils/json_utils.hpp"
Janet Adkins1516c212024-08-14 13:22:41 -050015#include "utils/sensor_utils.hpp"
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020016#include "utils/telemetry_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080017#include "utils/time_utils.hpp"
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020018
Ed Tanousef4c65b2023-04-24 15:28:50 -070019#include <boost/url/format.hpp>
Krzysztof Grobelny89474492022-09-06 16:30:38 +020020#include <sdbusplus/asio/property.hpp>
21#include <sdbusplus/unpack_properties.hpp>
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020022
George Liu7a1dbc42022-12-07 16:03:22 +080023#include <array>
24#include <string_view>
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020025#include <tuple>
26#include <variant>
27#include <vector>
28
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020029namespace redfish
30{
31namespace telemetry
32{
33constexpr const char* triggerInterface =
34 "xyz.openbmc_project.Telemetry.Trigger";
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +020035
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020036using NumericThresholdParams =
37 std::tuple<std::string, uint64_t, std::string, double>;
38
39using DiscreteThresholdParams =
40 std::tuple<std::string, std::string, uint64_t, std::string>;
41
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020042using TriggerSensorsParams =
43 std::vector<std::pair<sdbusplus::message::object_path, std::string>>;
44
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010045inline triggers::TriggerActionEnum
46 toRedfishTriggerAction(std::string_view dbusValue)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020047{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010048 if (dbusValue ==
49 "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.UpdateReport")
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020050 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010051 return triggers::TriggerActionEnum::RedfishMetricReport;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020052 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010053 if (dbusValue ==
54 "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToRedfishEventLog")
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020055 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010056 return triggers::TriggerActionEnum::RedfishEvent;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020057 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010058 if (dbusValue ==
59 "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToJournal")
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020060 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010061 return triggers::TriggerActionEnum::LogToLogService;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020062 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010063 return triggers::TriggerActionEnum::Invalid;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +020064}
65
Szymon Dompkedd1c4a92022-03-04 13:11:38 +010066inline std::string toDbusTriggerAction(std::string_view redfishValue)
67{
68 if (redfishValue == "RedfishMetricReport")
69 {
70 return "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.UpdateReport";
71 }
72 if (redfishValue == "RedfishEvent")
73 {
74 return "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToRedfishEventLog";
75 }
76 if (redfishValue == "LogToLogService")
77 {
78 return "xyz.openbmc_project.Telemetry.Trigger.TriggerAction.LogToJournal";
79 }
80 return "";
81}
82
83inline std::string toDbusSeverity(std::string_view redfishValue)
84{
85 if (redfishValue == "OK")
86 {
87 return "xyz.openbmc_project.Telemetry.Trigger.Severity.OK";
88 }
89 if (redfishValue == "Warning")
90 {
91 return "xyz.openbmc_project.Telemetry.Trigger.Severity.Warning";
92 }
93 if (redfishValue == "Critical")
94 {
95 return "xyz.openbmc_project.Telemetry.Trigger.Severity.Critical";
96 }
97 return "";
98}
99
100inline resource::Health toRedfishSeverity(std::string_view dbusValue)
101{
102 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Severity.OK")
103 {
104 return resource::Health::OK;
105 }
106 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Severity.Warning")
107 {
108 return resource::Health::Warning;
109 }
110 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Severity.Critical")
111 {
112 return resource::Health::Critical;
113 }
114 return resource::Health::Invalid;
115}
116
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100117inline std::string toRedfishThresholdName(std::string_view dbusValue)
118{
119 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.UpperCritical")
120 {
121 return "UpperCritical";
122 }
123
124 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.LowerCritical")
125 {
126 return "LowerCritical";
127 }
128
129 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.UpperWarning")
130 {
131 return "UpperWarning";
132 }
133
134 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Type.LowerWarning")
135 {
136 return "LowerWarning";
137 }
138
139 return "";
140}
141
142inline std::string toDbusActivation(std::string_view redfishValue)
143{
144 if (redfishValue == "Either")
145 {
146 return "xyz.openbmc_project.Telemetry.Trigger.Direction.Either";
147 }
148
149 if (redfishValue == "Decreasing")
150 {
151 return "xyz.openbmc_project.Telemetry.Trigger.Direction.Decreasing";
152 }
153
154 if (redfishValue == "Increasing")
155 {
156 return "xyz.openbmc_project.Telemetry.Trigger.Direction.Increasing";
157 }
158
159 return "";
160}
161
162inline triggers::ThresholdActivation
163 toRedfishActivation(std::string_view dbusValue)
164{
165 if (dbusValue == "xyz.openbmc_project.Telemetry.Trigger.Direction.Either")
166 {
167 return triggers::ThresholdActivation::Either;
168 }
169
170 if (dbusValue ==
171 "xyz.openbmc_project.Telemetry.Trigger.Direction.Decreasing")
172 {
173 return triggers::ThresholdActivation::Decreasing;
174 }
175
176 if (dbusValue ==
177 "xyz.openbmc_project.Telemetry.Trigger.Direction.Increasing")
178 {
179 return triggers::ThresholdActivation::Increasing;
180 }
181
182 return triggers::ThresholdActivation::Invalid;
183}
184
185enum class MetricType
186{
187 Discrete,
188 Numeric
189};
190
191enum class DiscreteCondition
192{
193 Specified,
194 Changed
195};
196
197struct Context
198{
199 std::string id;
200 std::string name;
201 std::vector<std::string> actions;
202 std::vector<std::pair<sdbusplus::message::object_path, std::string>>
203 sensors;
204 std::vector<sdbusplus::message::object_path> reports;
Ed Tanous58c71482024-10-19 14:35:07 -0700205 std::vector<NumericThresholdParams> numericThresholds;
206 std::vector<DiscreteThresholdParams> discreteThresholds;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100207 std::optional<DiscreteCondition> discreteCondition;
208 std::optional<MetricType> metricType;
209 std::optional<std::vector<std::string>> metricProperties;
210};
211
212inline std::optional<sdbusplus::message::object_path>
213 getReportPathFromReportDefinitionUri(const std::string& uri)
214{
Ed Tanous6fd29552023-10-04 09:40:14 -0700215 boost::system::result<boost::urls::url_view> parsed =
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100216 boost::urls::parse_relative_ref(uri);
217
218 if (!parsed)
219 {
220 return std::nullopt;
221 }
222
223 std::string id;
224 if (!crow::utility::readUrlSegments(
225 *parsed, "redfish", "v1", "TelemetryService",
226 "MetricReportDefinitions", std::ref(id)))
227 {
228 return std::nullopt;
229 }
230
231 return sdbusplus::message::object_path(
232 "/xyz/openbmc_project/Telemetry/Reports") /
233 "TelemetryService" / id;
234}
235
236inline std::optional<MetricType> getMetricType(const std::string& metricType)
237{
238 if (metricType == "Discrete")
239 {
240 return MetricType::Discrete;
241 }
242 if (metricType == "Numeric")
243 {
244 return MetricType::Numeric;
245 }
246 return std::nullopt;
247}
248
249inline std::optional<DiscreteCondition>
250 getDiscreteCondition(const std::string& discreteTriggerCondition)
251{
252 if (discreteTriggerCondition == "Specified")
253 {
254 return DiscreteCondition::Specified;
255 }
256 if (discreteTriggerCondition == "Changed")
257 {
258 return DiscreteCondition::Changed;
259 }
260 return std::nullopt;
261}
262
Ed Tanous2932dcb2024-03-06 12:04:47 -0800263inline bool parseThreshold(crow::Response& res,
264 nlohmann::json::object_t& threshold,
265 std::string_view dbusThresholdName,
266 std::vector<NumericThresholdParams>& parsedParams)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100267{
Ed Tanous2932dcb2024-03-06 12:04:47 -0800268 double reading = 0.0;
269 std::string activation;
270 std::string dwellTimeStr;
271
Myung Baeafc474a2024-10-09 00:53:29 -0700272 if (!json_util::readJsonObject( //
273 threshold, res, //
274 "Activation", activation, //
275 "DwellTime", dwellTimeStr, //
276 "Reading", reading //
277 ))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100278 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100279 return false;
280 }
281
Ed Tanous2932dcb2024-03-06 12:04:47 -0800282 std::string dbusActivation = toDbusActivation(activation);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100283
Ed Tanous2932dcb2024-03-06 12:04:47 -0800284 if (dbusActivation.empty())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100285 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800286 messages::propertyValueIncorrect(res, "Activation", activation);
287 return false;
288 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100289
Ed Tanous2932dcb2024-03-06 12:04:47 -0800290 std::optional<std::chrono::milliseconds> dwellTime =
291 time_utils::fromDurationString(dwellTimeStr);
292 if (!dwellTime)
293 {
294 messages::propertyValueIncorrect(res, "DwellTime", dwellTimeStr);
295 return false;
296 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100297
Ed Tanous2932dcb2024-03-06 12:04:47 -0800298 parsedParams.emplace_back(dbusThresholdName,
299 static_cast<uint64_t>(dwellTime->count()),
300 dbusActivation, reading);
301 return true;
302}
303
304struct NumericThresholds
305{
306 std::optional<nlohmann::json::object_t> upperCritical;
307 std::optional<nlohmann::json::object_t> upperWarning;
308 std::optional<nlohmann::json::object_t> lowerWarning;
309 std::optional<nlohmann::json::object_t> lowerCritical;
310
311 bool any() const
312 {
313 return upperCritical || upperWarning || lowerWarning || lowerCritical;
314 }
315};
316
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400317inline bool parseNumericThresholds(
318 crow::Response& res, NumericThresholds& numericThresholds, Context& ctx)
Ed Tanous2932dcb2024-03-06 12:04:47 -0800319{
320 std::vector<NumericThresholdParams> parsedParams;
321 if (numericThresholds.upperCritical)
322 {
323 if (!parseThreshold(
324 res, *numericThresholds.upperCritical,
325 "xyz.openbmc_project.Telemetry.Trigger.Type.UpperCritical",
326 parsedParams))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100327 {
328 return false;
329 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800330 }
331 if (numericThresholds.upperWarning)
332 {
333 if (!parseThreshold(
334 res, *numericThresholds.upperWarning,
335 "xyz.openbmc_project.Telemetry.Trigger.Type.UpperWarning",
336 parsedParams))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100337 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100338 return false;
339 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800340 }
341 if (numericThresholds.lowerWarning)
342 {
343 if (!parseThreshold(
344 res, *numericThresholds.lowerWarning,
345 "xyz.openbmc_project.Telemetry.Trigger.Type.LowerWarning",
346 parsedParams))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100347 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100348 return false;
349 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800350 }
351 if (numericThresholds.lowerCritical)
352 {
353 if (!parseThreshold(
354 res, *numericThresholds.lowerCritical,
355 "xyz.openbmc_project.Telemetry.Trigger.Type.LowerCritical",
356 parsedParams))
357 {
358 return false;
359 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100360 }
361
Ed Tanous58c71482024-10-19 14:35:07 -0700362 ctx.numericThresholds = std::move(parsedParams);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100363 return true;
364}
365
366inline bool parseDiscreteTriggers(
367 crow::Response& res,
Ed Tanous2932dcb2024-03-06 12:04:47 -0800368 std::optional<std::vector<nlohmann::json::object_t>>& discreteTriggers,
369 Context& ctx)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100370{
371 std::vector<DiscreteThresholdParams> parsedParams;
372 if (!discreteTriggers)
373 {
Ed Tanous58c71482024-10-19 14:35:07 -0700374 ctx.discreteThresholds = std::move(parsedParams);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100375 return true;
376 }
377
378 parsedParams.reserve(discreteTriggers->size());
Ed Tanous2932dcb2024-03-06 12:04:47 -0800379 for (nlohmann::json::object_t& thresholdInfo : *discreteTriggers)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100380 {
381 std::optional<std::string> name = "";
382 std::string value;
383 std::string dwellTimeStr;
384 std::string severity;
385
Myung Baeafc474a2024-10-09 00:53:29 -0700386 if (!json_util::readJsonObject( //
387 thresholdInfo, res, //
388 "DwellTime", dwellTimeStr, //
389 "Name", name, //
390 "Severity", severity, //
391 "Value", value //
392 ))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100393 {
394 return false;
395 }
396
397 std::optional<std::chrono::milliseconds> dwellTime =
398 time_utils::fromDurationString(dwellTimeStr);
399 if (!dwellTime)
400 {
401 messages::propertyValueIncorrect(res, "DwellTime", dwellTimeStr);
402 return false;
403 }
404
405 std::string dbusSeverity = toDbusSeverity(severity);
406 if (dbusSeverity.empty())
407 {
408 messages::propertyValueIncorrect(res, "Severity", severity);
409 return false;
410 }
411
412 parsedParams.emplace_back(*name, dbusSeverity,
413 static_cast<uint64_t>(dwellTime->count()),
414 value);
415 }
416
Ed Tanous58c71482024-10-19 14:35:07 -0700417 ctx.discreteThresholds = std::move(parsedParams);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100418 return true;
419}
420
421inline bool parseTriggerThresholds(
422 crow::Response& res,
Ed Tanous2932dcb2024-03-06 12:04:47 -0800423 std::optional<std::vector<nlohmann::json::object_t>>& discreteTriggers,
424 NumericThresholds& numericThresholds, Context& ctx)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100425{
Ed Tanous2932dcb2024-03-06 12:04:47 -0800426 if (discreteTriggers && numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100427 {
428 messages::propertyValueConflict(res, "DiscreteTriggers",
429 "NumericThresholds");
430 messages::propertyValueConflict(res, "NumericThresholds",
431 "DiscreteTriggers");
432 return false;
433 }
434
435 if (ctx.discreteCondition)
436 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800437 if (numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100438 {
439 messages::propertyValueConflict(res, "DiscreteTriggerCondition",
440 "NumericThresholds");
441 messages::propertyValueConflict(res, "NumericThresholds",
442 "DiscreteTriggerCondition");
443 return false;
444 }
445 }
446
447 if (ctx.metricType)
448 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800449 if (*ctx.metricType == MetricType::Discrete && numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100450 {
451 messages::propertyValueConflict(res, "NumericThresholds",
452 "MetricType");
453 return false;
454 }
455 if (*ctx.metricType == MetricType::Numeric && discreteTriggers)
456 {
457 messages::propertyValueConflict(res, "DiscreteTriggers",
458 "MetricType");
459 return false;
460 }
461 if (*ctx.metricType == MetricType::Numeric && ctx.discreteCondition)
462 {
463 messages::propertyValueConflict(res, "DiscreteTriggers",
464 "DiscreteTriggerCondition");
465 return false;
466 }
467 }
468
469 if (discreteTriggers || ctx.discreteCondition ||
470 (ctx.metricType && *ctx.metricType == MetricType::Discrete))
471 {
472 if (ctx.discreteCondition)
473 {
474 if (*ctx.discreteCondition == DiscreteCondition::Specified &&
475 !discreteTriggers)
476 {
477 messages::createFailedMissingReqProperties(res,
478 "DiscreteTriggers");
479 return false;
480 }
481 if (discreteTriggers &&
482 ((*ctx.discreteCondition == DiscreteCondition::Specified &&
483 discreteTriggers->empty()) ||
484 (*ctx.discreteCondition == DiscreteCondition::Changed &&
485 !discreteTriggers->empty())))
486 {
487 messages::propertyValueConflict(res, "DiscreteTriggers",
488 "DiscreteTriggerCondition");
489 return false;
490 }
491 }
492 if (!parseDiscreteTriggers(res, discreteTriggers, ctx))
493 {
494 return false;
495 }
496 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800497 else if (numericThresholds.any())
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100498 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800499 if (!parseNumericThresholds(res, numericThresholds, ctx))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100500 {
501 return false;
502 }
503 }
504 else
505 {
506 messages::createFailedMissingReqProperties(
507 res, "'DiscreteTriggers', 'NumericThresholds', "
508 "'DiscreteTriggerCondition' or 'MetricType'");
509 return false;
510 }
511 return true;
512}
513
Ed Tanous2932dcb2024-03-06 12:04:47 -0800514inline bool parseLinks(crow::Response& res,
515 const std::vector<std::string>& metricReportDefinitions,
516 Context& ctx)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100517{
Ed Tanous2932dcb2024-03-06 12:04:47 -0800518 ctx.reports.reserve(metricReportDefinitions.size());
519 for (const std::string& reportDefinionUri : metricReportDefinitions)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100520 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800521 std::optional<sdbusplus::message::object_path> reportPath =
522 getReportPathFromReportDefinitionUri(reportDefinionUri);
523 if (!reportPath)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100524 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800525 messages::propertyValueIncorrect(res, "MetricReportDefinitions",
526 reportDefinionUri);
527 return false;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100528 }
Ed Tanous2932dcb2024-03-06 12:04:47 -0800529 ctx.reports.emplace_back(*reportPath);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100530 }
531 return true;
532}
533
534inline bool parseMetricProperties(crow::Response& res, Context& ctx)
535{
536 if (!ctx.metricProperties)
537 {
538 return true;
539 }
540
541 ctx.sensors.reserve(ctx.metricProperties->size());
542
543 size_t uriIdx = 0;
544 for (const std::string& uriStr : *ctx.metricProperties)
545 {
Ed Tanous4a7fbef2024-04-06 16:03:49 -0700546 boost::system::result<boost::urls::url> uri =
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100547 boost::urls::parse_relative_ref(uriStr);
548 if (!uri)
549 {
550 messages::propertyValueIncorrect(
551 res, "MetricProperties/" + std::to_string(uriIdx), uriStr);
552 return false;
553 }
554 std::string chassisName;
555 std::string sensorName;
556 if (!crow::utility::readUrlSegments(*uri, "redfish", "v1", "Chassis",
557 std::ref(chassisName), "Sensors",
558 std::ref(sensorName)))
559 {
560 messages::propertyValueIncorrect(
561 res, "MetricProperties/" + std::to_string(uriIdx), uriStr);
562 return false;
563 }
564
565 std::pair<std::string, std::string> split =
Janet Adkins1516c212024-08-14 13:22:41 -0500566 redfish::sensor_utils::splitSensorNameAndType(sensorName);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100567 if (split.first.empty() || split.second.empty())
568 {
569 messages::propertyValueIncorrect(
570 res, "MetricProperties/" + std::to_string(uriIdx), uriStr);
571 return false;
572 }
573
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400574 std::string sensorPath =
575 "/xyz/openbmc_project/sensors/" + split.first + '/' + split.second;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100576
577 ctx.sensors.emplace_back(sensorPath, uriStr);
578 uriIdx++;
579 }
580 return true;
581}
582
583inline bool parsePostTriggerParams(crow::Response& res,
584 const crow::Request& req, Context& ctx)
585{
586 std::optional<std::string> id = "";
587 std::optional<std::string> name = "";
588 std::optional<std::string> metricType;
589 std::optional<std::vector<std::string>> triggerActions;
590 std::optional<std::string> discreteTriggerCondition;
Ed Tanous2932dcb2024-03-06 12:04:47 -0800591 std::optional<std::vector<nlohmann::json::object_t>> discreteTriggers;
592 std::optional<std::vector<std::string>> metricReportDefinitions;
593 NumericThresholds thresholds;
Myung Baeafc474a2024-10-09 00:53:29 -0700594
595 if (!json_util::readJsonPatch( //
596 req, res, //
597 "Id", id, //
598 "DiscreteTriggerCondition", discreteTriggerCondition, //
599 "DiscreteTriggers", discreteTriggers, //
600 "Links/MetricReportDefinitions", metricReportDefinitions, //
601 "MetricProperties", ctx.metricProperties, //
602 "MetricType", metricType, //
603 "Name", name, //
604 "NumericThresholds/LowerCritical", thresholds.lowerCritical, //
605 "NumericThresholds/LowerWarning", thresholds.lowerWarning, //
606 "NumericThresholds/UpperCritical", thresholds.upperCritical, //
607 "NumericThresholds/UpperWarning", thresholds.upperWarning, //
608 "TriggerActions", triggerActions //
609 ))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100610 {
611 return false;
612 }
613
614 ctx.id = *id;
615 ctx.name = *name;
616
617 if (metricType)
618 {
Ed Tanousd5736ef2023-07-06 10:37:23 -0700619 ctx.metricType = getMetricType(*metricType);
620 if (!ctx.metricType)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100621 {
622 messages::propertyValueIncorrect(res, "MetricType", *metricType);
623 return false;
624 }
625 }
626
627 if (discreteTriggerCondition)
628 {
Ed Tanousd5736ef2023-07-06 10:37:23 -0700629 ctx.discreteCondition = getDiscreteCondition(*discreteTriggerCondition);
630 if (!ctx.discreteCondition)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100631 {
632 messages::propertyValueIncorrect(res, "DiscreteTriggerCondition",
633 *discreteTriggerCondition);
634 return false;
635 }
636 }
637
638 if (triggerActions)
639 {
640 ctx.actions.reserve(triggerActions->size());
641 for (const std::string& action : *triggerActions)
642 {
643 std::string dbusAction = toDbusTriggerAction(action);
644
645 if (dbusAction.empty())
646 {
647 messages::propertyValueNotInList(res, action, "TriggerActions");
648 return false;
649 }
650
651 ctx.actions.emplace_back(dbusAction);
652 }
653 }
654 if (!parseMetricProperties(res, ctx))
655 {
656 return false;
657 }
658
Ed Tanous2932dcb2024-03-06 12:04:47 -0800659 if (!parseTriggerThresholds(res, discreteTriggers, thresholds, ctx))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100660 {
661 return false;
662 }
663
Ed Tanous2932dcb2024-03-06 12:04:47 -0800664 if (metricReportDefinitions)
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100665 {
Ed Tanous2932dcb2024-03-06 12:04:47 -0800666 if (!parseLinks(res, *metricReportDefinitions, ctx))
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100667 {
668 return false;
669 }
670 }
671 return true;
672}
673
674inline void afterCreateTrigger(
675 const boost::system::error_code& ec, const std::string& dbusPath,
676 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
677{
678 if (ec == boost::system::errc::file_exists)
679 {
680 messages::resourceAlreadyExists(asyncResp->res, "Trigger", "Id", id);
681 return;
682 }
683 if (ec == boost::system::errc::too_many_files_open)
684 {
685 messages::createLimitReachedForResource(asyncResp->res);
686 return;
687 }
688 if (ec)
689 {
690 messages::internalError(asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -0700691 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100692 return;
693 }
694
695 const std::optional<std::string>& triggerId =
696 getTriggerIdFromDbusPath(dbusPath);
697 if (!triggerId)
698 {
699 messages::internalError(asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -0700700 BMCWEB_LOG_ERROR("Unknown data returned by "
701 "AddTrigger DBus method");
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100702 return;
703 }
704
705 messages::created(asyncResp->res);
706 boost::urls::url locationUrl = boost::urls::format(
707 "/redfish/v1/TelemetryService/Triggers/{}", *triggerId);
708 asyncResp->res.addHeader("Location", locationUrl.buffer());
709}
710
711inline std::optional<nlohmann::json::array_t>
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200712 getTriggerActions(const std::vector<std::string>& dbusActions)
713{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100714 nlohmann::json::array_t triggerActions;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200715 for (const std::string& dbusAction : dbusActions)
716 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100717 triggers::TriggerActionEnum redfishAction =
718 toRedfishTriggerAction(dbusAction);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200719
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100720 if (redfishAction == triggers::TriggerActionEnum::Invalid)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200721 {
722 return std::nullopt;
723 }
724
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100725 triggerActions.emplace_back(redfishAction);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200726 }
727
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100728 return triggerActions;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200729}
730
Ed Tanous58c71482024-10-19 14:35:07 -0700731inline std::optional<nlohmann::json::array_t> getDiscreteTriggers(
732 const std::vector<DiscreteThresholdParams>& discreteParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200733{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100734 nlohmann::json::array_t triggers;
Ed Tanous58c71482024-10-19 14:35:07 -0700735 for (const auto& [name, severity, dwellTime, value] : discreteParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200736 {
737 std::optional<std::string> duration =
738 time_utils::toDurationStringFromUint(dwellTime);
739
740 if (!duration)
741 {
742 return std::nullopt;
743 }
Ed Tanous613dabe2022-07-09 11:17:36 -0700744 nlohmann::json::object_t trigger;
745 trigger["Name"] = name;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100746 trigger["Severity"] = toRedfishSeverity(severity);
Ed Tanous613dabe2022-07-09 11:17:36 -0700747 trigger["DwellTime"] = *duration;
748 trigger["Value"] = value;
Patrick Williamsad539542023-05-12 10:10:08 -0500749 triggers.emplace_back(std::move(trigger));
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200750 }
751
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100752 return triggers;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200753}
754
Ed Tanous58c71482024-10-19 14:35:07 -0700755inline std::optional<nlohmann::json::object_t> getNumericThresholds(
756 const std::vector<NumericThresholdParams>& numericParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200757{
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100758 nlohmann::json::object_t thresholds;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200759
Ed Tanous58c71482024-10-19 14:35:07 -0700760 for (const auto& [type, dwellTime, activation, reading] : numericParams)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200761 {
762 std::optional<std::string> duration =
763 time_utils::toDurationStringFromUint(dwellTime);
764
765 if (!duration)
766 {
767 return std::nullopt;
768 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100769 nlohmann::json& threshold = thresholds[toRedfishThresholdName(type)];
Ed Tanous14766872022-03-15 10:44:42 -0700770 threshold["Reading"] = reading;
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100771 threshold["Activation"] = toRedfishActivation(activation);
Ed Tanous14766872022-03-15 10:44:42 -0700772 threshold["DwellTime"] = *duration;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200773 }
774
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100775 return thresholds;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200776}
777
Szymon Dompke3f215c92022-02-22 13:58:00 +0100778inline std::optional<nlohmann::json> getMetricReportDefinitions(
779 const std::vector<sdbusplus::message::object_path>& reportPaths)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200780{
781 nlohmann::json reports = nlohmann::json::array();
Szymon Dompke3f215c92022-02-22 13:58:00 +0100782
783 for (const sdbusplus::message::object_path& path : reportPaths)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200784 {
Szymon Dompke3f215c92022-02-22 13:58:00 +0100785 std::string reportId = path.filename();
786 if (reportId.empty())
787 {
788 {
Ed Tanous62598e32023-07-17 17:06:25 -0700789 BMCWEB_LOG_ERROR("Property Reports contains invalid value: {}",
790 path.str);
Szymon Dompke3f215c92022-02-22 13:58:00 +0100791 return std::nullopt;
792 }
793 }
794
Ed Tanous14766872022-03-15 10:44:42 -0700795 nlohmann::json::object_t report;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700796 report["@odata.id"] = boost::urls::format(
797 "/redfish/v1/TelemetryService/MetricReportDefinitions/{}",
798 reportId);
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500799 reports.emplace_back(std::move(report));
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200800 }
801
Szymon Dompke3f215c92022-02-22 13:58:00 +0100802 return {std::move(reports)};
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200803}
804
805inline std::vector<std::string>
806 getMetricProperties(const TriggerSensorsParams& sensors)
807{
808 std::vector<std::string> metricProperties;
809 metricProperties.reserve(sensors.size());
810 for (const auto& [_, metadata] : sensors)
811 {
812 metricProperties.emplace_back(metadata);
813 }
814
815 return metricProperties;
816}
817
Ed Tanouse3648032024-10-16 18:06:39 -0700818inline bool fillTrigger(nlohmann::json& json, const std::string& id,
819 const dbus::utility::DBusPropertiesMap& properties)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200820{
821 const std::string* name = nullptr;
822 const bool* discrete = nullptr;
823 const TriggerSensorsParams* sensors = nullptr;
Szymon Dompke3f215c92022-02-22 13:58:00 +0100824 const std::vector<sdbusplus::message::object_path>* reports = nullptr;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200825 const std::vector<std::string>* triggerActions = nullptr;
Ed Tanous58c71482024-10-19 14:35:07 -0700826
827 const std::vector<DiscreteThresholdParams>* discreteThresholds = nullptr;
828 const std::vector<NumericThresholdParams>* numericThresholds = nullptr;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200829
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200830 const bool success = sdbusplus::unpackPropertiesNoThrow(
831 dbus_utils::UnpackErrorPrinter(), properties, "Name", name, "Discrete",
832 discrete, "Sensors", sensors, "Reports", reports, "TriggerActions",
Ed Tanous58c71482024-10-19 14:35:07 -0700833 triggerActions, "DiscreteThresholds", discreteThresholds,
834 "NumericThresholds", numericThresholds);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200835
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200836 if (!success)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200837 {
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200838 return false;
839 }
840
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200841 if (triggerActions != nullptr)
Szymon Dompke3f215c92022-02-22 13:58:00 +0100842 {
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100843 std::optional<nlohmann::json::array_t> redfishTriggerActions =
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200844 getTriggerActions(*triggerActions);
845 if (!redfishTriggerActions)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200846 {
Ed Tanous62598e32023-07-17 17:06:25 -0700847 BMCWEB_LOG_ERROR(
848 "Property TriggerActions is invalid in Trigger: {}", id);
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200849 return false;
850 }
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100851 json["TriggerActions"] = *redfishTriggerActions;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200852 }
853
854 if (reports != nullptr)
855 {
856 std::optional<nlohmann::json> linkedReports =
857 getMetricReportDefinitions(*reports);
858 if (!linkedReports)
859 {
Ed Tanous62598e32023-07-17 17:06:25 -0700860 BMCWEB_LOG_ERROR("Property Reports is invalid in Trigger: {}", id);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200861 return false;
862 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200863 json["Links"]["MetricReportDefinitions"] = *linkedReports;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200864 }
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200865
Ed Tanous58c71482024-10-19 14:35:07 -0700866 if (discreteThresholds != nullptr)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200867 {
Ed Tanous58c71482024-10-19 14:35:07 -0700868 std::optional<nlohmann::json::array_t> discreteTriggers =
869 getDiscreteTriggers(*discreteThresholds);
870
871 if (!discreteTriggers)
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200872 {
Ed Tanous58c71482024-10-19 14:35:07 -0700873 BMCWEB_LOG_ERROR("Property Thresholds is invalid for discrete "
874 "triggers in Trigger: {}",
875 id);
876 return false;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200877 }
Ed Tanous58c71482024-10-19 14:35:07 -0700878
879 json["DiscreteTriggers"] = *discreteTriggers;
880 json["DiscreteTriggerCondition"] =
881 discreteTriggers->empty() ? "Changed" : "Specified";
882 json["MetricType"] = metric_definition::MetricType::Discrete;
883 }
884 if (numericThresholds != nullptr)
885 {
886 std::optional<nlohmann::json::object_t> jnumericThresholds =
887 getNumericThresholds(*numericThresholds);
888
889 if (!jnumericThresholds)
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200890 {
Ed Tanous58c71482024-10-19 14:35:07 -0700891 BMCWEB_LOG_ERROR("Property Thresholds is invalid for numeric "
892 "thresholds in Trigger: {}",
893 id);
894 return false;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200895 }
Ed Tanous58c71482024-10-19 14:35:07 -0700896
897 json["NumericThresholds"] = *jnumericThresholds;
898 json["MetricType"] = metric_definition::MetricType::Numeric;
Krzysztof Grobelny89474492022-09-06 16:30:38 +0200899 }
900
901 if (name != nullptr)
902 {
903 json["Name"] = *name;
904 }
905
906 if (sensors != nullptr)
907 {
908 json["MetricProperties"] = getMetricProperties(*sensors);
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200909 }
910
Szymon Dompke3f215c92022-02-22 13:58:00 +0100911 json["@odata.type"] = "#Triggers.v1_2_0.Triggers";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700912 json["@odata.id"] =
913 boost::urls::format("/redfish/v1/TelemetryService/Triggers/{}", id);
Szymon Dompke3f215c92022-02-22 13:58:00 +0100914 json["Id"] = id;
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200915
916 return true;
917}
918
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100919inline void handleTriggerCollectionPost(
920 App& app, const crow::Request& req,
921 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
922{
923 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
924 {
925 return;
926 }
927
928 telemetry::Context ctx;
929 if (!telemetry::parsePostTriggerParams(asyncResp->res, req, ctx))
930 {
931 return;
932 }
933
934 crow::connections::systemBus->async_method_call(
935 [asyncResp, id = ctx.id](const boost::system::error_code& ec,
936 const std::string& dbusPath) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400937 afterCreateTrigger(ec, dbusPath, asyncResp, id);
938 },
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100939 service, "/xyz/openbmc_project/Telemetry/Triggers",
940 "xyz.openbmc_project.Telemetry.TriggerManager", "AddTrigger",
941 "TelemetryService/" + ctx.id, ctx.name, ctx.actions, ctx.sensors,
Ed Tanous58c71482024-10-19 14:35:07 -0700942 ctx.reports, ctx.numericThresholds, ctx.discreteThresholds);
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100943}
944
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +0200945} // namespace telemetry
946
947inline void requestRoutesTriggerCollection(App& app)
948{
949 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/")
950 .privileges(redfish::privileges::getTriggersCollection)
951 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700952 [&app](const crow::Request& req,
953 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400954 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
955 {
956 return;
957 }
958 asyncResp->res.jsonValue["@odata.type"] =
959 "#TriggersCollection.TriggersCollection";
960 asyncResp->res.jsonValue["@odata.id"] =
961 "/redfish/v1/TelemetryService/Triggers";
962 asyncResp->res.jsonValue["Name"] = "Triggers Collection";
963 constexpr std::array<std::string_view, 1> interfaces{
964 telemetry::triggerInterface};
965 collection_util::getCollectionMembers(
966 asyncResp,
967 boost::urls::url("/redfish/v1/TelemetryService/Triggers"),
968 interfaces,
969 "/xyz/openbmc_project/Telemetry/Triggers/TelemetryService");
970 });
Szymon Dompkedd1c4a92022-03-04 13:11:38 +0100971
972 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/")
973 .privileges(redfish::privileges::postTriggersCollection)
974 .methods(boost::beast::http::verb::post)(std::bind_front(
975 telemetry::handleTriggerCollectionPost, std::ref(app)));
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +0200976}
977
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200978inline void requestRoutesTrigger(App& app)
979{
980 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")
981 .privileges(redfish::privileges::getTriggers)
982 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700983 [&app](const crow::Request& req,
984 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
985 const std::string& id) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400986 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
987 {
988 return;
989 }
990 sdbusplus::asio::getAllProperties(
991 *crow::connections::systemBus, telemetry::service,
992 telemetry::getDbusTriggerPath(id),
993 telemetry::triggerInterface,
994 [asyncResp,
995 id](const boost::system::error_code& ec,
Ed Tanouse3648032024-10-16 18:06:39 -0700996 const dbus::utility::DBusPropertiesMap& ret) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400997 if (ec.value() == EBADR ||
998 ec == boost::system::errc::host_unreachable)
999 {
1000 messages::resourceNotFound(asyncResp->res,
1001 "Triggers", id);
1002 return;
1003 }
1004 if (ec)
1005 {
1006 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
1007 messages::internalError(asyncResp->res);
1008 return;
1009 }
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +02001010
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001011 if (!telemetry::fillTrigger(asyncResp->res.jsonValue,
1012 id, ret))
1013 {
1014 messages::internalError(asyncResp->res);
1015 }
1016 });
1017 });
Szymon Dompke163994a2021-08-12 17:30:23 +02001018
1019 BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/")
1020 .privileges(redfish::privileges::deleteTriggers)
1021 .methods(boost::beast::http::verb::delete_)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07001022 [&app](const crow::Request& req,
1023 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1024 const std::string& id) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001025 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1026 {
1027 return;
1028 }
1029 const std::string triggerPath =
1030 telemetry::getDbusTriggerPath(id);
Szymon Dompke163994a2021-08-12 17:30:23 +02001031
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001032 crow::connections::systemBus->async_method_call(
1033 [asyncResp, id](const boost::system::error_code& ec) {
1034 if (ec.value() == EBADR)
1035 {
1036 messages::resourceNotFound(asyncResp->res,
1037 "Triggers", id);
1038 return;
1039 }
Szymon Dompke163994a2021-08-12 17:30:23 +02001040
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001041 if (ec)
1042 {
1043 BMCWEB_LOG_ERROR("respHandler DBus error {}", ec);
1044 messages::internalError(asyncResp->res);
1045 return;
1046 }
Szymon Dompke163994a2021-08-12 17:30:23 +02001047
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001048 asyncResp->res.result(
1049 boost::beast::http::status::no_content);
1050 },
1051 telemetry::service, triggerPath,
1052 "xyz.openbmc_project.Object.Delete", "Delete");
1053 });
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +02001054}
1055
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +02001056} // namespace redfish