diff options
author | Sunitha Harish <sunithaharish04@gmail.com> | 2020-06-26 13:42:14 +0300 |
---|---|---|
committer | Sunitha Harish <sunithaharish04@gmail.com> | 2020-08-04 06:32:54 +0300 |
commit | 96330b9965034bacf1f676c8f049f273db82cc14 (patch) | |
tree | 3c46ca3562a6ff47287e500e0717b2697b45908f | |
parent | 3d0ecaca735d2f7efa660d6319765274dc8974e6 (diff) | |
download | bmcweb-96330b9965034bacf1f676c8f049f273db82cc14.tar.xz |
EventService : Send event for the ConfigFile creation
This implements the sendEvent when the IBM management console
creates the ConfigFile at BMC using the PUT operation on the
url /ibm/v1/Host/ConfigFiles
Tested by: (Used https://github.com/DMTF/Redfish-Event-Listener)
1. Create a subscription by passing "ResourceTypes" as ["IBMConfigFile"]
POST -D headers.txt https://${bmc}/redfish/v1/EventService/Subscriptions
-d '{"Destination" : "https://<host:port>,"ResourceTypes":["IBMConfigFile"],"Protocol":"Redfish"}'
2. Create a ConfigFile
PUT https://${bmc}/ibm/v1/Host/ConfigFiles/<filename> --data-binary "@<local_path>"
3. Verify the event is generated and posted to the subscriber as below example
bodydata: {
"@odata.type":"#Event.v1_4_0.Event",
"Events":[
{
"EventId":1,
"EventTimestamp":"2020-06-26T08:40:04+00:00",
"EventType":"ResourceAdded",
"MemberId":0,
"Message":"The resource has been created successfully.",
"MessageArgs":null,
"MessageId":"ResourceEvent.1.0.3.ResourceCreated",
"OriginOfCondition":"/ibm/v1/Host/ConfigFiles/<filename>",
"MessageSeverity":"OK"
}
],
"Id":1,
"Name":"Event Log"
}
4. Verified the event is sent to the subscriber when the resourceType list is empty.
5. Verified the client subscribes for other resource - not ConfigFile ; then
the event is not sent to the subscriber.
Signed-off-by: Sunitha Harish <sunithaharish04@gmail.com>
Change-Id: Ic9b195266fe2df67a3160197d03d9ac155ef0cd1
-rw-r--r-- | include/ibm/management_console_rest.hpp | 7 | ||||
-rw-r--r-- | redfish-core/include/event_service_manager.hpp | 73 |
2 files changed, 77 insertions, 3 deletions
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp index 3038916de9..af87b76684 100644 --- a/include/ibm/management_console_rest.hpp +++ b/include/ibm/management_console_rest.hpp @@ -6,8 +6,10 @@ #include <boost/algorithm/string.hpp> #include <boost/container/flat_set.hpp> #include <error_messages.hpp> +#include <event_service_manager.hpp> #include <ibm/locks.hpp> #include <nlohmann/json.hpp> +#include <resource_messages.hpp> #include <sdbusplus/message/types.hpp> #include <utils/json_utils.hpp> @@ -30,6 +32,7 @@ namespace crow { namespace ibm_mc { +using namespace redfish; constexpr const char* methodNotAllowedMsg = "Method Not Allowed"; constexpr const char* resourceNotFoundMsg = "Resource Not Found"; constexpr const char* contentNotAcceptableMsg = "Content Not Acceptable"; @@ -127,6 +130,10 @@ void handleFilePut(const crow::Request& req, crow::Response& res, file << data; BMCWEB_LOG_DEBUG << "save-area file is created"; res.jsonValue["Description"] = "File Created"; + // Push an event + std::string origin = "/ibm/v1/Host/ConfigFiles/" + fileID; + redfish::EventServiceManager::getInstance().sendEvent( + redfish::messages::ResourceCreated(), origin, "IBMConfigFile"); } } diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 451816ed0f..0a9b022213 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -412,6 +412,7 @@ class Subscription } conn->setHeaders(reqHeaders); conn->sendData(msg); + this->eventSeqNum++; } if (sseConn != nullptr) @@ -441,7 +442,6 @@ class Subscription {"Events", logEntryArray}}; this->sendEvent(msg.dump()); - this->eventSeqNum++; } #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES @@ -505,7 +505,6 @@ class Subscription {"Events", logEntryArray}}; this->sendEvent(msg.dump()); - this->eventSeqNum++; } #endif @@ -568,6 +567,11 @@ class Subscription } } + uint64_t getEventSeqNum() + { + return eventSeqNum; + } + private: uint64_t eventSeqNum; std::string host; @@ -598,7 +602,7 @@ class EventServiceManager EventServiceManager& operator=(EventServiceManager&&) = delete; EventServiceManager() : - noOfEventLogSubscribers(0), noOfMetricReportSubscribers(0) + noOfEventLogSubscribers(0), noOfMetricReportSubscribers(0), eventId(1) { // Load config from persist store. initConfig(); @@ -611,6 +615,8 @@ class EventServiceManager boost::container::flat_map<std::string, std::shared_ptr<Subscription>> subscriptionsMap; + uint64_t eventId; + public: static EventServiceManager& getInstance() { @@ -1018,6 +1024,67 @@ class EventServiceManager } } + void sendEvent(const nlohmann::json& eventMessageIn, + const std::string& origin, const std::string& resType) + { + nlohmann::json eventRecord = nlohmann::json::array(); + nlohmann::json eventMessage = eventMessageIn; + // MemberId is 0 : since we are sending one event record. + uint64_t memberId = 0; + + nlohmann::json event = { + {"EventId", eventId}, + {"MemberId", memberId}, + {"EventTimestamp", crow::utility::dateTimeNow()}, + {"OriginOfCondition", origin}}; + for (nlohmann::json::iterator it = event.begin(); it != event.end(); + ++it) + { + eventMessage[it.key()] = it.value(); + } + eventRecord.push_back(eventMessage); + + for (const auto& it : this->subscriptionsMap) + { + std::shared_ptr<Subscription> entry = it.second; + bool isSubscribed = false; + // Search the resourceTypes list for the subscription. + // If resourceTypes list is empty, don't filter events + // send everything. + if (entry->resourceTypes.size()) + { + for (auto resource : entry->resourceTypes) + { + if (resType == resource) + { + BMCWEB_LOG_INFO << "ResourceType " << resource + << " found in the subscribed list"; + isSubscribed = true; + break; + } + } + } + else // resourceTypes list is empty. + { + isSubscribed = true; + } + if (isSubscribed) + { + nlohmann::json msgJson = { + {"@odata.type", "#Event.v1_4_0.Event"}, + {"Name", "Event Log"}, + {"Id", eventId}, + {"Events", eventRecord}}; + entry->sendEvent(msgJson.dump()); + eventId++; // increament the eventId + } + else + { + BMCWEB_LOG_INFO << "Not subscribed to this resource"; + } + } + } + #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES void cacheLastEventTimestamp() { |