summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels/manager.cpp
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-07-17 13:54:30 -0500
committerMatt Spinler <spinler@us.ibm.com>2019-08-05 12:49:54 -0500
commit89fa082a68c975128db6fa96eab33200c6bc7bb6 (patch)
tree30ef8f010c8431536b631c47fa54bab43ecc2f51 /extensions/openpower-pels/manager.cpp
parentcb6b059eec52ddfe099221de003d7dca86ce1db0 (diff)
downloadphosphor-logging-89fa082a68c975128db6fa96eab33200c6bc7bb6.tar.gz
phosphor-logging-89fa082a68c975128db6fa96eab33200c6bc7bb6.zip
PEL: Add repository to save PELs
Create the Repository class that can save PELs in (and later retrieve them from) the filesystem. It provides an add() method that can add a PEL object to the repository. Now, when the Manager class sees an OpenBMC event log created with the RAWPEL metadata in the AdditionalData property that points at a file that contains a PEL, it can save that PEL. Before the PEL is saved, the log ID and commit timestamp fields in the PEL will be updated - the log ID to a unique value, and the timestamp to the current time. Change-Id: I8dbaddf0f155bcb6d40b933294ada83feb75ce53
Diffstat (limited to 'extensions/openpower-pels/manager.cpp')
-rw-r--r--extensions/openpower-pels/manager.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/extensions/openpower-pels/manager.cpp b/extensions/openpower-pels/manager.cpp
index 3e22336..a009188 100644
--- a/extensions/openpower-pels/manager.cpp
+++ b/extensions/openpower-pels/manager.cpp
@@ -1,6 +1,10 @@
#include "manager.hpp"
#include "additional_data.hpp"
+#include "pel.hpp"
+
+#include <filesystem>
+#include <fstream>
namespace openpower
{
@@ -8,6 +12,7 @@ namespace pels
{
using namespace phosphor::logging;
+namespace fs = std::filesystem;
namespace additional_data
{
@@ -36,6 +41,55 @@ void Manager::create(const std::string& message, uint32_t obmcLogID,
void Manager::addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID)
{
+ if (fs::exists(rawPelPath))
+ {
+ std::ifstream file(rawPelPath, std::ios::in | std::ios::binary);
+
+ auto data = std::vector<uint8_t>(std::istreambuf_iterator<char>(file),
+ std::istreambuf_iterator<char>());
+ if (file.fail())
+ {
+ log<level::ERR>("Filesystem error reading a raw PEL",
+ entry("PELFILE=%s", rawPelPath.c_str()),
+ entry("OBMCLOGID=%d", obmcLogID));
+ // TODO, Decide what to do here. Maybe nothing.
+ return;
+ }
+
+ file.close();
+
+ auto pel = std::make_unique<PEL>(data, obmcLogID);
+ if (pel->valid())
+ {
+ // PELs created by others still need these fields set by us.
+ pel->assignID();
+ pel->setCommitTime();
+
+ try
+ {
+ _repo.add(pel);
+ }
+ catch (std::exception& e)
+ {
+ // Probably a full or r/o filesystem, not much we can do.
+ log<level::ERR>("Unable to add PEL to Repository",
+ entry("PEL_ID=0x%X", pel->id()));
+ }
+ }
+ else
+ {
+ log<level::ERR>("Invalid PEL found",
+ entry("PELFILE=%s", rawPelPath.c_str()),
+ entry("OBMCLOGID=%d", obmcLogID));
+ // TODO, make a whole new OpenBMC event log + PEL
+ }
+ }
+ else
+ {
+ log<level::ERR>("Raw PEL file from BMC event log does not exist",
+ entry("PELFILE=%s", (rawPelPath).c_str()),
+ entry("OBMCLOGID=%d", obmcLogID));
+ }
}
void Manager::erase(uint32_t obmcLogID)
OpenPOWER on IntegriCloud