diff options
author | Matt Spinler <spinler@us.ibm.com> | 2020-01-23 10:04:29 -0600 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2020-01-31 15:00:11 +0000 |
commit | 677381b8fc84d49923cf49ab9e2fe6f520f19767 (patch) | |
tree | dda76bf4ed287b68e79a5507e15d221c04625999 /extensions | |
parent | 4dcd3f46599a8c702fca4b13e4370a0ec7f66ffd (diff) | |
download | phosphor-logging-677381b8fc84d49923cf49ab9e2fe6f520f19767.tar.gz phosphor-logging-677381b8fc84d49923cf49ab9e2fe6f520f19767.zip |
PEL: Save BMC Version ID in UserData section
When creating a PEL, save the VERSION_ID value from the /etc/os-release
file in the UserData section that keeps useful system information.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I6d9008b15c5347239bf8c21ef79219d3b6ee08e6
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/openpower-pels/data_interface.cpp | 30 | ||||
-rw-r--r-- | extensions/openpower-pels/data_interface.hpp | 21 | ||||
-rw-r--r-- | extensions/openpower-pels/pel.cpp | 17 |
3 files changed, 62 insertions, 6 deletions
diff --git a/extensions/openpower-pels/data_interface.cpp b/extensions/openpower-pels/data_interface.cpp index 6ad8b6e..3342569 100644 --- a/extensions/openpower-pels/data_interface.cpp +++ b/extensions/openpower-pels/data_interface.cpp @@ -55,6 +55,7 @@ DataInterface::DataInterface(sdbusplus::bus::bus& bus) : _bus(bus) readHostState(); readBMCFWVersion(); readServerFWVersion(); + readBMCFWVersionID(); } void DataInterface::readMTMS() @@ -244,21 +245,35 @@ uint8_t DataInterface::getPLDMInstanceID(uint8_t eid) const #endif } -void DataInterface::readBMCFWVersion() +/** + * @brief Return a value found in the /etc/os-release file + * + * @param[in] key - The key name, like "VERSION" + * + * @return std::optional<std::string> - The value + */ +std::optional<std::string> getOSReleaseValue(const std::string& key) { std::ifstream versionFile{BMC_VERSION_FILE}; std::string line; - static const auto versionID = "VERSION="; + std::string keyPattern{key + '='}; while (std::getline(versionFile, line)) { - if (line.find(versionID) != std::string::npos) + if (line.find(keyPattern) != std::string::npos) { auto pos = line.find_first_of('"') + 1; - _bmcFWVersion = line.substr(pos, line.find_last_of('"') - pos); - break; + auto value = line.substr(pos, line.find_last_of('"') - pos); + return value; } } + + return std::nullopt; +} + +void DataInterface::readBMCFWVersion() +{ + _bmcFWVersion = getOSReleaseValue("VERSION").value_or(""); } void DataInterface::readServerFWVersion() @@ -266,5 +281,10 @@ void DataInterface::readServerFWVersion() // Not available yet } +void DataInterface::readBMCFWVersionID() +{ + _bmcFWVersionID = getOSReleaseValue("VERSION_ID").value_or(""); +} + } // namespace pels } // namespace openpower diff --git a/extensions/openpower-pels/data_interface.hpp b/extensions/openpower-pels/data_interface.hpp index e690542..e139c07 100644 --- a/extensions/openpower-pels/data_interface.hpp +++ b/extensions/openpower-pels/data_interface.hpp @@ -137,6 +137,16 @@ class DataInterfaceBase } /** + * @brief Returns the BMC FW version ID + * + * @return std::string - The BMC FW version ID + */ + virtual std::string getBMCFWVersionID() const + { + return _bmcFWVersionID; + } + + /** * @brief Returns the process name given its PID. * * @param[in] pid - The PID value as a string @@ -221,6 +231,11 @@ class DataInterfaceBase * @brief The server firmware version string */ std::string _serverFWVersion; + + /** + * @brief The BMC firmware version ID string + */ + std::string _bmcFWVersionID; }; /** @@ -291,6 +306,12 @@ class DataInterface : public DataInterfaceBase void readServerFWVersion(); /** + * @brief Reads the BMC firmware version ID and puts it into + * _bmcFWVersionID. + */ + void readBMCFWVersionID(); + + /** * @brief Finds the D-Bus service name that hosts the * passed in path and interface. * diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp index 0c05ac1..e560d5e 100644 --- a/extensions/openpower-pels/pel.cpp +++ b/extensions/openpower-pels/pel.cpp @@ -37,6 +37,8 @@ namespace pels namespace message = openpower::pels::message; namespace pv = openpower::pels::pel_values; +constexpr auto unknownValue = "Unknown"; + PEL::PEL(const message::Entry& entry, uint32_t obmcLogID, uint64_t timestamp, phosphor::logging::Entry::Level severity, const AdditionalData& additionalData, @@ -343,7 +345,7 @@ void addProcessNameToJSON(nlohmann::json& json, const std::optional<std::string>& pid, const DataInterfaceBase& dataIface) { - std::string name = "Unknown"; + std::string name{unknownValue}; try { @@ -363,6 +365,18 @@ void addProcessNameToJSON(nlohmann::json& json, json["Process Name"] = std::move(name); } +void addBMCFWVersionIDToJSON(nlohmann::json& json, + const DataInterfaceBase& dataIface) +{ + auto id = dataIface.getBMCFWVersionID(); + if (id.empty()) + { + id = unknownValue; + } + + json["BMC Version ID"] = std::move(id); +} + std::unique_ptr<UserData> makeSysInfoUserDataSection(const AdditionalData& ad, const DataInterfaceBase& dataIface) @@ -370,6 +384,7 @@ std::unique_ptr<UserData> nlohmann::json json; addProcessNameToJSON(json, ad.getValue("_PID"), dataIface); + addBMCFWVersionIDToJSON(json, dataIface); return makeJSONUserDataSection(json); } |