EventService: SubmitTestEvent initial support
This commit adds SubmitTestEvent initial support to
send out test events to subscribers.
URI:
/redfish/v1/EventService/Actions/EventService.SubmitTestEvent
Tested:
- Client subscribed to event listener via destination uri.
After sending POST request on SubmitTestEvent uri, could see
generated test event.
- Successfully ran the redfish validator.
Counter({'metadataNamespaces': 1739, 'pass': 26,
'skipOptional': 22, 'serviceNamespaces': 3, 'passGet': 3,
'passAction': 1})
Validation has succeeded.
Change-Id: I16e02c1977e99af39317070567196767ac7c7400
Signed-off-by: Ayushi Smriti <smriti.ayushi@linux.intel.com>
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 0634328..54bc503 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -48,8 +48,8 @@
Subscription(const std::string& inHost, const std::string& inPort,
const std::string& inPath, const std::string& inUriProto) :
- host(inHost),
- port(inPort), path(inPath), uriProto(inUriProto)
+ eventSeqNum(1),
+ host(inHost), port(inPort), path(inPath), uriProto(inUriProto)
{
conn = std::make_shared<crow::HttpClient>(
crow::connections::systemBus->get_io_context(), host, port, path);
@@ -74,7 +74,32 @@
conn->sendData(msg);
}
+ void sendTestEventLog()
+ {
+ nlohmann::json logEntryArray;
+ logEntryArray.push_back({});
+ nlohmann::json& logEntryJson = logEntryArray.back();
+
+ logEntryJson = {{"EventId", "TestID"},
+ {"EventType", "Event"},
+ {"Severity", "OK"},
+ {"Message", "Generated test event"},
+ {"MessageId", "OpenBMC.0.1.TestEventLog"},
+ {"MessageArgs", nlohmann::json::array()},
+ {"EventTimestamp", crow::utility::dateTimeNow()},
+ {"Context", customText}};
+
+ nlohmann::json msg = {{"@odata.type", "#Event.v1_4_0.Event"},
+ {"Id", std::to_string(eventSeqNum)},
+ {"Name", "Event Log"},
+ {"Events", logEntryArray}};
+
+ this->sendEvent(msg.dump());
+ this->eventSeqNum++;
+ }
+
private:
+ uint64_t eventSeqNum;
std::string host;
std::string port;
std::string path;
@@ -208,6 +233,15 @@
}
return false;
}
+
+ void sendTestEventLog()
+ {
+ for (const auto& it : this->subscriptionsMap)
+ {
+ std::shared_ptr<Subscription> entry = it.second;
+ entry->sendTestEventLog();
+ }
+ }
};
} // namespace redfish
diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp
index 6f2e753..1f97b18 100644
--- a/redfish-core/include/redfish.hpp
+++ b/redfish-core/include/redfish.hpp
@@ -180,6 +180,7 @@
nodes.emplace_back(std::make_unique<EventService>(app));
nodes.emplace_back(std::make_unique<EventDestinationCollection>(app));
nodes.emplace_back(std::make_unique<EventDestination>(app));
+ nodes.emplace_back(std::make_unique<SubmitTestEvent>(app));
nodes.emplace_back(
std::make_unique<HypervisorInterfaceCollection>(app));