summaryrefslogtreecommitdiff
path: root/redfish-core/include/event_service_manager.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-02-14 20:32:05 +0300
committerEd Tanous <ed@tanous.net>2022-08-02 07:07:07 +0300
commit80f595e7c00dc5b82e1aba8828c3a8205f9a4332 (patch)
treea2cdd7a257753d87de520bb01d712a55dd11254a /redfish-core/include/event_service_manager.hpp
parente155ab54ec5ad4c31937f4d7de8b502e91468e43 (diff)
downloadbmcweb-80f595e7c00dc5b82e1aba8828c3a8205f9a4332.tar.xz
Simplify fillMessageArgs
The aforementioned function does a lot of reconstruction of strings as args are filled in. This results in the end of the string being copied many times (N). Replace the algorithm with one that builds a new string, using reserve (which is good practice) and is also capable of returning errors in the case of bad entries. fillMessageArgs now returns a string instead of trying to do things in place, which avoids the initial std::string construction, so we should be net the same here. Given this new algorithm can now detect failures in parsing (ie, trying to parse %1 with no arguments) add unit tests for coverage of that, and modify event manager slightly to handle errors. Tested: Unit tests pass. Pretty good coverage of this stuff. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I16f28a2ac78580fb35266561f5ae38078b471989
Diffstat (limited to 'redfish-core/include/event_service_manager.hpp')
-rw-r--r--redfish-core/include/event_service_manager.hpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 6b3f84fc90..d581aeb283 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -235,15 +235,17 @@ inline int formatEventLogEntry(const std::string& logEntryID,
// Get the Message from the MessageRegistry
const registries::Message* message = registries::formatMessage(messageID);
- std::string msg;
- std::string severity;
- if (message != nullptr)
+ if (message == nullptr)
{
- msg = message->message;
- severity = message->messageSeverity;
+ return -1;
}
- redfish::registries::fillMessageArgs(messageArgs, msg);
+ std::string msg =
+ redfish::registries::fillMessageArgs(messageArgs, message->message);
+ if (msg.empty())
+ {
+ return -1;
+ }
// Get the Created time from the timestamp. The log timestamp is in
// RFC3339 format which matches the Redfish format except for the
@@ -258,7 +260,7 @@ inline int formatEventLogEntry(const std::string& logEntryID,
// Fill in the log entry with the gathered data
logEntryJson["EventId"] = logEntryID;
logEntryJson["EventType"] = "Event";
- logEntryJson["Severity"] = std::move(severity);
+ logEntryJson["Severity"] = message->messageSeverity;
logEntryJson["Message"] = std::move(msg);
logEntryJson["MessageId"] = messageID;
logEntryJson["MessageArgs"] = messageArgs;