blob: 42eb6381ba9e51159045663a05f61146098c2216 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2020 Intel Corporation
AppaRao Pulie5aaf042020-03-20 01:05:52 +05304#pragma once
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08005#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "async_resp.hpp"
7#include "dbus_singleton.hpp"
8#include "dbus_utility.hpp"
9#include "error_messages.hpp"
AppaRao Pulib52664e2020-04-09 21:36:51 +053010#include "event_service_manager.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080011#include "event_service_store.hpp"
12#include "generated/enums/event_destination.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080013#include "http/utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080014#include "http_request.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080015#include "logging.hpp"
16#include "query.hpp"
Alexander Hansend109e2b2024-11-18 14:38:06 +010017#include "registries.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "registries/privilege_registry.hpp"
Alexander Hansend109e2b2024-11-18 14:38:06 +010019#include "registries_selector.hpp"
Chicago Duan3d307082020-11-26 14:12:12 +080020#include "snmp_trap_event_clients.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080021#include "subscription.hpp"
Alexander Hansend109e2b2024-11-18 14:38:06 +010022#include "utils/json_utils.hpp"
AppaRao Pulie5aaf042020-03-20 01:05:52 +053023
Ed Tanousd7857202025-01-28 15:32:26 -080024#include <asm-generic/errno.h>
Ed Tanoused398212021-06-09 17:05:54 -070025
Ed Tanousd7857202025-01-28 15:32:26 -080026#include <boost/beast/http/fields.hpp>
27#include <boost/beast/http/status.hpp>
28#include <boost/beast/http/verb.hpp>
29#include <boost/system/error_code.hpp>
30#include <boost/system/result.hpp>
31#include <boost/url/format.hpp>
32#include <boost/url/parse.hpp>
33#include <boost/url/url.hpp>
34#include <sdbusplus/message/native_types.hpp>
35
36#include <algorithm>
37#include <array>
38#include <cerrno>
39#include <cstddef>
40#include <cstdint>
Chicago Duan3d307082020-11-26 14:12:12 +080041#include <memory>
Myung Bae5064a252024-10-04 09:34:25 -070042#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070043#include <ranges>
Patrick Williams1e270c52021-12-04 06:06:56 -060044#include <span>
Chicago Duan3d307082020-11-26 14:12:12 +080045#include <string>
Ed Tanousd7857202025-01-28 15:32:26 -080046#include <utility>
Ed Tanousa14c9112024-09-04 10:46:47 -070047#include <vector>
Patrick Williams1e270c52021-12-04 06:06:56 -060048
AppaRao Pulie5aaf042020-03-20 01:05:52 +053049namespace redfish
50{
51
AppaRao Puli156d6b02020-04-25 06:04:05 +053052static constexpr const std::array<const char*, 2> supportedEvtFormatTypes = {
53 eventFormatType, metricReportFormatType};
Myung Baefb546102024-10-29 10:21:26 -050054static constexpr const std::array<const char*, 4> supportedRegPrefixes = {
55 "Base", "OpenBMC", "TaskEvent", "HeartbeatEvent"};
AppaRao Pulie5aaf042020-03-20 01:05:52 +053056static constexpr const std::array<const char*, 3> supportedRetryPolicies = {
57 "TerminateAfterRetries", "SuspendRetries", "RetryForever"};
58
Myung Baefb546102024-10-29 10:21:26 -050059static constexpr const std::array<const char*, 2> supportedResourceTypes = {
60 "Task", "Heartbeat"};
Sunitha Harishe56f2542020-07-22 02:38:59 -050061
John Edward Broadbent7e860f12021-04-08 15:57:16 -070062inline void requestRoutesEventService(App& app)
AppaRao Pulie5aaf042020-03-20 01:05:52 +053063{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070064 BMCWEB_ROUTE(app, "/redfish/v1/EventService/")
Ed Tanoused398212021-06-09 17:05:54 -070065 .privileges(redfish::privileges::getEventService)
Patrick Williamsbd79bce2024-08-16 15:22:20 -040066 .methods(
67 boost::beast::http::verb::
68 get)([&app](
69 const crow::Request& req,
70 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
71 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
72 {
73 return;
74 }
Ed Tanous14766872022-03-15 10:44:42 -070075
Patrick Williamsbd79bce2024-08-16 15:22:20 -040076 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/EventService";
77 asyncResp->res.jsonValue["@odata.type"] =
78 "#EventService.v1_5_0.EventService";
79 asyncResp->res.jsonValue["Id"] = "EventService";
80 asyncResp->res.jsonValue["Name"] = "Event Service";
81 asyncResp->res.jsonValue["ServerSentEventUri"] =
82 "/redfish/v1/EventService/SSE";
AppaRao Puli5e44e3d2021-03-16 15:37:24 +000083
Patrick Williamsbd79bce2024-08-16 15:22:20 -040084 asyncResp->res.jsonValue["Subscriptions"]["@odata.id"] =
85 "/redfish/v1/EventService/Subscriptions";
86 asyncResp->res.jsonValue["Actions"]["#EventService.SubmitTestEvent"]
87 ["target"] =
88 "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent";
AppaRao Pulie5aaf042020-03-20 01:05:52 +053089
Patrick Williamsbd79bce2024-08-16 15:22:20 -040090 const persistent_data::EventServiceConfig eventServiceConfig =
91 persistent_data::EventServiceStore::getInstance()
92 .getEventServiceConfig();
zhanghch058d1b46d2021-04-01 11:18:24 +080093
Patrick Williamsbd79bce2024-08-16 15:22:20 -040094 asyncResp->res.jsonValue["Status"]["State"] =
95 (eventServiceConfig.enabled ? "Enabled" : "Disabled");
96 asyncResp->res.jsonValue["ServiceEnabled"] =
97 eventServiceConfig.enabled;
98 asyncResp->res.jsonValue["DeliveryRetryAttempts"] =
99 eventServiceConfig.retryAttempts;
100 asyncResp->res.jsonValue["DeliveryRetryIntervalSeconds"] =
101 eventServiceConfig.retryTimeoutInterval;
102 asyncResp->res.jsonValue["EventFormatTypes"] =
103 supportedEvtFormatTypes;
104 asyncResp->res.jsonValue["RegistryPrefixes"] = supportedRegPrefixes;
105 asyncResp->res.jsonValue["ResourceTypes"] = supportedResourceTypes;
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530106
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400107 nlohmann::json::object_t supportedSSEFilters;
108 supportedSSEFilters["EventFormatType"] = true;
109 supportedSSEFilters["MessageId"] = true;
110 supportedSSEFilters["MetricReportDefinition"] = true;
111 supportedSSEFilters["RegistryPrefix"] = true;
112 supportedSSEFilters["OriginResource"] = false;
113 supportedSSEFilters["ResourceType"] = false;
AppaRao Puli7d1cc382020-05-16 02:42:22 +0530114
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400115 asyncResp->res.jsonValue["SSEFilterPropertiesSupported"] =
116 std::move(supportedSSEFilters);
117 });
Ayushi Smriti07941a82020-05-21 15:55:34 +0530118
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700119 BMCWEB_ROUTE(app, "/redfish/v1/EventService/")
Ed Tanoused398212021-06-09 17:05:54 -0700120 .privileges(redfish::privileges::patchEventService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700121 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700122 [&app](const crow::Request& req,
123 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400124 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
125 {
126 return;
127 }
128 std::optional<bool> serviceEnabled;
129 std::optional<uint32_t> retryAttemps;
130 std::optional<uint32_t> retryInterval;
Myung Baeafc474a2024-10-09 00:53:29 -0700131 if (!json_util::readJsonPatch( //
132 req, asyncResp->res, //
133 "DeliveryRetryAttempts", retryAttemps, //
134 "DeliveryRetryIntervalSeconds", retryInterval, //
135 "ServiceEnabled", serviceEnabled //
136 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400137 {
138 return;
139 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530140
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400141 persistent_data::EventServiceConfig eventServiceConfig =
142 persistent_data::EventServiceStore::getInstance()
143 .getEventServiceConfig();
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700144
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400145 if (serviceEnabled)
146 {
147 eventServiceConfig.enabled = *serviceEnabled;
148 }
Sunitha Harishe56f2542020-07-22 02:38:59 -0500149
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400150 if (retryAttemps)
151 {
152 // Supported range [1-3]
153 if ((*retryAttemps < 1) || (*retryAttemps > 3))
154 {
155 messages::queryParameterOutOfRange(
156 asyncResp->res, std::to_string(*retryAttemps),
157 "DeliveryRetryAttempts", "[1-3]");
158 }
159 else
160 {
161 eventServiceConfig.retryAttempts = *retryAttemps;
162 }
163 }
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530164
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400165 if (retryInterval)
166 {
167 // Supported range [5 - 180]
168 if ((*retryInterval < 5) || (*retryInterval > 180))
169 {
170 messages::queryParameterOutOfRange(
171 asyncResp->res, std::to_string(*retryInterval),
172 "DeliveryRetryIntervalSeconds", "[5-180]");
173 }
174 else
175 {
176 eventServiceConfig.retryTimeoutInterval =
177 *retryInterval;
178 }
179 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700180
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400181 EventServiceManager::getInstance().setEventServiceConfig(
182 eventServiceConfig);
183 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700184}
185
186inline void requestRoutesSubmitTestEvent(App& app)
187{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700188 BMCWEB_ROUTE(
189 app, "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent/")
Ed Tanoused398212021-06-09 17:05:54 -0700190 .privileges(redfish::privileges::postEventService)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700191 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700192 [&app](const crow::Request& req,
193 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400194 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
195 {
196 return;
197 }
Chandramohan Harkude81ee0e72024-12-20 19:22:12 +0530198
199 TestEvent testEvent;
200 // clang-format off
201 if (!json_util::readJsonAction(
202 req, asyncResp->res,
203 "EventGroupId", testEvent.eventGroupId,
204 "EventId", testEvent.eventId,
205 "EventTimestamp", testEvent.eventTimestamp,
206 "Message", testEvent.message,
207 "MessageArgs", testEvent.messageArgs,
208 "MessageId", testEvent.messageId,
209 "OriginOfCondition", testEvent.originOfCondition,
210 "Resolution", testEvent.resolution,
211 "Severity", testEvent.severity))
212 {
213 return;
214 }
215 // clang-format on
216
217 if (!EventServiceManager::getInstance().sendTestEventLog(
218 testEvent))
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400219 {
220 messages::serviceDisabled(asyncResp->res,
221 "/redfish/v1/EventService/");
222 return;
223 }
224 asyncResp->res.result(boost::beast::http::status::no_content);
225 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700226}
227
Chicago Duan3d307082020-11-26 14:12:12 +0800228inline void doSubscriptionCollection(
Ed Tanouse81de512023-06-27 17:07:00 -0700229 const boost::system::error_code& ec,
Chicago Duan3d307082020-11-26 14:12:12 +0800230 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
231 const dbus::utility::ManagedObjectType& resp)
232{
233 if (ec)
234 {
Ed Tanous13061012023-07-25 11:12:19 -0700235 if (ec.value() == EBADR || ec.value() == EHOSTUNREACH)
Chicago Duan3d307082020-11-26 14:12:12 +0800236 {
237 // This is an optional process so just return if it isn't there
238 return;
239 }
240
Ed Tanous62598e32023-07-17 17:06:25 -0700241 BMCWEB_LOG_ERROR("D-Bus response error on GetManagedObjects {}", ec);
Chicago Duan3d307082020-11-26 14:12:12 +0800242 messages::internalError(asyncResp->res);
243 return;
244 }
245 nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"];
246 for (const auto& objpath : resp)
247 {
248 sdbusplus::message::object_path path(objpath.first);
249 const std::string snmpId = path.filename();
250 if (snmpId.empty())
251 {
Ed Tanous62598e32023-07-17 17:06:25 -0700252 BMCWEB_LOG_ERROR("The SNMP client ID is wrong");
Chicago Duan3d307082020-11-26 14:12:12 +0800253 messages::internalError(asyncResp->res);
254 return;
255 }
256
257 getSnmpSubscriptionList(asyncResp, snmpId, memberArray);
258 }
259}
260
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700261inline void requestRoutesEventDestinationCollection(App& app)
262{
Gayathri Leburu1ebe3e42022-02-09 10:45:19 +0000263 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/")
Ed Tanoused398212021-06-09 17:05:54 -0700264 .privileges(redfish::privileges::getEventDestinationCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700265 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700266 [&app](const crow::Request& req,
267 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400268 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
269 {
270 return;
271 }
272 asyncResp->res.jsonValue["@odata.type"] =
273 "#EventDestinationCollection.EventDestinationCollection";
274 asyncResp->res.jsonValue["@odata.id"] =
275 "/redfish/v1/EventService/Subscriptions";
276 asyncResp->res.jsonValue["Name"] =
277 "Event Destination Collections";
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700278
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400279 nlohmann::json& memberArray =
280 asyncResp->res.jsonValue["Members"];
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700281
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400282 std::vector<std::string> subscripIds =
283 EventServiceManager::getInstance().getAllIDs();
284 memberArray = nlohmann::json::array();
285 asyncResp->res.jsonValue["Members@odata.count"] =
286 subscripIds.size();
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700287
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400288 for (const std::string& id : subscripIds)
289 {
290 nlohmann::json::object_t member;
291 member["@odata.id"] = boost::urls::format(
292 "/redfish/v1/EventService/Subscriptions/{}" + id);
293 memberArray.emplace_back(std::move(member));
294 }
295 crow::connections::systemBus->async_method_call(
296 [asyncResp](const boost::system::error_code& ec,
297 const dbus::utility::ManagedObjectType& resp) {
298 doSubscriptionCollection(ec, asyncResp, resp);
299 },
300 "xyz.openbmc_project.Network.SNMP",
301 "/xyz/openbmc_project/network/snmp/manager",
302 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
303 });
Chicago Duan3d307082020-11-26 14:12:12 +0800304
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700305 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/")
Abhishek Patel7eeafa72021-07-28 10:59:16 -0500306 .privileges(redfish::privileges::postEventDestinationCollection)
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400307 .methods(
308 boost::beast::http::verb::
309 post)([&app](
310 const crow::Request& req,
311 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
312 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
313 {
314 return;
315 }
316 if (EventServiceManager::getInstance().getNumberOfSubscriptions() >=
317 maxNoOfSubscriptions)
318 {
319 messages::eventSubscriptionLimitExceeded(asyncResp->res);
320 return;
321 }
322 std::string destUrl;
323 std::string protocol;
324 std::optional<bool> verifyCertificate;
325 std::optional<std::string> context;
326 std::optional<std::string> subscriptionType;
327 std::optional<std::string> eventFormatType2;
328 std::optional<std::string> retryPolicy;
Myung Bae5064a252024-10-04 09:34:25 -0700329 std::optional<bool> sendHeartbeat;
330 std::optional<uint64_t> hbIntervalMinutes;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400331 std::optional<std::vector<std::string>> msgIds;
332 std::optional<std::vector<std::string>> regPrefixes;
Ed Tanousa14c9112024-09-04 10:46:47 -0700333 std::optional<std::vector<std::string>> originResources;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400334 std::optional<std::vector<std::string>> resTypes;
335 std::optional<std::vector<nlohmann::json::object_t>> headers;
336 std::optional<std::vector<nlohmann::json::object_t>> mrdJsonArray;
Ed Tanousfffb8c12022-02-07 23:53:03 -0800337
Myung Baeafc474a2024-10-09 00:53:29 -0700338 if (!json_util::readJsonPatch( //
339 req, asyncResp->res, //
340 "Context", context, //
341 "DeliveryRetryPolicy", retryPolicy, //
342 "Destination", destUrl, //
343 "EventFormatType", eventFormatType2, //
Myung Bae5064a252024-10-04 09:34:25 -0700344 "HeartbeatIntervalMinutes", hbIntervalMinutes, //
Myung Baeafc474a2024-10-09 00:53:29 -0700345 "HttpHeaders", headers, //
346 "MessageIds", msgIds, //
347 "MetricReportDefinitions", mrdJsonArray, //
348 "OriginResources", originResources, //
349 "Protocol", protocol, //
350 "RegistryPrefixes", regPrefixes, //
351 "ResourceTypes", resTypes, //
Myung Bae5064a252024-10-04 09:34:25 -0700352 "SendHeartbeat", sendHeartbeat, //
Myung Baeafc474a2024-10-09 00:53:29 -0700353 "SubscriptionType", subscriptionType, //
354 "VerifyCertificate", verifyCertificate //
355 ))
Ed Tanousfffb8c12022-02-07 23:53:03 -0800356 {
Ed Tanousa716aa72023-08-01 11:35:53 -0700357 return;
358 }
Ed Tanous4b712a22023-08-02 12:56:52 -0700359 // clang-format on
Chicago Duan3d307082020-11-26 14:12:12 +0800360
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400361 // https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
362 static constexpr const uint16_t maxDestinationSize = 2000;
363 if (destUrl.size() > maxDestinationSize)
Ed Tanousfffb8c12022-02-07 23:53:03 -0800364 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400365 messages::stringValueTooLong(asyncResp->res, "Destination",
366 maxDestinationSize);
Ed Tanous002d39b2022-05-31 08:59:27 -0700367 return;
368 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700369
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400370 if (regPrefixes && msgIds)
Ed Tanous002d39b2022-05-31 08:59:27 -0700371 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400372 if (!regPrefixes->empty() && !msgIds->empty())
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700373 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400374 messages::propertyValueConflict(
375 asyncResp->res, "MessageIds", "RegistryPrefixes");
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530376 return;
377 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800378 }
P Dheeraj Srujan Kumarb304bd72021-01-29 17:46:35 +0530379
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400380 boost::system::result<boost::urls::url> url =
381 boost::urls::parse_absolute_uri(destUrl);
382 if (!url)
Ed Tanousfffb8c12022-02-07 23:53:03 -0800383 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400384 BMCWEB_LOG_WARNING(
385 "Failed to validate and split destination url");
386 messages::propertyValueFormatError(asyncResp->res, destUrl,
387 "Destination");
388 return;
389 }
390 url->normalize();
George Liub07942e2024-11-01 09:59:40 +0800391
392 // port_number returns zero if it is not a valid representable port
393 if (url->has_port() && url->port_number() == 0)
394 {
395 BMCWEB_LOG_WARNING("{} is an invalid port in destination url",
396 url->port());
397 messages::propertyValueFormatError(asyncResp->res, destUrl,
398 "Destination");
399 return;
400 }
401
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400402 crow::utility::setProtocolDefaults(*url, protocol);
403 crow::utility::setPortDefaults(*url);
404
405 if (url->path().empty())
406 {
407 url->set_path("/");
408 }
409
410 if (url->has_userinfo())
411 {
412 messages::propertyValueFormatError(asyncResp->res, destUrl,
413 "Destination");
414 return;
415 }
416
417 if (protocol == "SNMPv2c")
418 {
419 if (context)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700420 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400421 messages::propertyValueConflict(asyncResp->res, "Context",
422 "Protocol");
AppaRao Puli144b6312020-08-03 22:23:12 +0530423 return;
424 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400425 if (eventFormatType2)
426 {
427 messages::propertyValueConflict(
428 asyncResp->res, "EventFormatType", "Protocol");
429 return;
430 }
431 if (retryPolicy)
432 {
433 messages::propertyValueConflict(asyncResp->res,
434 "RetryPolicy", "Protocol");
435 return;
436 }
Myung Bae5064a252024-10-04 09:34:25 -0700437 if (sendHeartbeat)
438 {
439 messages::propertyValueConflict(
440 asyncResp->res, "SendHeartbeat", "Protocol");
441 return;
442 }
443 if (hbIntervalMinutes)
444 {
445 messages::propertyValueConflict(
446 asyncResp->res, "HeartbeatIntervalMinutes", "Protocol");
447 return;
448 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400449 if (msgIds)
450 {
451 messages::propertyValueConflict(asyncResp->res,
452 "MessageIds", "Protocol");
453 return;
454 }
455 if (regPrefixes)
456 {
457 messages::propertyValueConflict(
458 asyncResp->res, "RegistryPrefixes", "Protocol");
459 return;
460 }
461 if (resTypes)
462 {
463 messages::propertyValueConflict(
464 asyncResp->res, "ResourceTypes", "Protocol");
465 return;
466 }
467 if (headers)
468 {
469 messages::propertyValueConflict(asyncResp->res,
470 "HttpHeaders", "Protocol");
471 return;
472 }
473 if (mrdJsonArray)
474 {
475 messages::propertyValueConflict(
476 asyncResp->res, "MetricReportDefinitions", "Protocol");
477 return;
478 }
479 if (url->scheme() != "snmp")
480 {
481 messages::propertyValueConflict(asyncResp->res,
482 "Destination", "Protocol");
483 return;
484 }
485
486 addSnmpTrapClient(asyncResp, url->host_address(),
487 url->port_number());
488 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700489 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700490
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400491 std::shared_ptr<Subscription> subValue =
Myung Bae21a94d52024-10-14 15:02:57 -0700492 std::make_shared<Subscription>(
Myung Bae5fe4ef32024-10-19 09:56:02 -0400493 std::make_shared<persistent_data::UserSubscription>(), *url,
494 app.ioContext());
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400495
496 if (subscriptionType)
Ed Tanous002d39b2022-05-31 08:59:27 -0700497 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400498 if (*subscriptionType != "RedfishEvent")
499 {
500 messages::propertyValueNotInList(
501 asyncResp->res, *subscriptionType, "SubscriptionType");
502 return;
503 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400504 subValue->userSub->subscriptionType = *subscriptionType;
Ed Tanousfffb8c12022-02-07 23:53:03 -0800505 }
506 else
507 {
Ed Tanous4b712a22023-08-02 12:56:52 -0700508 // Default
Myung Bae5fe4ef32024-10-19 09:56:02 -0400509 subValue->userSub->subscriptionType = "RedfishEvent";
Ed Tanousfffb8c12022-02-07 23:53:03 -0800510 }
AppaRao Puli156d6b02020-04-25 06:04:05 +0530511
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400512 if (protocol != "Redfish")
Ed Tanousfffb8c12022-02-07 23:53:03 -0800513 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400514 messages::propertyValueNotInList(asyncResp->res, protocol,
515 "Protocol");
516 return;
517 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400518 subValue->userSub->protocol = protocol;
Ed Tanousfffb8c12022-02-07 23:53:03 -0800519
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400520 if (verifyCertificate)
521 {
Myung Bae5fe4ef32024-10-19 09:56:02 -0400522 subValue->userSub->verifyCertificate = *verifyCertificate;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400523 }
524
525 if (eventFormatType2)
526 {
527 if (std::ranges::find(supportedEvtFormatTypes,
528 *eventFormatType2) ==
529 supportedEvtFormatTypes.end())
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700530 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400531 messages::propertyValueNotInList(
532 asyncResp->res, *eventFormatType2, "EventFormatType");
533 return;
534 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400535 subValue->userSub->eventFormatType = *eventFormatType2;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400536 }
537 else
538 {
539 // If not specified, use default "Event"
Myung Bae5fe4ef32024-10-19 09:56:02 -0400540 subValue->userSub->eventFormatType = "Event";
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400541 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700542
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400543 if (context)
544 {
545 // This value is selected arbitrarily.
546 constexpr const size_t maxContextSize = 256;
547 if (context->size() > maxContextSize)
548 {
549 messages::stringValueTooLong(asyncResp->res, "Context",
550 maxContextSize);
551 return;
552 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400553 subValue->userSub->customText = *context;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400554 }
555
556 if (headers)
557 {
558 size_t cumulativeLen = 0;
559
560 for (const nlohmann::json::object_t& headerChunk : *headers)
561 {
562 for (const auto& item : headerChunk)
Ed Tanous002d39b2022-05-31 08:59:27 -0700563 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400564 const std::string* value =
565 item.second.get_ptr<const std::string*>();
566 if (value == nullptr)
567 {
568 messages::propertyValueFormatError(
569 asyncResp->res, item.second,
570 "HttpHeaders/" + item.first);
571 return;
572 }
573 // Adding a new json value is the size of the key, +
574 // the size of the value + 2 * 2 quotes for each, +
575 // the colon and space between. example:
576 // "key": "value"
577 cumulativeLen += item.first.size() + value->size() + 6;
578 // This value is selected to mirror http_connection.hpp
579 constexpr const uint16_t maxHeaderSizeED = 8096;
580 if (cumulativeLen > maxHeaderSizeED)
581 {
582 messages::arraySizeTooLong(
583 asyncResp->res, "HttpHeaders", maxHeaderSizeED);
584 return;
585 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400586 subValue->userSub->httpHeaders.set(item.first, *value);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400587 }
588 }
589 }
590
591 if (regPrefixes)
592 {
593 for (const std::string& it : *regPrefixes)
594 {
595 if (std::ranges::find(supportedRegPrefixes, it) ==
596 supportedRegPrefixes.end())
597 {
598 messages::propertyValueNotInList(asyncResp->res, it,
599 "RegistryPrefixes");
600 return;
601 }
602 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400603 subValue->userSub->registryPrefixes = *regPrefixes;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400604 }
605
Ed Tanousa14c9112024-09-04 10:46:47 -0700606 if (originResources)
607 {
Myung Bae5fe4ef32024-10-19 09:56:02 -0400608 subValue->userSub->originResources = *originResources;
Ed Tanousa14c9112024-09-04 10:46:47 -0700609 }
610
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400611 if (resTypes)
612 {
613 for (const std::string& it : *resTypes)
614 {
615 if (std::ranges::find(supportedResourceTypes, it) ==
616 supportedResourceTypes.end())
617 {
618 messages::propertyValueNotInList(asyncResp->res, it,
619 "ResourceTypes");
620 return;
621 }
622 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400623 subValue->userSub->resourceTypes = *resTypes;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400624 }
625
626 if (msgIds)
627 {
628 std::vector<std::string> registryPrefix;
629
630 // If no registry prefixes are mentioned, consider all
631 // supported prefixes
Myung Bae5fe4ef32024-10-19 09:56:02 -0400632 if (subValue->userSub->registryPrefixes.empty())
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400633 {
634 registryPrefix.assign(supportedRegPrefixes.begin(),
635 supportedRegPrefixes.end());
636 }
637 else
638 {
Myung Bae5fe4ef32024-10-19 09:56:02 -0400639 registryPrefix = subValue->userSub->registryPrefixes;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400640 }
641
642 for (const std::string& id : *msgIds)
643 {
644 bool validId = false;
645
646 // Check for Message ID in each of the selected Registry
647 for (const std::string& it : registryPrefix)
648 {
649 const std::span<const redfish::registries::MessageEntry>
650 registry =
651 redfish::registries::getRegistryFromPrefix(it);
652
653 if (std::ranges::any_of(
654 registry,
655 [&id](const redfish::registries::MessageEntry&
656 messageEntry) {
657 return id == messageEntry.first;
658 }))
659 {
660 validId = true;
661 break;
662 }
663 }
664
665 if (!validId)
666 {
667 messages::propertyValueNotInList(asyncResp->res, id,
668 "MessageIds");
669 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700670 }
671 }
672
Myung Bae5fe4ef32024-10-19 09:56:02 -0400673 subValue->userSub->registryMsgIds = *msgIds;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400674 }
675
676 if (retryPolicy)
677 {
678 if (std::ranges::find(supportedRetryPolicies, *retryPolicy) ==
679 supportedRetryPolicies.end())
Ed Tanous002d39b2022-05-31 08:59:27 -0700680 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400681 messages::propertyValueNotInList(
682 asyncResp->res, *retryPolicy, "DeliveryRetryPolicy");
Ed Tanousfffb8c12022-02-07 23:53:03 -0800683 return;
684 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400685 subValue->userSub->retryPolicy = *retryPolicy;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400686 }
687 else
688 {
689 // Default "TerminateAfterRetries"
Myung Bae5fe4ef32024-10-19 09:56:02 -0400690 subValue->userSub->retryPolicy = "TerminateAfterRetries";
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400691 }
Myung Bae5064a252024-10-04 09:34:25 -0700692 if (sendHeartbeat)
693 {
694 subValue->userSub->sendHeartbeat = *sendHeartbeat;
695 }
696 if (hbIntervalMinutes)
697 {
698 if (*hbIntervalMinutes < 1 || *hbIntervalMinutes > 65535)
699 {
700 messages::propertyValueOutOfRange(
701 asyncResp->res, *hbIntervalMinutes,
702 "HeartbeatIntervalMinutes");
703 return;
704 }
705 subValue->userSub->hbIntervalMinutes = *hbIntervalMinutes;
706 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400707
708 if (mrdJsonArray)
709 {
710 for (nlohmann::json::object_t& mrdObj : *mrdJsonArray)
711 {
712 std::string mrdUri;
713
714 if (!json_util::readJsonObject(mrdObj, asyncResp->res,
715 "@odata.id", mrdUri))
716
717 {
718 return;
719 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400720 subValue->userSub->metricReportDefinitions.emplace_back(
Ed Tanous4b712a22023-08-02 12:56:52 -0700721 mrdUri);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400722 }
Ed Tanousfffb8c12022-02-07 23:53:03 -0800723 }
724
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400725 std::string id =
726 EventServiceManager::getInstance().addPushSubscription(
727 subValue);
728 if (id.empty())
Ed Tanousfffb8c12022-02-07 23:53:03 -0800729 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400730 messages::internalError(asyncResp->res);
Ed Tanousfffb8c12022-02-07 23:53:03 -0800731 return;
732 }
733
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400734 messages::created(asyncResp->res);
735 asyncResp->res.addHeader(
736 "Location", "/redfish/v1/EventService/Subscriptions/" + id);
Myung Baefb546102024-10-29 10:21:26 -0500737
738 // schedule a heartbeat
739 if (subValue->userSub->sendHeartbeat)
740 {
741 subValue->scheduleNextHeartbeatEvent();
742 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400743 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700744}
745
746inline void requestRoutesEventDestination(App& app)
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530747{
Ravi Teja9d41aec2021-07-23 01:57:01 -0500748 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700749 .privileges(redfish::privileges::getEventDestination)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700750 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700751 [&app](const crow::Request& req,
752 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
753 const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400754 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
755 {
756 return;
757 }
Chicago Duan3d307082020-11-26 14:12:12 +0800758
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400759 if (param.starts_with("snmp"))
760 {
761 getSnmpTrapClient(asyncResp, param);
762 return;
763 }
Chicago Duan3d307082020-11-26 14:12:12 +0800764
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400765 std::shared_ptr<Subscription> subValue =
766 EventServiceManager::getInstance().getSubscription(param);
767 if (subValue == nullptr)
768 {
769 asyncResp->res.result(
770 boost::beast::http::status::not_found);
771 return;
772 }
773 const std::string& id = param;
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530774
Ed Tanous4b712a22023-08-02 12:56:52 -0700775 const persistent_data::UserSubscription& userSub =
Myung Bae5fe4ef32024-10-19 09:56:02 -0400776 *subValue->userSub;
zhanghch058d1b46d2021-04-01 11:18:24 +0800777
Ed Tanous4b712a22023-08-02 12:56:52 -0700778 nlohmann::json& jVal = asyncResp->res.jsonValue;
779 jVal["@odata.type"] =
780 "#EventDestination.v1_14_1.EventDestination";
781 jVal["Protocol"] =
782 event_destination::EventDestinationProtocol::Redfish;
783 jVal["@odata.id"] = boost::urls::format(
784 "/redfish/v1/EventService/Subscriptions/{}", id);
785 jVal["Id"] = id;
786 jVal["Name"] = "Event Destination " + id;
787 jVal["Destination"] = userSub.destinationUrl;
788 jVal["Context"] = userSub.customText;
789 jVal["SubscriptionType"] = userSub.subscriptionType;
790 jVal["HttpHeaders"] = nlohmann::json::array();
791 jVal["EventFormatType"] = userSub.eventFormatType;
792 jVal["RegistryPrefixes"] = userSub.registryPrefixes;
793 jVal["ResourceTypes"] = userSub.resourceTypes;
794
795 jVal["MessageIds"] = userSub.registryMsgIds;
796 jVal["DeliveryRetryPolicy"] = userSub.retryPolicy;
Myung Bae5064a252024-10-04 09:34:25 -0700797 jVal["SendHeartbeat"] = userSub.sendHeartbeat;
798 jVal["HeartbeatIntervalMinutes"] = userSub.hbIntervalMinutes;
Ed Tanous4b712a22023-08-02 12:56:52 -0700799 jVal["VerifyCertificate"] = userSub.verifyCertificate;
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530800
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400801 nlohmann::json::array_t mrdJsonArray;
Ed Tanous4b712a22023-08-02 12:56:52 -0700802 for (const auto& mdrUri : userSub.metricReportDefinitions)
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400803 {
804 nlohmann::json::object_t mdr;
805 mdr["@odata.id"] = mdrUri;
806 mrdJsonArray.emplace_back(std::move(mdr));
807 }
Ed Tanous4b712a22023-08-02 12:56:52 -0700808 jVal["MetricReportDefinitions"] = mrdJsonArray;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400809 });
Ravi Teja9d41aec2021-07-23 01:57:01 -0500810 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700811 // The below privilege is wrong, it should be ConfigureManager OR
812 // ConfigureSelf
Abhishek Patel7eeafa72021-07-28 10:59:16 -0500813 // https://github.com/openbmc/bmcweb/issues/220
Ed Tanoused398212021-06-09 17:05:54 -0700814 //.privileges(redfish::privileges::patchEventDestination)
Ed Tanous432a8902021-06-14 15:28:56 -0700815 .privileges({{"ConfigureManager"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700816 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700817 [&app](const crow::Request& req,
818 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
819 const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400820 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700821 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400822 return;
823 }
824 std::shared_ptr<Subscription> subValue =
825 EventServiceManager::getInstance().getSubscription(param);
826 if (subValue == nullptr)
827 {
828 asyncResp->res.result(
829 boost::beast::http::status::not_found);
830 return;
831 }
832
833 std::optional<std::string> context;
834 std::optional<std::string> retryPolicy;
Myung Bae5064a252024-10-04 09:34:25 -0700835 std::optional<bool> sendHeartbeat;
836 std::optional<uint64_t> hbIntervalMinutes;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400837 std::optional<bool> verifyCertificate;
838 std::optional<std::vector<nlohmann::json::object_t>> headers;
839
Myung Baeafc474a2024-10-09 00:53:29 -0700840 if (!json_util::readJsonPatch( //
841 req, asyncResp->res, //
842 "Context", context, //
843 "DeliveryRetryPolicy", retryPolicy, //
Myung Bae5064a252024-10-04 09:34:25 -0700844 "HeartbeatIntervalMinutes", hbIntervalMinutes, //
Myung Baeafc474a2024-10-09 00:53:29 -0700845 "HttpHeaders", headers, //
Myung Bae5064a252024-10-04 09:34:25 -0700846 "SendHeartbeat", sendHeartbeat, //
Myung Baeafc474a2024-10-09 00:53:29 -0700847 "VerifyCertificate", verifyCertificate //
848 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400849 {
850 return;
851 }
852
853 if (context)
854 {
Myung Bae5fe4ef32024-10-19 09:56:02 -0400855 subValue->userSub->customText = *context;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400856 }
857
858 if (headers)
859 {
860 boost::beast::http::fields fields;
861 for (const nlohmann::json::object_t& headerChunk : *headers)
Ed Tanous601c71a2021-09-08 16:40:12 -0700862 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400863 for (const auto& it : headerChunk)
864 {
865 const std::string* value =
866 it.second.get_ptr<const std::string*>();
867 if (value == nullptr)
868 {
869 messages::propertyValueFormatError(
870 asyncResp->res, it.second,
871 "HttpHeaders/" + it.first);
872 return;
873 }
874 fields.set(it.first, *value);
875 }
876 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400877 subValue->userSub->httpHeaders = std::move(fields);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400878 }
879
880 if (retryPolicy)
881 {
882 if (std::ranges::find(supportedRetryPolicies,
883 *retryPolicy) ==
884 supportedRetryPolicies.end())
885 {
886 messages::propertyValueNotInList(asyncResp->res,
887 *retryPolicy,
888 "DeliveryRetryPolicy");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700889 return;
890 }
Myung Bae5fe4ef32024-10-19 09:56:02 -0400891 subValue->userSub->retryPolicy = *retryPolicy;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700892 }
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530893
Myung Bae5064a252024-10-04 09:34:25 -0700894 if (sendHeartbeat)
895 {
896 subValue->userSub->sendHeartbeat = *sendHeartbeat;
897 }
898 if (hbIntervalMinutes)
899 {
900 if (*hbIntervalMinutes < 1 || *hbIntervalMinutes > 65535)
901 {
902 messages::propertyValueOutOfRange(
903 asyncResp->res, *hbIntervalMinutes,
904 "HeartbeatIntervalMinutes");
905 return;
906 }
907 subValue->userSub->hbIntervalMinutes = *hbIntervalMinutes;
908 }
909
Myung Baefb546102024-10-29 10:21:26 -0500910 if (hbIntervalMinutes || sendHeartbeat)
911 {
912 // if Heartbeat interval or send heart were changed, cancel
913 // the heartbeat timer if running and start a new heartbeat
914 // if needed
915 subValue->heartbeatParametersChanged();
916 }
917
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400918 if (verifyCertificate)
919 {
Myung Bae5fe4ef32024-10-19 09:56:02 -0400920 subValue->userSub->verifyCertificate = *verifyCertificate;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400921 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700922
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400923 EventServiceManager::getInstance().updateSubscriptionData();
924 });
Ravi Teja9d41aec2021-07-23 01:57:01 -0500925 BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700926 // The below privilege is wrong, it should be ConfigureManager OR
927 // ConfigureSelf
Abhishek Patel7eeafa72021-07-28 10:59:16 -0500928 // https://github.com/openbmc/bmcweb/issues/220
Ed Tanoused398212021-06-09 17:05:54 -0700929 //.privileges(redfish::privileges::deleteEventDestination)
Ed Tanous432a8902021-06-14 15:28:56 -0700930 .privileges({{"ConfigureManager"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700931 .methods(boost::beast::http::verb::delete_)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700932 [&app](const crow::Request& req,
933 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
934 const std::string& param) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400935 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
936 {
937 return;
938 }
Ed Tanous4b712a22023-08-02 12:56:52 -0700939 EventServiceManager& event = EventServiceManager::getInstance();
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400940 if (param.starts_with("snmp"))
941 {
942 deleteSnmpTrapClient(asyncResp, param);
Ed Tanous4b712a22023-08-02 12:56:52 -0700943 event.deleteSubscription(param);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400944 return;
945 }
Chicago Duan3d307082020-11-26 14:12:12 +0800946
Ed Tanous4b712a22023-08-02 12:56:52 -0700947 if (!event.deleteSubscription(param))
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400948 {
Ed Tanous4b712a22023-08-02 12:56:52 -0700949 messages::resourceNotFound(asyncResp->res,
950 "EventDestination", param);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400951 return;
952 }
Ed Tanous4b712a22023-08-02 12:56:52 -0700953 messages::success(asyncResp->res);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400954 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700955}
AppaRao Pulie5aaf042020-03-20 01:05:52 +0530956
957} // namespace redfish