PEL: Deleted PELs moved to new folder under logs
- PELs whose corresponding event logs have been deleted
will be available in the archive folder.
- Archive folder size is tracked under sizeWarning() function.
- Archived PELs log can be viewed using peltool with flag --archive.
- PELs deleted using peltool is not archived.
- Updated README.md
Change-Id: Ie2c1b4c2ca30fb79904bc9d582a01ef8102aed0e
Signed-off-by: Sumit Kumar <sumit_kumar@in.ibm.com>
diff --git a/extensions/openpower-pels/tools/peltool.cpp b/extensions/openpower-pels/tools/peltool.cpp
index fcea8af..6dc2ef0 100644
--- a/extensions/openpower-pels/tools/peltool.cpp
+++ b/extensions/openpower-pels/tools/peltool.cpp
@@ -289,7 +289,8 @@
std::string genPELJSON(T itr, bool hidden, bool includeInfo, bool critSysTerm,
bool fullPEL, bool& foundPEL,
const std::optional<std::regex>& scrubRegex,
- const std::vector<std::string>& plugins, bool hexDump)
+ const std::vector<std::string>& plugins, bool hexDump,
+ bool archive)
{
std::size_t found;
std::string val;
@@ -300,7 +301,7 @@
itr.second.yearLSB, itr.second.month, itr.second.day,
itr.second.hour, itr.second.minutes, itr.second.seconds,
itr.second.hundredths, itr.first);
- auto fileName = pelLogDir() + name;
+ auto fileName = (archive ? pelLogDir() + "/archive" : pelLogDir()) + name;
try
{
std::vector<uint8_t> data = getFileData(fileName);
@@ -450,13 +451,14 @@
*/
void printPELs(bool order, bool hidden, bool includeInfo, bool critSysTerm,
bool fullPEL, const std::optional<std::regex>& scrubRegex,
- bool hexDump)
+ bool hexDump, bool archive = false)
{
std::string listStr;
std::map<uint32_t, BCDTime> PELs;
std::vector<std::string> plugins;
listStr = "{\n";
- for (auto it = fs::directory_iterator(pelLogDir());
+ for (auto it = (archive ? fs::directory_iterator(pelLogDir() + "/archive")
+ : fs::directory_iterator(pelLogDir()));
it != fs::directory_iterator(); ++it)
{
if (!fs::is_regular_file((*it).path()))
@@ -469,6 +471,7 @@
fileNameToTimestamp((*it).path().filename()));
}
}
+
bool foundPEL = false;
if (fullPEL && !hexDump)
@@ -476,10 +479,10 @@
plugins = getPlugins();
}
auto buildJSON = [&listStr, &hidden, &includeInfo, &critSysTerm, &fullPEL,
- &foundPEL, &scrubRegex, &plugins,
- &hexDump](const auto& i) {
+ &foundPEL, &scrubRegex, &plugins, &hexDump,
+ &archive](const auto& i) {
listStr += genPELJSON(i, hidden, includeInfo, critSysTerm, fullPEL,
- foundPEL, scrubRegex, plugins, hexDump);
+ foundPEL, scrubRegex, plugins, hexDump, archive);
};
if (order)
{
@@ -530,7 +533,8 @@
* @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON
*/
void callFunctionOnPEL(const std::string& id, const PELFunc& func,
- bool useBMC = false, bool hexDump = false)
+ bool useBMC = false, bool hexDump = false,
+ bool archive = false)
{
std::string pelID{id};
if (!useBMC)
@@ -545,7 +549,8 @@
bool found = false;
- for (auto it = fs::directory_iterator(pelLogDir());
+ for (auto it = (archive ? fs::directory_iterator(pelLogDir() + "/archive")
+ : fs::directory_iterator(pelLogDir()));
it != fs::directory_iterator(); ++it)
{
// The PEL ID is part of the filename, so use that to find the PEL if
@@ -629,6 +634,10 @@
for (const auto& entry : fs::directory_iterator(pelLogDir()))
{
+ if (!fs::is_regular_file(entry.path()))
+ {
+ continue;
+ }
fs::remove(entry.path());
}
}
@@ -820,6 +829,7 @@
bool showPELCount = false;
bool fullPEL = false;
bool hexDump = false;
+ bool archive = false;
app.set_help_flag("--help", "Print this help message and exit");
app.add_option("--file", fileName, "Display a PEL using its Raw PEL file");
@@ -839,6 +849,7 @@
app.add_option("-s, --scrub", scrubFile,
"File containing SRC regular expressions to ignore");
app.add_flag("-x", hexDump, "Display PEL(s) in hexdump instead of JSON");
+ app.add_flag("--archive", archive, "List or display archived PELs");
CLI11_PARSE(app, argc, argv);
@@ -868,11 +879,11 @@
}
else if (!idPEL.empty())
{
- callFunctionOnPEL(idPEL, displayPEL, false, hexDump);
+ callFunctionOnPEL(idPEL, displayPEL, false, hexDump, archive);
}
else if (!bmcId.empty())
{
- callFunctionOnPEL(bmcId, displayPEL, true, hexDump);
+ callFunctionOnPEL(bmcId, displayPEL, true, hexDump, archive);
}
else if (fullPEL || listPEL)
{
@@ -881,7 +892,7 @@
scrubRegex = genRegex(scrubFile);
}
printPELs(listPELDescOrd, hidden, includeInfo, critSysTerm, fullPEL,
- scrubRegex, hexDump);
+ scrubRegex, hexDump, archive);
}
else if (showPELCount)
{