Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "utils/collection.hpp" |
| 4 | #include "utils/telemetry_utils.hpp" |
| 5 | |
| 6 | #include <app.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 7 | #include <query.hpp> |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 8 | #include <registries/privilege_registry.hpp> |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 9 | #include <sdbusplus/asio/property.hpp> |
| 10 | #include <sdbusplus/unpack_properties.hpp> |
| 11 | #include <utils/dbus_utils.hpp> |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 12 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 13 | #include <array> |
| 14 | #include <string_view> |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 15 | #include <tuple> |
| 16 | #include <variant> |
| 17 | #include <vector> |
| 18 | |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 19 | namespace redfish |
| 20 | { |
| 21 | namespace telemetry |
| 22 | { |
| 23 | constexpr const char* triggerInterface = |
| 24 | "xyz.openbmc_project.Telemetry.Trigger"; |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 25 | |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 26 | using NumericThresholdParams = |
| 27 | std::tuple<std::string, uint64_t, std::string, double>; |
| 28 | |
| 29 | using DiscreteThresholdParams = |
| 30 | std::tuple<std::string, std::string, uint64_t, std::string>; |
| 31 | |
| 32 | using TriggerThresholdParamsExt = |
| 33 | std::variant<std::monostate, std::vector<NumericThresholdParams>, |
| 34 | std::vector<DiscreteThresholdParams>>; |
| 35 | |
| 36 | using TriggerSensorsParams = |
| 37 | std::vector<std::pair<sdbusplus::message::object_path, std::string>>; |
| 38 | |
| 39 | using TriggerGetParamsVariant = |
| 40 | std::variant<std::monostate, bool, std::string, TriggerThresholdParamsExt, |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 41 | TriggerSensorsParams, std::vector<std::string>, |
| 42 | std::vector<sdbusplus::message::object_path>>; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 43 | |
| 44 | inline std::optional<std::string> |
| 45 | getRedfishFromDbusAction(const std::string& dbusAction) |
| 46 | { |
| 47 | std::optional<std::string> redfishAction = std::nullopt; |
| 48 | if (dbusAction == "UpdateReport") |
| 49 | { |
| 50 | redfishAction = "RedfishMetricReport"; |
| 51 | } |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 52 | if (dbusAction == "LogToRedfishEventLog") |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 53 | { |
| 54 | redfishAction = "RedfishEvent"; |
| 55 | } |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 56 | if (dbusAction == "LogToJournal") |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 57 | { |
| 58 | redfishAction = "LogToLogService"; |
| 59 | } |
| 60 | return redfishAction; |
| 61 | } |
| 62 | |
| 63 | inline std::optional<std::vector<std::string>> |
| 64 | getTriggerActions(const std::vector<std::string>& dbusActions) |
| 65 | { |
| 66 | std::vector<std::string> triggerActions; |
| 67 | for (const std::string& dbusAction : dbusActions) |
| 68 | { |
| 69 | std::optional<std::string> redfishAction = |
| 70 | getRedfishFromDbusAction(dbusAction); |
| 71 | |
| 72 | if (!redfishAction) |
| 73 | { |
| 74 | return std::nullopt; |
| 75 | } |
| 76 | |
| 77 | triggerActions.push_back(*redfishAction); |
| 78 | } |
| 79 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 80 | return {std::move(triggerActions)}; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 83 | inline std::optional<nlohmann::json::array_t> |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 84 | getDiscreteTriggers(const TriggerThresholdParamsExt& thresholdParams) |
| 85 | { |
| 86 | const std::vector<DiscreteThresholdParams>* discreteParams = |
| 87 | std::get_if<std::vector<DiscreteThresholdParams>>(&thresholdParams); |
| 88 | |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 89 | if (discreteParams == nullptr) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 90 | { |
| 91 | return std::nullopt; |
| 92 | } |
| 93 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 94 | nlohmann::json::array_t triggers; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 95 | for (const auto& [name, severity, dwellTime, value] : *discreteParams) |
| 96 | { |
| 97 | std::optional<std::string> duration = |
| 98 | time_utils::toDurationStringFromUint(dwellTime); |
| 99 | |
| 100 | if (!duration) |
| 101 | { |
| 102 | return std::nullopt; |
| 103 | } |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 104 | nlohmann::json::object_t trigger; |
| 105 | trigger["Name"] = name; |
| 106 | trigger["Severity"] = severity; |
| 107 | trigger["DwellTime"] = *duration; |
| 108 | trigger["Value"] = value; |
| 109 | triggers.push_back(std::move(trigger)); |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 112 | return {std::move(triggers)}; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | inline std::optional<nlohmann::json> |
| 116 | getNumericThresholds(const TriggerThresholdParamsExt& thresholdParams) |
| 117 | { |
| 118 | const std::vector<NumericThresholdParams>* numericParams = |
| 119 | std::get_if<std::vector<NumericThresholdParams>>(&thresholdParams); |
| 120 | |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 121 | if (numericParams == nullptr) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 122 | { |
| 123 | return std::nullopt; |
| 124 | } |
| 125 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 126 | nlohmann::json::object_t thresholds; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 127 | for (const auto& [type, dwellTime, activation, reading] : *numericParams) |
| 128 | { |
| 129 | std::optional<std::string> duration = |
| 130 | time_utils::toDurationStringFromUint(dwellTime); |
| 131 | |
| 132 | if (!duration) |
| 133 | { |
| 134 | return std::nullopt; |
| 135 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 136 | nlohmann::json& threshold = thresholds[type]; |
| 137 | threshold["Reading"] = reading; |
| 138 | threshold["Activation"] = activation; |
| 139 | threshold["DwellTime"] = *duration; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 142 | return {std::move(thresholds)}; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 145 | inline std::optional<nlohmann::json> getMetricReportDefinitions( |
| 146 | const std::vector<sdbusplus::message::object_path>& reportPaths) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 147 | { |
| 148 | nlohmann::json reports = nlohmann::json::array(); |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 149 | |
| 150 | for (const sdbusplus::message::object_path& path : reportPaths) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 151 | { |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 152 | std::string reportId = path.filename(); |
| 153 | if (reportId.empty()) |
| 154 | { |
| 155 | { |
| 156 | BMCWEB_LOG_ERROR << "Property Reports contains invalid value: " |
| 157 | << path.str; |
| 158 | return std::nullopt; |
| 159 | } |
| 160 | } |
| 161 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 162 | nlohmann::json::object_t report; |
| 163 | report["@odata.id"] = |
| 164 | crow::utility::urlFromPieces("redfish", "v1", "TelemetryService", |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 165 | "MetricReportDefinitions", reportId); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 166 | reports.push_back(std::move(report)); |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 169 | return {std::move(reports)}; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | inline std::vector<std::string> |
| 173 | getMetricProperties(const TriggerSensorsParams& sensors) |
| 174 | { |
| 175 | std::vector<std::string> metricProperties; |
| 176 | metricProperties.reserve(sensors.size()); |
| 177 | for (const auto& [_, metadata] : sensors) |
| 178 | { |
| 179 | metricProperties.emplace_back(metadata); |
| 180 | } |
| 181 | |
| 182 | return metricProperties; |
| 183 | } |
| 184 | |
| 185 | inline bool fillTrigger( |
| 186 | nlohmann::json& json, const std::string& id, |
| 187 | const std::vector<std::pair<std::string, TriggerGetParamsVariant>>& |
| 188 | properties) |
| 189 | { |
| 190 | const std::string* name = nullptr; |
| 191 | const bool* discrete = nullptr; |
| 192 | const TriggerSensorsParams* sensors = nullptr; |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 193 | const std::vector<sdbusplus::message::object_path>* reports = nullptr; |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 194 | const std::vector<std::string>* triggerActions = nullptr; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 195 | const TriggerThresholdParamsExt* thresholds = nullptr; |
| 196 | |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 197 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 198 | dbus_utils::UnpackErrorPrinter(), properties, "Name", name, "Discrete", |
| 199 | discrete, "Sensors", sensors, "Reports", reports, "TriggerActions", |
| 200 | triggerActions, "Thresholds", thresholds); |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 201 | |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 202 | if (!success) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 203 | { |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 207 | if (triggerActions != nullptr) |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 208 | { |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 209 | std::optional<std::vector<std::string>> redfishTriggerActions = |
| 210 | getTriggerActions(*triggerActions); |
| 211 | if (!redfishTriggerActions) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 212 | { |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 213 | BMCWEB_LOG_ERROR |
| 214 | << "Property TriggerActions is invalid in Trigger: " << id; |
| 215 | return false; |
| 216 | } |
| 217 | json["TriggerActions"] = *triggerActions; |
| 218 | } |
| 219 | |
| 220 | if (reports != nullptr) |
| 221 | { |
| 222 | std::optional<nlohmann::json> linkedReports = |
| 223 | getMetricReportDefinitions(*reports); |
| 224 | if (!linkedReports) |
| 225 | { |
| 226 | BMCWEB_LOG_ERROR << "Property Reports is invalid in Trigger: " |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 227 | << id; |
| 228 | return false; |
| 229 | } |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 230 | json["Links"]["MetricReportDefinitions"] = *linkedReports; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 231 | } |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 232 | |
| 233 | if (discrete != nullptr) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 234 | { |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 235 | if (*discrete) |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 236 | { |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 237 | std::optional<nlohmann::json::array_t> discreteTriggers = |
| 238 | getDiscreteTriggers(*thresholds); |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 239 | |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 240 | if (!discreteTriggers) |
| 241 | { |
| 242 | BMCWEB_LOG_ERROR |
| 243 | << "Property Thresholds is invalid for discrete " |
| 244 | "triggers in Trigger: " |
| 245 | << id; |
| 246 | return false; |
| 247 | } |
| 248 | |
| 249 | json["DiscreteTriggers"] = *discreteTriggers; |
| 250 | json["DiscreteTriggerCondition"] = |
| 251 | discreteTriggers->empty() ? "Changed" : "Specified"; |
| 252 | json["MetricType"] = "Discrete"; |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | std::optional<nlohmann::json> numericThresholds = |
| 257 | getNumericThresholds(*thresholds); |
| 258 | |
| 259 | if (!numericThresholds) |
| 260 | { |
| 261 | BMCWEB_LOG_ERROR |
| 262 | << "Property Thresholds is invalid for numeric " |
| 263 | "thresholds in Trigger: " |
| 264 | << id; |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | json["NumericThresholds"] = *numericThresholds; |
| 269 | json["MetricType"] = "Numeric"; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if (name != nullptr) |
| 274 | { |
| 275 | json["Name"] = *name; |
| 276 | } |
| 277 | |
| 278 | if (sensors != nullptr) |
| 279 | { |
| 280 | json["MetricProperties"] = getMetricProperties(*sensors); |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 281 | } |
| 282 | |
Szymon Dompke | 3f215c9 | 2022-02-22 13:58:00 +0100 | [diff] [blame] | 283 | json["@odata.type"] = "#Triggers.v1_2_0.Triggers"; |
| 284 | json["@odata.id"] = crow::utility::urlFromPieces( |
| 285 | "redfish", "v1", "TelemetryService", "Triggers", id); |
| 286 | json["Id"] = id; |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 287 | |
| 288 | return true; |
| 289 | } |
| 290 | |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 291 | } // namespace telemetry |
| 292 | |
| 293 | inline void requestRoutesTriggerCollection(App& app) |
| 294 | { |
| 295 | BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/") |
| 296 | .privileges(redfish::privileges::getTriggersCollection) |
| 297 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 298 | [&app](const crow::Request& req, |
| 299 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 300 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 301 | { |
| 302 | return; |
| 303 | } |
| 304 | asyncResp->res.jsonValue["@odata.type"] = |
| 305 | "#TriggersCollection.TriggersCollection"; |
Willy Tu | ae9031f | 2022-09-27 05:48:07 +0000 | [diff] [blame] | 306 | asyncResp->res.jsonValue["@odata.id"] = |
| 307 | "/redfish/v1/TelemetryService/Triggers"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 308 | asyncResp->res.jsonValue["Name"] = "Triggers Collection"; |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 309 | constexpr std::array<std::string_view, 1> interfaces{ |
| 310 | telemetry::triggerInterface}; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 311 | collection_util::getCollectionMembers( |
Willy Tu | ae9031f | 2022-09-27 05:48:07 +0000 | [diff] [blame] | 312 | asyncResp, |
| 313 | boost::urls::url("/redfish/v1/TelemetryService/Triggers"), |
| 314 | interfaces, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 315 | "/xyz/openbmc_project/Telemetry/Triggers/TelemetryService"); |
| 316 | }); |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 317 | } |
| 318 | |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 319 | inline void requestRoutesTrigger(App& app) |
| 320 | { |
| 321 | BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/") |
| 322 | .privileges(redfish::privileges::getTriggers) |
| 323 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 324 | [&app](const crow::Request& req, |
| 325 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 326 | const std::string& id) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 327 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 328 | { |
| 329 | return; |
| 330 | } |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 331 | sdbusplus::asio::getAllProperties( |
| 332 | *crow::connections::systemBus, telemetry::service, |
| 333 | telemetry::getDbusTriggerPath(id), telemetry::triggerInterface, |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 334 | [asyncResp, |
| 335 | id](const boost::system::error_code ec, |
| 336 | const std::vector<std::pair< |
| 337 | std::string, telemetry::TriggerGetParamsVariant>>& ret) { |
| 338 | if (ec.value() == EBADR || |
| 339 | ec == boost::system::errc::host_unreachable) |
| 340 | { |
| 341 | messages::resourceNotFound(asyncResp->res, "Triggers", id); |
| 342 | return; |
| 343 | } |
| 344 | if (ec) |
| 345 | { |
| 346 | BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; |
| 347 | messages::internalError(asyncResp->res); |
| 348 | return; |
| 349 | } |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 350 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 351 | if (!telemetry::fillTrigger(asyncResp->res.jsonValue, id, ret)) |
| 352 | { |
| 353 | messages::internalError(asyncResp->res); |
| 354 | } |
Krzysztof Grobelny | 8947449 | 2022-09-06 16:30:38 +0200 | [diff] [blame] | 355 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 356 | }); |
Szymon Dompke | 163994a | 2021-08-12 17:30:23 +0200 | [diff] [blame] | 357 | |
| 358 | BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/Triggers/<str>/") |
| 359 | .privileges(redfish::privileges::deleteTriggers) |
| 360 | .methods(boost::beast::http::verb::delete_)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 361 | [&app](const crow::Request& req, |
| 362 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 363 | const std::string& id) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 364 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 365 | { |
| 366 | return; |
| 367 | } |
| 368 | const std::string triggerPath = telemetry::getDbusTriggerPath(id); |
Szymon Dompke | 163994a | 2021-08-12 17:30:23 +0200 | [diff] [blame] | 369 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 370 | crow::connections::systemBus->async_method_call( |
| 371 | [asyncResp, id](const boost::system::error_code ec) { |
| 372 | if (ec.value() == EBADR) |
| 373 | { |
| 374 | messages::resourceNotFound(asyncResp->res, "Triggers", id); |
| 375 | return; |
| 376 | } |
Szymon Dompke | 163994a | 2021-08-12 17:30:23 +0200 | [diff] [blame] | 377 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 378 | if (ec) |
| 379 | { |
| 380 | BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; |
| 381 | messages::internalError(asyncResp->res); |
| 382 | return; |
| 383 | } |
Szymon Dompke | 163994a | 2021-08-12 17:30:23 +0200 | [diff] [blame] | 384 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 385 | asyncResp->res.result(boost::beast::http::status::no_content); |
| 386 | }, |
| 387 | telemetry::service, triggerPath, |
| 388 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 389 | }); |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 392 | } // namespace redfish |