summaryrefslogtreecommitdiff
path: root/redfish-core/include/event_service_manager.hpp
diff options
context:
space:
mode:
authorsunharis_in <sunharis@in.ibm.com>2021-07-06 14:06:58 +0300
committerEd Tanous <ed@tanous.net>2022-02-09 00:36:56 +0300
commit6ba8c82ef6e67486b251cdc8c75e5a65a419a0ab (patch)
treee944ada84f6de96a498e4c1c5cdca34bdd596c56 /redfish-core/include/event_service_manager.hpp
parenteae855c74b30085f6ac1094f6087c6b3913a9a69 (diff)
downloadbmcweb-6ba8c82ef6e67486b251cdc8c75e5a65a419a0ab.tar.xz
Send push-style event only if EventService enabled
As per DMTF Redfish, if the event service is disabled, events are not expected to be posted to the existing subscribers This commit adds validation to check "ServiceEnabled" property while sending events. An additional check is made not to attempt sending events if there are no event subscribers at BMC Tested by: Using DMTF Redfish-Event-Listener script with some local modification to support the latest event subscription specifications 1. With a Push-style event subscriber setup, set "ServiceEnabled" to false PATCH /redfish/v1/EventService -d '{"ServiceEnabled":false}' 2. Generate events and check no events are posted to subscriber 2. Set "ServiceEnabled" to true. BMC should resume sending further events 3. Check if BMC attempts to send events by forming the eventRecords when there are no subscriptions made - Verified with traces that events are not sent out 4. With "ServiceEnabled" set to false, verified the SubmitTestEvent fails Signed-off-by: Sunitha Harish <sunharis@in.ibm.com> Change-Id: Icbe7c25ba12bbfb73e59639c484fccdf384ebecf
Diffstat (limited to 'redfish-core/include/event_service_manager.hpp')
-rw-r--r--redfish-core/include/event_service_manager.hpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 556a635917..4fb07ca235 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -391,8 +391,16 @@ class Subscription : public persistent_data::UserSubscription
~Subscription() = default;
- void sendEvent(const std::string& msg)
+ bool sendEvent(const std::string& msg)
{
+ persistent_data::EventServiceConfig eventServiceConfig =
+ persistent_data::EventServiceStore::getInstance()
+ .getEventServiceConfig();
+ if (!eventServiceConfig.enabled)
+ {
+ return false;
+ }
+
if (conn == nullptr)
{
// create the HttpClient connection
@@ -408,9 +416,10 @@ class Subscription : public persistent_data::UserSubscription
{
sseConn->sendData(eventSeqNum, msg);
}
+ return true;
}
- void sendTestEventLog()
+ bool sendTestEventLog()
{
nlohmann::json logEntryArray;
logEntryArray.push_back({});
@@ -431,7 +440,7 @@ class Subscription : public persistent_data::UserSubscription
{"Name", "Event Log"},
{"Events", logEntryArray}};
- this->sendEvent(
+ return this->sendEvent(
msg.dump(2, ' ', true, nlohmann::json::error_handler_t::replace));
}
@@ -971,18 +980,27 @@ class EventServiceManager
return false;
}
- void sendTestEventLog()
+ bool sendTestEventLog()
{
for (const auto& it : this->subscriptionsMap)
{
std::shared_ptr<Subscription> entry = it.second;
- entry->sendTestEventLog();
+ if (!entry->sendTestEventLog())
+ {
+ return false;
+ }
}
+ return true;
}
void sendEvent(const nlohmann::json& eventMessageIn,
const std::string& origin, const std::string& resType)
{
+ if (!serviceEnabled || !noOfEventLogSubscribers)
+ {
+ BMCWEB_LOG_DEBUG << "EventService disabled or no Subscriptions.";
+ return;
+ }
nlohmann::json eventRecord = nlohmann::json::array();
nlohmann::json eventMessage = eventMessageIn;
// MemberId is 0 : since we are sending one event record.