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