1e5aaf047SAppaRao Puli /* 2e5aaf047SAppaRao Puli // Copyright (c) 2020 Intel Corporation 3e5aaf047SAppaRao Puli // 4e5aaf047SAppaRao Puli // Licensed under the Apache License, Version 2.0 (the "License"); 5e5aaf047SAppaRao Puli // you may not use this file except in compliance with the License. 6e5aaf047SAppaRao Puli // You may obtain a copy of the License at 7e5aaf047SAppaRao Puli // 8e5aaf047SAppaRao Puli // http://www.apache.org/licenses/LICENSE-2.0 9e5aaf047SAppaRao Puli // 10e5aaf047SAppaRao Puli // Unless required by applicable law or agreed to in writing, software 11e5aaf047SAppaRao Puli // distributed under the License is distributed on an "AS IS" BASIS, 12e5aaf047SAppaRao Puli // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e5aaf047SAppaRao Puli // See the License for the specific language governing permissions and 14e5aaf047SAppaRao Puli // limitations under the License. 15e5aaf047SAppaRao Puli */ 16e5aaf047SAppaRao Puli #pragma once 173ccb3adbSEd Tanous #include "app.hpp" 18b52664e2SAppaRao Puli #include "event_service_manager.hpp" 193ccb3adbSEd Tanous #include "http/utility.hpp" 203ccb3adbSEd Tanous #include "logging.hpp" 213ccb3adbSEd Tanous #include "query.hpp" 223ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 233d30708fSChicago Duan #include "snmp_trap_event_clients.hpp" 24e5aaf047SAppaRao Puli 25601c71aeSEd Tanous #include <boost/beast/http/fields.hpp> 263d30708fSChicago Duan #include <boost/system/error_code.hpp> 273d30708fSChicago Duan #include <sdbusplus/unpack_properties.hpp> 283d30708fSChicago Duan #include <utils/dbus_utils.hpp> 29ed398213SEd Tanous 303d30708fSChicago Duan #include <charconv> 313d30708fSChicago Duan #include <memory> 321e270c5fSPatrick Williams #include <span> 333d30708fSChicago Duan #include <string> 341e270c5fSPatrick Williams 35e5aaf047SAppaRao Puli namespace redfish 36e5aaf047SAppaRao Puli { 37e5aaf047SAppaRao Puli 38156d6b00SAppaRao Puli static constexpr const std::array<const char*, 2> supportedEvtFormatTypes = { 39156d6b00SAppaRao Puli eventFormatType, metricReportFormatType}; 40e5aaf047SAppaRao Puli static constexpr const std::array<const char*, 3> supportedRegPrefixes = { 41b304bd79SP Dheeraj Srujan Kumar "Base", "OpenBMC", "TaskEvent"}; 42e5aaf047SAppaRao Puli static constexpr const std::array<const char*, 3> supportedRetryPolicies = { 43e5aaf047SAppaRao Puli "TerminateAfterRetries", "SuspendRetries", "RetryForever"}; 44e5aaf047SAppaRao Puli 45e56f254cSSunitha Harish static constexpr const std::array<const char*, 1> supportedResourceTypes = { 46e56f254cSSunitha Harish "Task"}; 47e56f254cSSunitha Harish 487e860f15SJohn Edward Broadbent inline void requestRoutesEventService(App& app) 49e5aaf047SAppaRao Puli { 507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/EventService/") 51ed398213SEd Tanous .privileges(redfish::privileges::getEventService) 52002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 53002d39b4SEd Tanous [&app](const crow::Request& req, 54002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 553ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 5645ca1b86SEd Tanous { 5745ca1b86SEd Tanous return; 5845ca1b86SEd Tanous } 591476687dSEd Tanous 601476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/EventService"; 611476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 621476687dSEd Tanous "#EventService.v1_5_0.EventService"; 631476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "EventService"; 641476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Event Service"; 655e44e3d8SAppaRao Puli asyncResp->res.jsonValue["ServerSentEventUri"] = 665e44e3d8SAppaRao Puli "/redfish/v1/EventService/SSE"; 675e44e3d8SAppaRao Puli 681476687dSEd Tanous asyncResp->res.jsonValue["Subscriptions"]["@odata.id"] = 691476687dSEd Tanous "/redfish/v1/EventService/Subscriptions"; 70002d39b4SEd Tanous asyncResp->res 71002d39b4SEd Tanous .jsonValue["Actions"]["#EventService.SubmitTestEvent"]["target"] = 721476687dSEd Tanous "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent"; 73e5aaf047SAppaRao Puli 7428afb49cSJunLin Chen const persistent_data::EventServiceConfig eventServiceConfig = 7528afb49cSJunLin Chen persistent_data::EventServiceStore::getInstance() 7628afb49cSJunLin Chen .getEventServiceConfig(); 777d1cc387SAppaRao Puli 787d1cc387SAppaRao Puli asyncResp->res.jsonValue["Status"]["State"] = 7928afb49cSJunLin Chen (eventServiceConfig.enabled ? "Enabled" : "Disabled"); 80002d39b4SEd Tanous asyncResp->res.jsonValue["ServiceEnabled"] = eventServiceConfig.enabled; 817e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["DeliveryRetryAttempts"] = 8228afb49cSJunLin Chen eventServiceConfig.retryAttempts; 83e5aaf047SAppaRao Puli asyncResp->res.jsonValue["DeliveryRetryIntervalSeconds"] = 8428afb49cSJunLin Chen eventServiceConfig.retryTimeoutInterval; 85002d39b4SEd Tanous asyncResp->res.jsonValue["EventFormatTypes"] = supportedEvtFormatTypes; 860fda0f12SGeorge Liu asyncResp->res.jsonValue["RegistryPrefixes"] = supportedRegPrefixes; 870fda0f12SGeorge Liu asyncResp->res.jsonValue["ResourceTypes"] = supportedResourceTypes; 8807941a88SAyushi Smriti 89613dabeaSEd Tanous nlohmann::json::object_t supportedSSEFilters; 90613dabeaSEd Tanous supportedSSEFilters["EventFormatType"] = true; 91613dabeaSEd Tanous supportedSSEFilters["MessageId"] = true; 92613dabeaSEd Tanous supportedSSEFilters["MetricReportDefinition"] = true; 93613dabeaSEd Tanous supportedSSEFilters["RegistryPrefix"] = true; 94613dabeaSEd Tanous supportedSSEFilters["OriginResource"] = false; 95613dabeaSEd Tanous supportedSSEFilters["ResourceType"] = false; 9607941a88SAyushi Smriti 9707941a88SAyushi Smriti asyncResp->res.jsonValue["SSEFilterPropertiesSupported"] = 98613dabeaSEd Tanous std::move(supportedSSEFilters); 997e860f15SJohn Edward Broadbent }); 100e5aaf047SAppaRao Puli 1017e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/EventService/") 102ed398213SEd Tanous .privileges(redfish::privileges::patchEventService) 1037e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 10445ca1b86SEd Tanous [&app](const crow::Request& req, 10545ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1063ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 107e5aaf047SAppaRao Puli { 10845ca1b86SEd Tanous return; 10945ca1b86SEd Tanous } 110e5aaf047SAppaRao Puli std::optional<bool> serviceEnabled; 111e5aaf047SAppaRao Puli std::optional<uint32_t> retryAttemps; 112e5aaf047SAppaRao Puli std::optional<uint32_t> retryInterval; 113e5aaf047SAppaRao Puli 11415ed6780SWilly Tu if (!json_util::readJsonPatch( 1157e860f15SJohn Edward Broadbent req, asyncResp->res, "ServiceEnabled", serviceEnabled, 1167e860f15SJohn Edward Broadbent "DeliveryRetryAttempts", retryAttemps, 1177e860f15SJohn Edward Broadbent "DeliveryRetryIntervalSeconds", retryInterval)) 118e5aaf047SAppaRao Puli { 119e5aaf047SAppaRao Puli return; 120e5aaf047SAppaRao Puli } 121e5aaf047SAppaRao Puli 12228afb49cSJunLin Chen persistent_data::EventServiceConfig eventServiceConfig = 12328afb49cSJunLin Chen persistent_data::EventServiceStore::getInstance() 12428afb49cSJunLin Chen .getEventServiceConfig(); 1257d1cc387SAppaRao Puli 126e5aaf047SAppaRao Puli if (serviceEnabled) 127e5aaf047SAppaRao Puli { 12828afb49cSJunLin Chen eventServiceConfig.enabled = *serviceEnabled; 129e5aaf047SAppaRao Puli } 130e5aaf047SAppaRao Puli 131e5aaf047SAppaRao Puli if (retryAttemps) 132e5aaf047SAppaRao Puli { 133e5aaf047SAppaRao Puli // Supported range [1-3] 134e5aaf047SAppaRao Puli if ((*retryAttemps < 1) || (*retryAttemps > 3)) 135e5aaf047SAppaRao Puli { 136e5aaf047SAppaRao Puli messages::queryParameterOutOfRange( 137e5aaf047SAppaRao Puli asyncResp->res, std::to_string(*retryAttemps), 138e5aaf047SAppaRao Puli "DeliveryRetryAttempts", "[1-3]"); 139e5aaf047SAppaRao Puli } 140e5aaf047SAppaRao Puli else 141e5aaf047SAppaRao Puli { 14228afb49cSJunLin Chen eventServiceConfig.retryAttempts = *retryAttemps; 143e5aaf047SAppaRao Puli } 144e5aaf047SAppaRao Puli } 145e5aaf047SAppaRao Puli 146e5aaf047SAppaRao Puli if (retryInterval) 147e5aaf047SAppaRao Puli { 14833a32b34SGunnar Mills // Supported range [5 - 180] 14933a32b34SGunnar Mills if ((*retryInterval < 5) || (*retryInterval > 180)) 150e5aaf047SAppaRao Puli { 151e5aaf047SAppaRao Puli messages::queryParameterOutOfRange( 152e5aaf047SAppaRao Puli asyncResp->res, std::to_string(*retryInterval), 15333a32b34SGunnar Mills "DeliveryRetryIntervalSeconds", "[5-180]"); 154e5aaf047SAppaRao Puli } 155e5aaf047SAppaRao Puli else 156e5aaf047SAppaRao Puli { 157002d39b4SEd Tanous eventServiceConfig.retryTimeoutInterval = *retryInterval; 158e5aaf047SAppaRao Puli } 159e5aaf047SAppaRao Puli } 160e5aaf047SAppaRao Puli 1617d1cc387SAppaRao Puli EventServiceManager::getInstance().setEventServiceConfig( 16228afb49cSJunLin Chen eventServiceConfig); 1637e860f15SJohn Edward Broadbent }); 1640b4bdd93SAppaRao Puli } 1650b4bdd93SAppaRao Puli 1667e860f15SJohn Edward Broadbent inline void requestRoutesSubmitTestEvent(App& app) 1670b4bdd93SAppaRao Puli { 1687e860f15SJohn Edward Broadbent BMCWEB_ROUTE( 1697e860f15SJohn Edward Broadbent app, "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent/") 170ed398213SEd Tanous .privileges(redfish::privileges::postEventService) 1717e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 17245ca1b86SEd Tanous [&app](const crow::Request& req, 1737e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1743ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 17545ca1b86SEd Tanous { 17645ca1b86SEd Tanous return; 17745ca1b86SEd Tanous } 1786ba8c82eSsunharis_in if (!EventServiceManager::getInstance().sendTestEventLog()) 1796ba8c82eSsunharis_in { 1806ba8c82eSsunharis_in messages::serviceDisabled(asyncResp->res, 1816ba8c82eSsunharis_in "/redfish/v1/EventService/"); 1826ba8c82eSsunharis_in return; 1836ba8c82eSsunharis_in } 1848d1b46d7Szhanghch05 asyncResp->res.result(boost::beast::http::status::no_content); 1857e860f15SJohn Edward Broadbent }); 186e5aaf047SAppaRao Puli } 187e5aaf047SAppaRao Puli 1883d30708fSChicago Duan inline void doSubscriptionCollection( 189e81de512SEd Tanous const boost::system::error_code& ec, 1903d30708fSChicago Duan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1913d30708fSChicago Duan const dbus::utility::ManagedObjectType& resp) 1923d30708fSChicago Duan { 1933d30708fSChicago Duan if (ec) 1943d30708fSChicago Duan { 1951306101eSEd Tanous if (ec.value() == EBADR || ec.value() == EHOSTUNREACH) 1963d30708fSChicago Duan { 1973d30708fSChicago Duan // This is an optional process so just return if it isn't there 1983d30708fSChicago Duan return; 1993d30708fSChicago Duan } 2003d30708fSChicago Duan 20162598e31SEd Tanous BMCWEB_LOG_ERROR("D-Bus response error on GetManagedObjects {}", ec); 2023d30708fSChicago Duan messages::internalError(asyncResp->res); 2033d30708fSChicago Duan return; 2043d30708fSChicago Duan } 2053d30708fSChicago Duan nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"]; 2063d30708fSChicago Duan for (const auto& objpath : resp) 2073d30708fSChicago Duan { 2083d30708fSChicago Duan sdbusplus::message::object_path path(objpath.first); 2093d30708fSChicago Duan const std::string snmpId = path.filename(); 2103d30708fSChicago Duan if (snmpId.empty()) 2113d30708fSChicago Duan { 21262598e31SEd Tanous BMCWEB_LOG_ERROR("The SNMP client ID is wrong"); 2133d30708fSChicago Duan messages::internalError(asyncResp->res); 2143d30708fSChicago Duan return; 2153d30708fSChicago Duan } 2163d30708fSChicago Duan 2173d30708fSChicago Duan getSnmpSubscriptionList(asyncResp, snmpId, memberArray); 2183d30708fSChicago Duan } 2193d30708fSChicago Duan } 2203d30708fSChicago Duan 2217e860f15SJohn Edward Broadbent inline void requestRoutesEventDestinationCollection(App& app) 222e5aaf047SAppaRao Puli { 2231ebe3e41SGayathri Leburu BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/") 224ed398213SEd Tanous .privileges(redfish::privileges::getEventDestinationCollection) 2257e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22645ca1b86SEd Tanous [&app](const crow::Request& req, 2277e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2283ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 22945ca1b86SEd Tanous { 23045ca1b86SEd Tanous return; 23145ca1b86SEd Tanous } 2321476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 2331476687dSEd Tanous "#EventDestinationCollection.EventDestinationCollection"; 2341476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2351476687dSEd Tanous "/redfish/v1/EventService/Subscriptions"; 236002d39b4SEd Tanous asyncResp->res.jsonValue["Name"] = "Event Destination Collections"; 237e5aaf047SAppaRao Puli 238002d39b4SEd Tanous nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"]; 239e5aaf047SAppaRao Puli 240b52664e2SAppaRao Puli std::vector<std::string> subscripIds = 241b52664e2SAppaRao Puli EventServiceManager::getInstance().getAllIDs(); 242b52664e2SAppaRao Puli memberArray = nlohmann::json::array(); 243002d39b4SEd Tanous asyncResp->res.jsonValue["Members@odata.count"] = subscripIds.size(); 244b52664e2SAppaRao Puli 245b52664e2SAppaRao Puli for (const std::string& id : subscripIds) 246e5aaf047SAppaRao Puli { 2471476687dSEd Tanous nlohmann::json::object_t member; 2483d30708fSChicago Duan member["@odata.id"] = boost::urls::format( 2493d30708fSChicago Duan "/redfish/v1/EventService/Subscriptions/{}" + id); 250b2ba3072SPatrick Williams memberArray.emplace_back(std::move(member)); 251e5aaf047SAppaRao Puli } 2523d30708fSChicago Duan crow::connections::systemBus->async_method_call( 253e81de512SEd Tanous [asyncResp](const boost::system::error_code& ec, 2543d30708fSChicago Duan const dbus::utility::ManagedObjectType& resp) { 2553d30708fSChicago Duan doSubscriptionCollection(ec, asyncResp, resp); 2563d30708fSChicago Duan }, 2573d30708fSChicago Duan "xyz.openbmc_project.Network.SNMP", 2583d30708fSChicago Duan "/xyz/openbmc_project/network/snmp/manager", 2593d30708fSChicago Duan "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 2607e860f15SJohn Edward Broadbent }); 2613d30708fSChicago Duan 2627e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/") 2637eeafa76SAbhishek Patel .privileges(redfish::privileges::postEventDestinationCollection) 264002d39b4SEd Tanous .methods(boost::beast::http::verb::post)( 265002d39b4SEd Tanous [&app](const crow::Request& req, 2667e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2673ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 26845ca1b86SEd Tanous { 26945ca1b86SEd Tanous return; 27045ca1b86SEd Tanous } 271fffb8c1fSEd Tanous if (EventServiceManager::getInstance().getNumberOfSubscriptions() >= 272fffb8c1fSEd Tanous maxNoOfSubscriptions) 273e5aaf047SAppaRao Puli { 274e5aaf047SAppaRao Puli messages::eventSubscriptionLimitExceeded(asyncResp->res); 275e5aaf047SAppaRao Puli return; 276e5aaf047SAppaRao Puli } 277e5aaf047SAppaRao Puli std::string destUrl; 278e5aaf047SAppaRao Puli std::string protocol; 279e5aaf047SAppaRao Puli std::optional<std::string> context; 280e5aaf047SAppaRao Puli std::optional<std::string> subscriptionType; 28123a21a1cSEd Tanous std::optional<std::string> eventFormatType2; 282e5aaf047SAppaRao Puli std::optional<std::string> retryPolicy; 283e5aaf047SAppaRao Puli std::optional<std::vector<std::string>> msgIds; 284e5aaf047SAppaRao Puli std::optional<std::vector<std::string>> regPrefixes; 285e56f254cSSunitha Harish std::optional<std::vector<std::string>> resTypes; 286e5aaf047SAppaRao Puli std::optional<std::vector<nlohmann::json>> headers; 287144b6318SAppaRao Puli std::optional<std::vector<nlohmann::json>> mrdJsonArray; 288e5aaf047SAppaRao Puli 28915ed6780SWilly Tu if (!json_util::readJsonPatch( 290002d39b4SEd Tanous req, asyncResp->res, "Destination", destUrl, "Context", context, 291002d39b4SEd Tanous "Protocol", protocol, "SubscriptionType", subscriptionType, 292002d39b4SEd Tanous "EventFormatType", eventFormatType2, "HttpHeaders", headers, 293002d39b4SEd Tanous "RegistryPrefixes", regPrefixes, "MessageIds", msgIds, 294002d39b4SEd Tanous "DeliveryRetryPolicy", retryPolicy, "MetricReportDefinitions", 295002d39b4SEd Tanous mrdJsonArray, "ResourceTypes", resTypes)) 296e5aaf047SAppaRao Puli { 297e5aaf047SAppaRao Puli return; 298e5aaf047SAppaRao Puli } 299e5aaf047SAppaRao Puli 300600af5f1SAppaRao Puli // https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers 301600af5f1SAppaRao Puli static constexpr const uint16_t maxDestinationSize = 2000; 302600af5f1SAppaRao Puli if (destUrl.size() > maxDestinationSize) 303600af5f1SAppaRao Puli { 304600af5f1SAppaRao Puli messages::stringValueTooLong(asyncResp->res, "Destination", 305600af5f1SAppaRao Puli maxDestinationSize); 306600af5f1SAppaRao Puli return; 307600af5f1SAppaRao Puli } 308600af5f1SAppaRao Puli 309dd28ba82SAppaRao Puli if (regPrefixes && msgIds) 310dd28ba82SAppaRao Puli { 31126f6976fSEd Tanous if (!regPrefixes->empty() && !msgIds->empty()) 312dd28ba82SAppaRao Puli { 313002d39b4SEd Tanous messages::propertyValueConflict(asyncResp->res, "MessageIds", 314002d39b4SEd Tanous "RegistryPrefixes"); 315dd28ba82SAppaRao Puli return; 316dd28ba82SAppaRao Puli } 317dd28ba82SAppaRao Puli } 318dd28ba82SAppaRao Puli 319eb1c47d3SEd Tanous std::string host; 320eb1c47d3SEd Tanous std::string urlProto; 321eb1c47d3SEd Tanous uint16_t port = 0; 322eb1c47d3SEd Tanous std::string path; 323eb1c47d3SEd Tanous 324002d39b4SEd Tanous if (!crow::utility::validateAndSplitUrl(destUrl, urlProto, host, port, 325002d39b4SEd Tanous path)) 326e5aaf047SAppaRao Puli { 32762598e31SEd Tanous BMCWEB_LOG_WARNING("Failed to validate and split destination url"); 328e5aaf047SAppaRao Puli messages::propertyValueFormatError(asyncResp->res, destUrl, 329e5aaf047SAppaRao Puli "Destination"); 330e5aaf047SAppaRao Puli return; 331e5aaf047SAppaRao Puli } 332b52664e2SAppaRao Puli 3333d30708fSChicago Duan if (protocol == "SNMPv2c") 3343d30708fSChicago Duan { 3353d30708fSChicago Duan if (context) 3363d30708fSChicago Duan { 3373d30708fSChicago Duan messages::propertyValueConflict(asyncResp->res, "Context", 3383d30708fSChicago Duan "Protocol"); 3393d30708fSChicago Duan return; 3403d30708fSChicago Duan } 3413d30708fSChicago Duan if (eventFormatType2) 3423d30708fSChicago Duan { 3433d30708fSChicago Duan messages::propertyValueConflict(asyncResp->res, 3443d30708fSChicago Duan "EventFormatType", "Protocol"); 3453d30708fSChicago Duan return; 3463d30708fSChicago Duan } 3473d30708fSChicago Duan if (retryPolicy) 3483d30708fSChicago Duan { 3493d30708fSChicago Duan messages::propertyValueConflict(asyncResp->res, "RetryPolicy", 3503d30708fSChicago Duan "Protocol"); 3513d30708fSChicago Duan return; 3523d30708fSChicago Duan } 3533d30708fSChicago Duan if (msgIds) 3543d30708fSChicago Duan { 3553d30708fSChicago Duan messages::propertyValueConflict(asyncResp->res, "MessageIds", 3563d30708fSChicago Duan "Protocol"); 3573d30708fSChicago Duan return; 3583d30708fSChicago Duan } 3593d30708fSChicago Duan if (regPrefixes) 3603d30708fSChicago Duan { 3613d30708fSChicago Duan messages::propertyValueConflict(asyncResp->res, 3623d30708fSChicago Duan "RegistryPrefixes", "Protocol"); 3633d30708fSChicago Duan return; 3643d30708fSChicago Duan } 3653d30708fSChicago Duan if (resTypes) 3663d30708fSChicago Duan { 3673d30708fSChicago Duan messages::propertyValueConflict(asyncResp->res, "ResourceTypes", 3683d30708fSChicago Duan "Protocol"); 3693d30708fSChicago Duan return; 3703d30708fSChicago Duan } 3713d30708fSChicago Duan if (headers) 3723d30708fSChicago Duan { 3733d30708fSChicago Duan messages::propertyValueConflict(asyncResp->res, "HttpHeaders", 3743d30708fSChicago Duan "Protocol"); 3753d30708fSChicago Duan return; 3763d30708fSChicago Duan } 3773d30708fSChicago Duan if (mrdJsonArray) 3783d30708fSChicago Duan { 3793d30708fSChicago Duan messages::propertyValueConflict( 3803d30708fSChicago Duan asyncResp->res, "MetricReportDefinitions", "Protocol"); 3813d30708fSChicago Duan return; 3823d30708fSChicago Duan } 3833d30708fSChicago Duan 3843d30708fSChicago Duan addSnmpTrapClient(asyncResp, host, port); 3853d30708fSChicago Duan return; 3863d30708fSChicago Duan } 3873d30708fSChicago Duan 388b52664e2SAppaRao Puli if (path.empty()) 389b52664e2SAppaRao Puli { 390b52664e2SAppaRao Puli path = "/"; 391b52664e2SAppaRao Puli } 3923d30708fSChicago Duan 393f8ca6d79SEd Tanous std::shared_ptr<Subscription> subValue = std::make_shared<Subscription>( 394f8ca6d79SEd Tanous host, port, path, urlProto, app.ioContext()); 395b52664e2SAppaRao Puli 396b52664e2SAppaRao Puli subValue->destinationUrl = destUrl; 397e5aaf047SAppaRao Puli 398e5aaf047SAppaRao Puli if (subscriptionType) 399e5aaf047SAppaRao Puli { 400e5aaf047SAppaRao Puli if (*subscriptionType != "RedfishEvent") 401e5aaf047SAppaRao Puli { 402fffb8c1fSEd Tanous messages::propertyValueNotInList( 403fffb8c1fSEd Tanous asyncResp->res, *subscriptionType, "SubscriptionType"); 404e5aaf047SAppaRao Puli return; 405e5aaf047SAppaRao Puli } 406b52664e2SAppaRao Puli subValue->subscriptionType = *subscriptionType; 407e5aaf047SAppaRao Puli } 408e5aaf047SAppaRao Puli else 409e5aaf047SAppaRao Puli { 410b52664e2SAppaRao Puli subValue->subscriptionType = "RedfishEvent"; // Default 411e5aaf047SAppaRao Puli } 412e5aaf047SAppaRao Puli 413e5aaf047SAppaRao Puli if (protocol != "Redfish") 414e5aaf047SAppaRao Puli { 415e5aaf047SAppaRao Puli messages::propertyValueNotInList(asyncResp->res, protocol, 416e5aaf047SAppaRao Puli "Protocol"); 417e5aaf047SAppaRao Puli return; 418e5aaf047SAppaRao Puli } 419b52664e2SAppaRao Puli subValue->protocol = protocol; 420e5aaf047SAppaRao Puli 42123a21a1cSEd Tanous if (eventFormatType2) 422e5aaf047SAppaRao Puli { 423e5aaf047SAppaRao Puli if (std::find(supportedEvtFormatTypes.begin(), 424e5aaf047SAppaRao Puli supportedEvtFormatTypes.end(), 425002d39b4SEd Tanous *eventFormatType2) == supportedEvtFormatTypes.end()) 426e5aaf047SAppaRao Puli { 427fffb8c1fSEd Tanous messages::propertyValueNotInList( 428fffb8c1fSEd Tanous asyncResp->res, *eventFormatType2, "EventFormatType"); 429e5aaf047SAppaRao Puli return; 430e5aaf047SAppaRao Puli } 43123a21a1cSEd Tanous subValue->eventFormatType = *eventFormatType2; 432e5aaf047SAppaRao Puli } 433e5aaf047SAppaRao Puli else 434e5aaf047SAppaRao Puli { 435e5aaf047SAppaRao Puli // If not specified, use default "Event" 43623a21a1cSEd Tanous subValue->eventFormatType = "Event"; 437e5aaf047SAppaRao Puli } 438e5aaf047SAppaRao Puli 439e5aaf047SAppaRao Puli if (context) 440e5aaf047SAppaRao Puli { 441600af5f1SAppaRao Puli // This value is selected aribitrarily. 442600af5f1SAppaRao Puli constexpr const size_t maxContextSize = 256; 443600af5f1SAppaRao Puli if (context->size() > maxContextSize) 444600af5f1SAppaRao Puli { 445600af5f1SAppaRao Puli messages::stringValueTooLong(asyncResp->res, "Context", 446600af5f1SAppaRao Puli maxContextSize); 447600af5f1SAppaRao Puli return; 448600af5f1SAppaRao Puli } 449b52664e2SAppaRao Puli subValue->customText = *context; 450e5aaf047SAppaRao Puli } 451e5aaf047SAppaRao Puli 452e5aaf047SAppaRao Puli if (headers) 453e5aaf047SAppaRao Puli { 454600af5f1SAppaRao Puli size_t cumulativeLen = 0; 455600af5f1SAppaRao Puli 456601c71aeSEd Tanous for (const nlohmann::json& headerChunk : *headers) 457601c71aeSEd Tanous { 458600af5f1SAppaRao Puli std::string hdr{headerChunk.dump( 459600af5f1SAppaRao Puli -1, ' ', true, nlohmann::json::error_handler_t::replace)}; 460600af5f1SAppaRao Puli cumulativeLen += hdr.length(); 461600af5f1SAppaRao Puli 462600af5f1SAppaRao Puli // This value is selected to mirror http_connection.hpp 463600af5f1SAppaRao Puli constexpr const uint16_t maxHeaderSizeED = 8096; 464600af5f1SAppaRao Puli if (cumulativeLen > maxHeaderSizeED) 465600af5f1SAppaRao Puli { 466600af5f1SAppaRao Puli messages::arraySizeTooLong(asyncResp->res, "HttpHeaders", 467600af5f1SAppaRao Puli maxHeaderSizeED); 468600af5f1SAppaRao Puli return; 469600af5f1SAppaRao Puli } 470601c71aeSEd Tanous for (const auto& item : headerChunk.items()) 471601c71aeSEd Tanous { 472601c71aeSEd Tanous const std::string* value = 473601c71aeSEd Tanous item.value().get_ptr<const std::string*>(); 474601c71aeSEd Tanous if (value == nullptr) 475601c71aeSEd Tanous { 476601c71aeSEd Tanous messages::propertyValueFormatError( 477f818b04dSEd Tanous asyncResp->res, item.value(), 478601c71aeSEd Tanous "HttpHeaders/" + item.key()); 479601c71aeSEd Tanous return; 480601c71aeSEd Tanous } 481601c71aeSEd Tanous subValue->httpHeaders.set(item.key(), *value); 482601c71aeSEd Tanous } 483601c71aeSEd Tanous } 484e5aaf047SAppaRao Puli } 485e5aaf047SAppaRao Puli 486e5aaf047SAppaRao Puli if (regPrefixes) 487e5aaf047SAppaRao Puli { 488e5aaf047SAppaRao Puli for (const std::string& it : *regPrefixes) 489e5aaf047SAppaRao Puli { 490e5aaf047SAppaRao Puli if (std::find(supportedRegPrefixes.begin(), 491e5aaf047SAppaRao Puli supportedRegPrefixes.end(), 492e5aaf047SAppaRao Puli it) == supportedRegPrefixes.end()) 493e5aaf047SAppaRao Puli { 494fffb8c1fSEd Tanous messages::propertyValueNotInList(asyncResp->res, it, 495fffb8c1fSEd Tanous "RegistryPrefixes"); 496e5aaf047SAppaRao Puli return; 497e5aaf047SAppaRao Puli } 498e5aaf047SAppaRao Puli } 499b52664e2SAppaRao Puli subValue->registryPrefixes = *regPrefixes; 500e5aaf047SAppaRao Puli } 501e5aaf047SAppaRao Puli 502e56f254cSSunitha Harish if (resTypes) 503e56f254cSSunitha Harish { 504e56f254cSSunitha Harish for (const std::string& it : *resTypes) 505e56f254cSSunitha Harish { 506e56f254cSSunitha Harish if (std::find(supportedResourceTypes.begin(), 507e56f254cSSunitha Harish supportedResourceTypes.end(), 508e56f254cSSunitha Harish it) == supportedResourceTypes.end()) 509e56f254cSSunitha Harish { 510e56f254cSSunitha Harish messages::propertyValueNotInList(asyncResp->res, it, 511e56f254cSSunitha Harish "ResourceTypes"); 512e56f254cSSunitha Harish return; 513e56f254cSSunitha Harish } 514e56f254cSSunitha Harish } 515e56f254cSSunitha Harish subValue->resourceTypes = *resTypes; 516e56f254cSSunitha Harish } 517e56f254cSSunitha Harish 518e5aaf047SAppaRao Puli if (msgIds) 519e5aaf047SAppaRao Puli { 520b304bd79SP Dheeraj Srujan Kumar std::vector<std::string> registryPrefix; 521b304bd79SP Dheeraj Srujan Kumar 5227e860f15SJohn Edward Broadbent // If no registry prefixes are mentioned, consider all 5237e860f15SJohn Edward Broadbent // supported prefixes 524b304bd79SP Dheeraj Srujan Kumar if (subValue->registryPrefixes.empty()) 525b304bd79SP Dheeraj Srujan Kumar { 526b304bd79SP Dheeraj Srujan Kumar registryPrefix.assign(supportedRegPrefixes.begin(), 527b304bd79SP Dheeraj Srujan Kumar supportedRegPrefixes.end()); 528b304bd79SP Dheeraj Srujan Kumar } 529b304bd79SP Dheeraj Srujan Kumar else 530b304bd79SP Dheeraj Srujan Kumar { 531b304bd79SP Dheeraj Srujan Kumar registryPrefix = subValue->registryPrefixes; 532b304bd79SP Dheeraj Srujan Kumar } 533b304bd79SP Dheeraj Srujan Kumar 534b304bd79SP Dheeraj Srujan Kumar for (const std::string& id : *msgIds) 535b304bd79SP Dheeraj Srujan Kumar { 536b304bd79SP Dheeraj Srujan Kumar bool validId = false; 537b304bd79SP Dheeraj Srujan Kumar 538b304bd79SP Dheeraj Srujan Kumar // Check for Message ID in each of the selected Registry 539b304bd79SP Dheeraj Srujan Kumar for (const std::string& it : registryPrefix) 540b304bd79SP Dheeraj Srujan Kumar { 541fffb8c1fSEd Tanous const std::span<const redfish::registries::MessageEntry> 542fffb8c1fSEd Tanous registry = 543fffb8c1fSEd Tanous redfish::registries::getRegistryFromPrefix(it); 544b304bd79SP Dheeraj Srujan Kumar 545b304bd79SP Dheeraj Srujan Kumar if (std::any_of( 54626702d01SEd Tanous registry.begin(), registry.end(), 547fffb8c1fSEd Tanous [&id](const redfish::registries::MessageEntry& 548fffb8c1fSEd Tanous messageEntry) { 54955f79e6fSEd Tanous return id == messageEntry.first; 550b304bd79SP Dheeraj Srujan Kumar })) 551b304bd79SP Dheeraj Srujan Kumar { 552b304bd79SP Dheeraj Srujan Kumar validId = true; 553b304bd79SP Dheeraj Srujan Kumar break; 554b304bd79SP Dheeraj Srujan Kumar } 555b304bd79SP Dheeraj Srujan Kumar } 556b304bd79SP Dheeraj Srujan Kumar 557b304bd79SP Dheeraj Srujan Kumar if (!validId) 558b304bd79SP Dheeraj Srujan Kumar { 559b304bd79SP Dheeraj Srujan Kumar messages::propertyValueNotInList(asyncResp->res, id, 560b304bd79SP Dheeraj Srujan Kumar "MessageIds"); 561b304bd79SP Dheeraj Srujan Kumar return; 562b304bd79SP Dheeraj Srujan Kumar } 563b304bd79SP Dheeraj Srujan Kumar } 564b304bd79SP Dheeraj Srujan Kumar 565b52664e2SAppaRao Puli subValue->registryMsgIds = *msgIds; 566e5aaf047SAppaRao Puli } 567e5aaf047SAppaRao Puli 568e5aaf047SAppaRao Puli if (retryPolicy) 569e5aaf047SAppaRao Puli { 570e5aaf047SAppaRao Puli if (std::find(supportedRetryPolicies.begin(), 571e5aaf047SAppaRao Puli supportedRetryPolicies.end(), 572e5aaf047SAppaRao Puli *retryPolicy) == supportedRetryPolicies.end()) 573e5aaf047SAppaRao Puli { 574002d39b4SEd Tanous messages::propertyValueNotInList(asyncResp->res, *retryPolicy, 575002d39b4SEd Tanous "DeliveryRetryPolicy"); 576e5aaf047SAppaRao Puli return; 577e5aaf047SAppaRao Puli } 578b52664e2SAppaRao Puli subValue->retryPolicy = *retryPolicy; 579e5aaf047SAppaRao Puli } 580e5aaf047SAppaRao Puli else 581e5aaf047SAppaRao Puli { 582e5aaf047SAppaRao Puli // Default "TerminateAfterRetries" 583b52664e2SAppaRao Puli subValue->retryPolicy = "TerminateAfterRetries"; 584e5aaf047SAppaRao Puli } 585e5aaf047SAppaRao Puli 586144b6318SAppaRao Puli if (mrdJsonArray) 587156d6b00SAppaRao Puli { 588144b6318SAppaRao Puli for (nlohmann::json& mrdObj : *mrdJsonArray) 589144b6318SAppaRao Puli { 590144b6318SAppaRao Puli std::string mrdUri; 591ea2e6eecSWilly Tu 592002d39b4SEd Tanous if (!json_util::readJson(mrdObj, asyncResp->res, "@odata.id", 593002d39b4SEd Tanous mrdUri)) 594ea2e6eecSWilly Tu 595144b6318SAppaRao Puli { 596144b6318SAppaRao Puli return; 597144b6318SAppaRao Puli } 598ea2e6eecSWilly Tu subValue->metricReportDefinitions.emplace_back(mrdUri); 599144b6318SAppaRao Puli } 600156d6b00SAppaRao Puli } 601156d6b00SAppaRao Puli 602b52664e2SAppaRao Puli std::string id = 603fffb8c1fSEd Tanous EventServiceManager::getInstance().addSubscription(subValue); 604b52664e2SAppaRao Puli if (id.empty()) 605e5aaf047SAppaRao Puli { 606e5aaf047SAppaRao Puli messages::internalError(asyncResp->res); 607e5aaf047SAppaRao Puli return; 608e5aaf047SAppaRao Puli } 609e5aaf047SAppaRao Puli 610e5aaf047SAppaRao Puli messages::created(asyncResp->res); 611e5aaf047SAppaRao Puli asyncResp->res.addHeader( 612e5aaf047SAppaRao Puli "Location", "/redfish/v1/EventService/Subscriptions/" + id); 6137e860f15SJohn Edward Broadbent }); 614e5aaf047SAppaRao Puli } 615e5aaf047SAppaRao Puli 6167e860f15SJohn Edward Broadbent inline void requestRoutesEventDestination(App& app) 617e5aaf047SAppaRao Puli { 6189d41aec6SRavi Teja BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/") 619ed398213SEd Tanous .privileges(redfish::privileges::getEventDestination) 6207e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 62145ca1b86SEd Tanous [&app](const crow::Request& req, 6227e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6237e860f15SJohn Edward Broadbent const std::string& param) { 6243ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 62545ca1b86SEd Tanous { 62645ca1b86SEd Tanous return; 62745ca1b86SEd Tanous } 6283d30708fSChicago Duan 6293d30708fSChicago Duan if (param.starts_with("snmp")) 6303d30708fSChicago Duan { 6313d30708fSChicago Duan getSnmpTrapClient(asyncResp, param); 6323d30708fSChicago Duan return; 6333d30708fSChicago Duan } 6343d30708fSChicago Duan 635b52664e2SAppaRao Puli std::shared_ptr<Subscription> subValue = 6367e860f15SJohn Edward Broadbent EventServiceManager::getInstance().getSubscription(param); 637b52664e2SAppaRao Puli if (subValue == nullptr) 638e5aaf047SAppaRao Puli { 639002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::not_found); 640e5aaf047SAppaRao Puli return; 641e5aaf047SAppaRao Puli } 6427e860f15SJohn Edward Broadbent const std::string& id = param; 643e5aaf047SAppaRao Puli 6441476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 6453d30708fSChicago Duan "#EventDestination.v1_8_0.EventDestination"; 6461476687dSEd Tanous asyncResp->res.jsonValue["Protocol"] = "Redfish"; 647*3b32780dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 648*3b32780dSEd Tanous "/redfish/v1/EventService/Subscriptions/{}", id); 649e5aaf047SAppaRao Puli asyncResp->res.jsonValue["Id"] = id; 650e5aaf047SAppaRao Puli asyncResp->res.jsonValue["Name"] = "Event Destination " + id; 651002d39b4SEd Tanous asyncResp->res.jsonValue["Destination"] = subValue->destinationUrl; 652b52664e2SAppaRao Puli asyncResp->res.jsonValue["Context"] = subValue->customText; 653e5aaf047SAppaRao Puli asyncResp->res.jsonValue["SubscriptionType"] = 654b52664e2SAppaRao Puli subValue->subscriptionType; 655002d39b4SEd Tanous asyncResp->res.jsonValue["HttpHeaders"] = nlohmann::json::array(); 656002d39b4SEd Tanous asyncResp->res.jsonValue["EventFormatType"] = subValue->eventFormatType; 657e5aaf047SAppaRao Puli asyncResp->res.jsonValue["RegistryPrefixes"] = 658b52664e2SAppaRao Puli subValue->registryPrefixes; 659002d39b4SEd Tanous asyncResp->res.jsonValue["ResourceTypes"] = subValue->resourceTypes; 660e56f254cSSunitha Harish 661002d39b4SEd Tanous asyncResp->res.jsonValue["MessageIds"] = subValue->registryMsgIds; 662002d39b4SEd Tanous asyncResp->res.jsonValue["DeliveryRetryPolicy"] = subValue->retryPolicy; 663144b6318SAppaRao Puli 6641476687dSEd Tanous nlohmann::json::array_t mrdJsonArray; 665144b6318SAppaRao Puli for (const auto& mdrUri : subValue->metricReportDefinitions) 666144b6318SAppaRao Puli { 6671476687dSEd Tanous nlohmann::json::object_t mdr; 6681476687dSEd Tanous mdr["@odata.id"] = mdrUri; 6691476687dSEd Tanous mrdJsonArray.emplace_back(std::move(mdr)); 670144b6318SAppaRao Puli } 671002d39b4SEd Tanous asyncResp->res.jsonValue["MetricReportDefinitions"] = mrdJsonArray; 6727e860f15SJohn Edward Broadbent }); 6739d41aec6SRavi Teja BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/") 674ed398213SEd Tanous // The below privilege is wrong, it should be ConfigureManager OR 675ed398213SEd Tanous // ConfigureSelf 6767eeafa76SAbhishek Patel // https://github.com/openbmc/bmcweb/issues/220 677ed398213SEd Tanous //.privileges(redfish::privileges::patchEventDestination) 678432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 6797e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 68045ca1b86SEd Tanous [&app](const crow::Request& req, 6817e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 6827e860f15SJohn Edward Broadbent const std::string& param) { 6833ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 68445ca1b86SEd Tanous { 68545ca1b86SEd Tanous return; 68645ca1b86SEd Tanous } 687b52664e2SAppaRao Puli std::shared_ptr<Subscription> subValue = 6887e860f15SJohn Edward Broadbent EventServiceManager::getInstance().getSubscription(param); 689b52664e2SAppaRao Puli if (subValue == nullptr) 690e5aaf047SAppaRao Puli { 691002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::not_found); 692e5aaf047SAppaRao Puli return; 693e5aaf047SAppaRao Puli } 694e5aaf047SAppaRao Puli 695e5aaf047SAppaRao Puli std::optional<std::string> context; 696e5aaf047SAppaRao Puli std::optional<std::string> retryPolicy; 697e5aaf047SAppaRao Puli std::optional<std::vector<nlohmann::json>> headers; 698e5aaf047SAppaRao Puli 699002d39b4SEd Tanous if (!json_util::readJsonPatch(req, asyncResp->res, "Context", context, 700002d39b4SEd Tanous "DeliveryRetryPolicy", retryPolicy, 701002d39b4SEd Tanous "HttpHeaders", headers)) 702e5aaf047SAppaRao Puli { 703e5aaf047SAppaRao Puli return; 704e5aaf047SAppaRao Puli } 705e5aaf047SAppaRao Puli 706e5aaf047SAppaRao Puli if (context) 707e5aaf047SAppaRao Puli { 708b52664e2SAppaRao Puli subValue->customText = *context; 709e5aaf047SAppaRao Puli } 710e5aaf047SAppaRao Puli 711e5aaf047SAppaRao Puli if (headers) 712e5aaf047SAppaRao Puli { 713601c71aeSEd Tanous boost::beast::http::fields fields; 714601c71aeSEd Tanous for (const nlohmann::json& headerChunk : *headers) 715601c71aeSEd Tanous { 71662bafc01SPatrick Williams for (const auto& it : headerChunk.items()) 717601c71aeSEd Tanous { 718601c71aeSEd Tanous const std::string* value = 719601c71aeSEd Tanous it.value().get_ptr<const std::string*>(); 720601c71aeSEd Tanous if (value == nullptr) 721601c71aeSEd Tanous { 722601c71aeSEd Tanous messages::propertyValueFormatError( 723f818b04dSEd Tanous asyncResp->res, it.value(), 724601c71aeSEd Tanous "HttpHeaders/" + it.key()); 725601c71aeSEd Tanous return; 726601c71aeSEd Tanous } 727601c71aeSEd Tanous fields.set(it.key(), *value); 728601c71aeSEd Tanous } 729601c71aeSEd Tanous } 730601c71aeSEd Tanous subValue->httpHeaders = fields; 731e5aaf047SAppaRao Puli } 732e5aaf047SAppaRao Puli 733e5aaf047SAppaRao Puli if (retryPolicy) 734e5aaf047SAppaRao Puli { 735e5aaf047SAppaRao Puli if (std::find(supportedRetryPolicies.begin(), 736e5aaf047SAppaRao Puli supportedRetryPolicies.end(), 737e5aaf047SAppaRao Puli *retryPolicy) == supportedRetryPolicies.end()) 738e5aaf047SAppaRao Puli { 739002d39b4SEd Tanous messages::propertyValueNotInList(asyncResp->res, *retryPolicy, 740e5aaf047SAppaRao Puli "DeliveryRetryPolicy"); 741e5aaf047SAppaRao Puli return; 742e5aaf047SAppaRao Puli } 743b52664e2SAppaRao Puli subValue->retryPolicy = *retryPolicy; 744e5aaf047SAppaRao Puli } 745e5aaf047SAppaRao Puli 746b52664e2SAppaRao Puli EventServiceManager::getInstance().updateSubscriptionData(); 7477e860f15SJohn Edward Broadbent }); 7489d41aec6SRavi Teja BMCWEB_ROUTE(app, "/redfish/v1/EventService/Subscriptions/<str>/") 749ed398213SEd Tanous // The below privilege is wrong, it should be ConfigureManager OR 750ed398213SEd Tanous // ConfigureSelf 7517eeafa76SAbhishek Patel // https://github.com/openbmc/bmcweb/issues/220 752ed398213SEd Tanous //.privileges(redfish::privileges::deleteEventDestination) 753432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 7547e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::delete_)( 75545ca1b86SEd Tanous [&app](const crow::Request& req, 7567e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7577e860f15SJohn Edward Broadbent const std::string& param) { 7583ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 75945ca1b86SEd Tanous { 76045ca1b86SEd Tanous return; 76145ca1b86SEd Tanous } 7623d30708fSChicago Duan 7633d30708fSChicago Duan if (param.starts_with("snmp")) 7643d30708fSChicago Duan { 7653d30708fSChicago Duan deleteSnmpTrapClient(asyncResp, param); 7663d30708fSChicago Duan EventServiceManager::getInstance().deleteSubscription(param); 7673d30708fSChicago Duan return; 7683d30708fSChicago Duan } 7693d30708fSChicago Duan 770002d39b4SEd Tanous if (!EventServiceManager::getInstance().isSubscriptionExist(param)) 771e5aaf047SAppaRao Puli { 772002d39b4SEd Tanous asyncResp->res.result(boost::beast::http::status::not_found); 773e5aaf047SAppaRao Puli return; 774e5aaf047SAppaRao Puli } 7757e860f15SJohn Edward Broadbent EventServiceManager::getInstance().deleteSubscription(param); 7767e860f15SJohn Edward Broadbent }); 777e5aaf047SAppaRao Puli } 778e5aaf047SAppaRao Puli 779e5aaf047SAppaRao Puli } // namespace redfish 780