summaryrefslogtreecommitdiff
path: root/redfish-core
diff options
context:
space:
mode:
authorAppaRao Puli <apparao.puli@linux.intel.com>2020-04-14 15:27:45 +0300
committersmriti.ayushi <smriti.ayushi@linux.intel.com>2020-05-07 03:55:25 +0300
commit0b4bdd93c79779913fcfc3641beb5f7f3966f339 (patch)
treeec38a80af4dff591062c62b7fdcd33cc98549c19 /redfish-core
parentdecde9ef8d94b40551803b47a09d7d3ea2b8c95d (diff)
downloadbmcweb-0b4bdd93c79779913fcfc3641beb5f7f3966f339.tar.xz
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>
Diffstat (limited to 'redfish-core')
-rw-r--r--redfish-core/include/event_service_manager.hpp38
-rw-r--r--redfish-core/include/redfish.hpp1
-rw-r--r--redfish-core/lib/event_service.hpp30
3 files changed, 67 insertions, 2 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 0634328701..54bc50329a 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -48,8 +48,8 @@ class Subscription
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 @@ class Subscription
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 @@ class EventServiceManager
}
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 6f2e75316c..1f97b18c2b 100644
--- a/redfish-core/include/redfish.hpp
+++ b/redfish-core/include/redfish.hpp
@@ -180,6 +180,7 @@ class RedfishService
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));
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 43517ddc63..3e3435ff49 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -55,6 +55,10 @@ class EventService : public Node
"/redfish/v1/EventService/Subscriptions/SSE"},
{"Subscriptions",
{{"@odata.id", "/redfish/v1/EventService/Subscriptions"}}},
+ {"Actions",
+ {{"#EventService.SubmitTestEvent",
+ {{"target", "/redfish/v1/EventService/Actions/"
+ "EventService.SubmitTestEvent"}}}}},
{"@odata.id", "/redfish/v1/EventService"}};
asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
@@ -125,6 +129,32 @@ class EventService : public Node
}
};
+class SubmitTestEvent : public Node
+{
+ public:
+ SubmitTestEvent(CrowApp& app) :
+ Node(app,
+ "/redfish/v1/EventService/Actions/EventService.SubmitTestEvent/")
+ {
+ entityPrivileges = {
+ {boost::beast::http::verb::get, {{"Login"}}},
+ {boost::beast::http::verb::head, {{"Login"}}},
+ {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
+ {boost::beast::http::verb::put, {{"ConfigureManager"}}},
+ {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
+ {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
+ }
+
+ private:
+ void doPost(crow::Response& res, const crow::Request& req,
+ const std::vector<std::string>& params) override
+ {
+ EventServiceManager::getInstance().sendTestEventLog();
+ res.result(boost::beast::http::status::no_content);
+ res.end();
+ }
+};
+
class EventDestinationCollection : public Node
{
public: