Correct the version of Message Id
Applications are logging Redfish Message ID to journal, but the version
of some message ID are different with the definition of bmcweb. E.g:
- psusensor is defining version of OpenBMC registry is "0.1" as [1].
- The bmcweb defines the version of OpenBMC registry is "0.5" as [2].
It makes the "MessageId" property of Event log's enties has different
version with definition in the /redfish/v1/Registries.
This commit corrects the version of Message ID.
[1]: https://github.com/openbmc/dbus-sensors/blob/6b7123225fc4a5180faf89190e9f64a7e248e697/src/psu/PSUEvent.cpp#L121
[2]: https://github.com/openbmc/bmcweb/blob/master/redfish-core/include/registries/openbmc.json#L1678
Tested:
Verify the version of Events are the same the version of Registries
that are defined in the bmcweb.
Change-Id: Ib862c8d0a62cae63082436cb4646a9ca45207872
Signed-off-by: Thang Tran <thuutran@amperecomputing.com>
diff --git a/redfish-core/src/registries.cpp b/redfish-core/src/registries.cpp
index 2a426bf..8084a51 100644
--- a/redfish-core/src/registries.cpp
+++ b/redfish-core/src/registries.cpp
@@ -17,6 +17,7 @@
#include <span>
#include <string>
#include <string_view>
+#include <utility>
#include <vector>
namespace redfish::registries
@@ -67,25 +68,34 @@
return nullptr;
}
-const Message* getMessage(std::string_view messageID)
+std::optional<MessageId> getMessageComponents(std::string_view message)
{
- // Redfish MessageIds are in the form
- // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
- // the right Message
+ // Redfish Message are in the form
+ // RegistryName.MajorVersion.MinorVersion.MessageKey
std::vector<std::string> fields;
fields.reserve(4);
- bmcweb::split(fields, messageID, '.');
+ bmcweb::split(fields, message, '.');
if (fields.size() != 4)
{
+ return std::nullopt;
+ }
+
+ return MessageId(std::move(fields[0]), std::move(fields[1]),
+ std::move(fields[2]), std::move(fields[3]));
+}
+
+const Message* getMessage(std::string_view messageID)
+{
+ std::optional<MessageId> msgComponents = getMessageComponents(messageID);
+ if (!msgComponents)
+ {
return nullptr;
}
- const std::string& registryName = fields[0];
- const std::string& messageKey = fields[3];
-
// Find the right registry and check it for the MessageKey
- return getMessageFromRegistry(messageKey,
- getRegistryMessagesFromPrefix(registryName));
+ return getMessageFromRegistry(
+ msgComponents->messageKey,
+ getRegistryMessagesFromPrefix(msgComponents->registryName));
}
} // namespace redfish::registries