blob: fcea8af2cd7274f890720718f1ae7e9e3b4178b7 [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Aatir7b291ec2019-11-19 10:37:37 -060016#include "config.h"
17
18#include "../bcd_time.hpp"
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +080019#include "../json_utils.hpp"
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +080020#include "../paths.hpp"
Aatir186ce8c2019-10-20 15:13:39 -050021#include "../pel.hpp"
Aatir7b291ec2019-11-19 10:37:37 -060022#include "../pel_types.hpp"
23#include "../pel_values.hpp"
Aatir186ce8c2019-10-20 15:13:39 -050024
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +080025#include <Python.h>
26
Aatir186ce8c2019-10-20 15:13:39 -050027#include <CLI/CLI.hpp>
Aatir7b291ec2019-11-19 10:37:37 -060028#include <bitset>
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +080029#include <fstream>
Aatir186ce8c2019-10-20 15:13:39 -050030#include <iostream>
Aatir7b291ec2019-11-19 10:37:37 -060031#include <phosphor-logging/log.hpp>
32#include <regex>
Aatir186ce8c2019-10-20 15:13:39 -050033#include <string>
Aatir7b291ec2019-11-19 10:37:37 -060034#include <xyz/openbmc_project/Common/File/error.hpp>
Aatir186ce8c2019-10-20 15:13:39 -050035
William A. Kennington IIIb6b25572021-05-19 17:09:41 -070036#include "config_main.h"
37
Aatir7b291ec2019-11-19 10:37:37 -060038namespace fs = std::filesystem;
Aatir186ce8c2019-10-20 15:13:39 -050039using namespace phosphor::logging;
40using namespace openpower::pels;
Matt Spinler27de6f32020-02-21 08:35:57 -060041using sdbusplus::exception::SdBusError;
Aatir7b291ec2019-11-19 10:37:37 -060042namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error;
43namespace message = openpower::pels::message;
44namespace pv = openpower::pels::pel_values;
Aatir186ce8c2019-10-20 15:13:39 -050045
Miguel Gomez011ccae2021-03-25 23:42:09 +000046const uint8_t critSysTermSeverity = 0x51;
47
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +080048using PELFunc = std::function<void(const PEL&, bool hexDump)>;
Matt Spinler0d804ef2020-05-12 16:16:26 -050049message::Registry registry(getPELReadOnlyDataPath() / message::registryFileName,
Matt Spinlerd8e29002020-04-09 09:11:22 -050050 false);
Matt Spinler27de6f32020-02-21 08:35:57 -060051namespace service
52{
53constexpr auto logging = "xyz.openbmc_project.Logging";
54} // namespace service
55
56namespace interface
57{
58constexpr auto deleteObj = "xyz.openbmc_project.Object.Delete";
59constexpr auto deleteAll = "xyz.openbmc_project.Collection.DeleteAll";
60} // namespace interface
61
62namespace object_path
63{
64constexpr auto logEntry = "/xyz/openbmc_project/logging/entry/";
65constexpr auto logging = "/xyz/openbmc_project/logging";
66} // namespace object_path
67
William A. Kennington IIIb6b25572021-05-19 17:09:41 -070068std::string pelLogDir()
69{
70 return std::string(EXTENSION_PERSIST_DIR) + "/pels/logs";
71}
72
Aatire340c132019-12-09 14:19:29 -060073/**
Aatir37822f62019-12-10 14:40:27 -060074 * @brief helper function to get PEL commit timestamp from file name
75 * @retrun BCDTime - PEL commit timestamp
76 * @param[in] std::string - file name
77 */
78BCDTime fileNameToTimestamp(const std::string& fileName)
79{
80 std::string token = fileName.substr(0, fileName.find("_"));
81 int i = 0;
82 BCDTime tmp;
83 if (token.length() >= 14)
84 {
85 try
86 {
Sumit Kumara1e40842021-06-23 09:52:25 -050087 tmp.yearMSB = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -060088 }
89 catch (std::exception& err)
90 {
91 std::cout << "Conversion failure: " << err.what() << std::endl;
92 }
93 i += 2;
94 try
95 {
Sumit Kumara1e40842021-06-23 09:52:25 -050096 tmp.yearLSB = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -060097 }
98 catch (std::exception& err)
99 {
100 std::cout << "Conversion failure: " << err.what() << std::endl;
101 }
102 i += 2;
103 try
104 {
Sumit Kumara1e40842021-06-23 09:52:25 -0500105 tmp.month = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -0600106 }
107 catch (std::exception& err)
108 {
109 std::cout << "Conversion failure: " << err.what() << std::endl;
110 }
111 i += 2;
112 try
113 {
Sumit Kumara1e40842021-06-23 09:52:25 -0500114 tmp.day = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -0600115 }
116 catch (std::exception& err)
117 {
118 std::cout << "Conversion failure: " << err.what() << std::endl;
119 }
120 i += 2;
121 try
122 {
Sumit Kumara1e40842021-06-23 09:52:25 -0500123 tmp.hour = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -0600124 }
125 catch (std::exception& err)
126 {
127 std::cout << "Conversion failure: " << err.what() << std::endl;
128 }
129 i += 2;
130 try
131 {
Sumit Kumara1e40842021-06-23 09:52:25 -0500132 tmp.minutes = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -0600133 }
134 catch (std::exception& err)
135 {
136 std::cout << "Conversion failure: " << err.what() << std::endl;
137 }
138 i += 2;
139 try
140 {
Sumit Kumara1e40842021-06-23 09:52:25 -0500141 tmp.seconds = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -0600142 }
143 catch (std::exception& err)
144 {
145 std::cout << "Conversion failure: " << err.what() << std::endl;
146 }
147 i += 2;
148 try
149 {
Sumit Kumara1e40842021-06-23 09:52:25 -0500150 tmp.hundredths = std::stoul(token.substr(i, 2), 0, 16);
Aatir37822f62019-12-10 14:40:27 -0600151 }
152 catch (std::exception& err)
153 {
154 std::cout << "Conversion failure: " << err.what() << std::endl;
155 }
156 }
157 return tmp;
158}
159
160/**
161 * @brief helper function to get PEL id from file name
162 * @retrun uint32_t - PEL id
163 * @param[in] std::string - file name
164 */
165uint32_t fileNameToPELId(const std::string& fileName)
166{
167 uint32_t num = 0;
168 try
169 {
Sumit Kumara1e40842021-06-23 09:52:25 -0500170 num = std::stoul(fileName.substr(fileName.find("_") + 1), 0, 16);
Aatir37822f62019-12-10 14:40:27 -0600171 }
172 catch (std::exception& err)
173 {
174 std::cout << "Conversion failure: " << err.what() << std::endl;
175 }
176 return num;
177}
178
179/**
Aatire340c132019-12-09 14:19:29 -0600180 * @brief helper function to check string suffix
181 * @retrun bool - true with suffix matches
182 * @param[in] std::string - string to check for suffix
183 * @param[in] std::string - suffix string
184 */
185bool ends_with(const std::string& str, const std::string& end)
186{
187 size_t slen = str.size(), elen = end.size();
188 if (slen < elen)
189 return false;
190 while (elen)
191 {
192 if (str[--slen] != end[--elen])
193 return false;
194 }
195 return true;
196}
197
Aatir37822f62019-12-10 14:40:27 -0600198/**
199 * @brief get data form raw PEL file.
200 * @param[in] std::string Name of file with raw PEL
201 * @return std::vector<uint8_t> char vector read from raw PEL file.
202 */
Aatirbad5f8a2019-12-10 15:27:16 -0600203std::vector<uint8_t> getFileData(const std::string& name)
Aatir37822f62019-12-10 14:40:27 -0600204{
205 std::ifstream file(name, std::ifstream::in);
206 if (file.good())
207 {
208 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
209 std::istreambuf_iterator<char>()};
210 return data;
211 }
212 else
213 {
Aatir37822f62019-12-10 14:40:27 -0600214 return {};
215 }
216}
217
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800218/**
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800219 * @brief Initialize Python interpreter and gather all UD parser modules under
220 * the paths found in Python sys.path and the current user directory.
221 * This is to prevent calling a non-existant module which causes Python
222 * to print an import error message and breaking JSON output.
223 *
224 * @return std::vector<std::string> Vector of plugins found in filesystem
225 */
226std::vector<std::string> getPlugins()
227{
228 Py_Initialize();
229 std::vector<std::string> plugins;
230 std::vector<std::string> siteDirs;
Harisuddin Mohamed Isac8d6cc62020-08-19 22:47:19 +0800231 std::array<std::string, 2> parserDirs = {"udparsers", "srcparsers"};
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800232 PyObject* pName = PyUnicode_FromString("sys");
233 PyObject* pModule = PyImport_Import(pName);
234 Py_XDECREF(pName);
235 PyObject* pDict = PyModule_GetDict(pModule);
236 Py_XDECREF(pModule);
237 PyObject* pResult = PyDict_GetItemString(pDict, "path");
238 PyObject* pValue = PyUnicode_FromString(".");
239 PyList_Append(pResult, pValue);
240 Py_XDECREF(pValue);
241 auto list_size = PyList_Size(pResult);
242 for (auto i = 0; i < list_size; i++)
243 {
244 PyObject* item = PyList_GetItem(pResult, i);
245 PyObject* pBytes = PyUnicode_AsEncodedString(item, "utf-8", "~E~");
246 const char* output = PyBytes_AS_STRING(pBytes);
247 Py_XDECREF(pBytes);
248 std::string tmpStr(output);
249 siteDirs.push_back(tmpStr);
250 }
251 for (const auto& dir : siteDirs)
252 {
Harisuddin Mohamed Isac8d6cc62020-08-19 22:47:19 +0800253 for (const auto& parserDir : parserDirs)
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800254 {
Harisuddin Mohamed Isac8d6cc62020-08-19 22:47:19 +0800255 if (fs::exists(dir + "/" + parserDir))
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800256 {
Harisuddin Mohamed Isac8d6cc62020-08-19 22:47:19 +0800257 for (const auto& entry :
258 fs::directory_iterator(dir + "/" + parserDir))
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800259 {
Harisuddin Mohamed Isac8d6cc62020-08-19 22:47:19 +0800260 if (entry.is_directory() and
261 fs::exists(entry.path().string() + "/" +
262 entry.path().stem().string() + ".py"))
263 {
264 plugins.push_back(entry.path().stem());
265 }
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800266 }
267 }
268 }
269 }
270 return plugins;
271}
272
273/**
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800274 * @brief Creates JSON string of a PEL entry if fullPEL is false or prints to
275 * stdout the full PEL in JSON if fullPEL is true
276 * @param[in] itr - std::map iterator of <uint32_t, BCDTime>
277 * @param[in] hidden - Boolean to include hidden PELs
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800278 * @param[in] includeInfo - Boolean to include informational PELs
Miguel Gomez011ccae2021-03-25 23:42:09 +0000279 * @param[in] critSysTerm - Boolean to include critical error and system
280 * termination PELs
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800281 * @param[in] fullPEL - Boolean to print full JSON representation of PEL
282 * @param[in] foundPEL - Boolean to check if any PEL is present
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800283 * @param[in] scrubRegex - SRC regex object
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800284 * @param[in] plugins - Vector of strings of plugins found in filesystem
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800285 * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800286 * @return std::string - JSON string of PEL entry (empty if fullPEL is true)
287 */
Aatir7b291ec2019-11-19 10:37:37 -0600288template <typename T>
Miguel Gomez011ccae2021-03-25 23:42:09 +0000289std::string genPELJSON(T itr, bool hidden, bool includeInfo, bool critSysTerm,
290 bool fullPEL, bool& foundPEL,
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800291 const std::optional<std::regex>& scrubRegex,
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800292 const std::vector<std::string>& plugins, bool hexDump)
Aatir7b291ec2019-11-19 10:37:37 -0600293{
294 std::size_t found;
295 std::string val;
296 char tmpValStr[50];
297 std::string listStr;
William A. Kennington IIIb6b25572021-05-19 17:09:41 -0700298 char name[51];
299 sprintf(name, "/%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X_%.8X", itr.second.yearMSB,
Aatir7b291ec2019-11-19 10:37:37 -0600300 itr.second.yearLSB, itr.second.month, itr.second.day,
301 itr.second.hour, itr.second.minutes, itr.second.seconds,
302 itr.second.hundredths, itr.first);
William A. Kennington IIIb6b25572021-05-19 17:09:41 -0700303 auto fileName = pelLogDir() + name;
Aatir7b291ec2019-11-19 10:37:37 -0600304 try
305 {
Aatir37822f62019-12-10 14:40:27 -0600306 std::vector<uint8_t> data = getFileData(fileName);
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800307 if (data.empty())
Aatir37822f62019-12-10 14:40:27 -0600308 {
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800309 log<level::ERR>("Empty PEL file",
310 entry("FILENAME=%s", fileName.c_str()));
311 return listStr;
312 }
313 PEL pel{data};
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800314 if (!pel.valid())
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800315 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800316 return listStr;
317 }
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800318 if (!includeInfo && pel.userHeader().severity() == 0)
319 {
320 return listStr;
321 }
Miguel Gomez011ccae2021-03-25 23:42:09 +0000322 if (critSysTerm && pel.userHeader().severity() != critSysTermSeverity)
323 {
324 return listStr;
325 }
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800326 std::bitset<16> actionFlags{pel.userHeader().actionFlags()};
327 if (!hidden && actionFlags.test(hiddenFlagBit))
328 {
329 return listStr;
330 }
331 if (pel.primarySRC() && scrubRegex)
332 {
333 val = pel.primarySRC().value()->asciiString();
334 if (std::regex_search(trimEnd(val), scrubRegex.value(),
335 std::regex_constants::match_not_null))
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800336 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800337 return listStr;
338 }
339 }
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800340 if (hexDump)
341 {
342 std::cout << dumpHex(std::data(pel.data()), pel.size(), 0, false)
343 << std::endl;
344 }
345 else if (fullPEL)
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800346 {
347 if (!foundPEL)
348 {
349 std::cout << "[\n";
350 foundPEL = true;
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800351 }
352 else
Aatir7b291ec2019-11-19 10:37:37 -0600353 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800354 std::cout << ",\n\n";
355 }
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800356 pel.toJSON(registry, plugins);
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800357 }
358 else
359 {
360 // id
Matt Spinler3025d0b2021-06-02 15:12:52 -0600361 listStr += " \"" +
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800362 getNumberString("0x%X", pel.privateHeader().id()) +
363 "\": {\n";
364 // ASCII
365 if (pel.primarySRC())
366 {
367 val = pel.primarySRC().value()->asciiString();
Matt Spinler3025d0b2021-06-02 15:12:52 -0600368 jsonInsert(listStr, "SRC", trimEnd(val), 2);
369
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800370 // Registry message
371 auto regVal = pel.primarySRC().value()->getErrorDetails(
372 registry, DetailLevel::message, true);
373 if (regVal)
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800374 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800375 val = regVal.value();
Matt Spinler3025d0b2021-06-02 15:12:52 -0600376 jsonInsert(listStr, "Message", val, 2);
Aatir37822f62019-12-10 14:40:27 -0600377 }
Aatir7b291ec2019-11-19 10:37:37 -0600378 }
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800379 else
380 {
Matt Spinler3025d0b2021-06-02 15:12:52 -0600381 jsonInsert(listStr, "SRC", "No SRC", 2);
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800382 }
Matt Spinler3025d0b2021-06-02 15:12:52 -0600383
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800384 // platformid
Matt Spinler3025d0b2021-06-02 15:12:52 -0600385 jsonInsert(listStr, "PLID",
386 getNumberString("0x%X", pel.privateHeader().plid()), 2);
387
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800388 // creatorid
389 std::string creatorID =
390 getNumberString("%c", pel.privateHeader().creatorID());
391 val = pv::creatorIDs.count(creatorID) ? pv::creatorIDs.at(creatorID)
392 : "Unknown Creator ID";
Matt Spinler3025d0b2021-06-02 15:12:52 -0600393 jsonInsert(listStr, "CreatorID", val, 2);
394
395 // subsystem
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800396 std::string subsystem = pv::getValue(pel.userHeader().subsystem(),
397 pel_values::subsystemValues);
Matt Spinler3025d0b2021-06-02 15:12:52 -0600398 jsonInsert(listStr, "Subsystem", subsystem, 2);
399
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800400 // commit time
401 sprintf(tmpValStr, "%02X/%02X/%02X%02X %02X:%02X:%02X",
402 pel.privateHeader().commitTimestamp().month,
403 pel.privateHeader().commitTimestamp().day,
404 pel.privateHeader().commitTimestamp().yearMSB,
405 pel.privateHeader().commitTimestamp().yearLSB,
406 pel.privateHeader().commitTimestamp().hour,
407 pel.privateHeader().commitTimestamp().minutes,
408 pel.privateHeader().commitTimestamp().seconds);
Matt Spinler3025d0b2021-06-02 15:12:52 -0600409 jsonInsert(listStr, "Commit Time", tmpValStr, 2);
410
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800411 // severity
412 std::string severity = pv::getValue(pel.userHeader().severity(),
413 pel_values::severityValues);
Matt Spinler3025d0b2021-06-02 15:12:52 -0600414 jsonInsert(listStr, "Sev", severity, 2);
415
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800416 // compID
Matt Spinler3025d0b2021-06-02 15:12:52 -0600417 jsonInsert(listStr, "CompID",
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800418 getNumberString(
Matt Spinler3025d0b2021-06-02 15:12:52 -0600419 "0x%X", pel.privateHeader().header().componentID),
420 2);
421
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800422 found = listStr.rfind(",");
423 if (found != std::string::npos)
424 {
425 listStr.replace(found, 1, "");
Matt Spinler3025d0b2021-06-02 15:12:52 -0600426 listStr += " },\n";
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800427 }
428 foundPEL = true;
Aatir7b291ec2019-11-19 10:37:37 -0600429 }
430 }
431 catch (std::exception& e)
432 {
433 log<level::ERR>("Hit exception while reading PEL File",
434 entry("FILENAME=%s", fileName.c_str()),
435 entry("ERROR=%s", e.what()));
436 }
437 return listStr;
438}
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800439
Aatir7b291ec2019-11-19 10:37:37 -0600440/**
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800441 * @brief Print a list of PELs or a JSON array of PELs
442 * @param[in] order - Boolean to print in reverse orser
443 * @param[in] hidden - Boolean to include hidden PELs
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800444 * @param[in] includeInfo - Boolean to include informational PELs
Miguel Gomez011ccae2021-03-25 23:42:09 +0000445 * @param[in] critSysTerm - Boolean to include critical error and system
446 * termination PELs
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800447 * @param[in] fullPEL - Boolean to print full PEL into a JSON array
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800448 * @param[in] scrubRegex - SRC regex object
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800449 * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON
Aatir7b291ec2019-11-19 10:37:37 -0600450 */
Miguel Gomez011ccae2021-03-25 23:42:09 +0000451void printPELs(bool order, bool hidden, bool includeInfo, bool critSysTerm,
452 bool fullPEL, const std::optional<std::regex>& scrubRegex,
453 bool hexDump)
Aatir7b291ec2019-11-19 10:37:37 -0600454{
455 std::string listStr;
456 std::map<uint32_t, BCDTime> PELs;
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800457 std::vector<std::string> plugins;
Aatir7b291ec2019-11-19 10:37:37 -0600458 listStr = "{\n";
William A. Kennington IIIb6b25572021-05-19 17:09:41 -0700459 for (auto it = fs::directory_iterator(pelLogDir());
Aatir7b291ec2019-11-19 10:37:37 -0600460 it != fs::directory_iterator(); ++it)
461 {
462 if (!fs::is_regular_file((*it).path()))
463 {
464 continue;
465 }
Aatir37822f62019-12-10 14:40:27 -0600466 else
Aatir7b291ec2019-11-19 10:37:37 -0600467 {
Aatir37822f62019-12-10 14:40:27 -0600468 PELs.emplace(fileNameToPELId((*it).path().filename()),
469 fileNameToTimestamp((*it).path().filename()));
Aatir7b291ec2019-11-19 10:37:37 -0600470 }
471 }
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800472 bool foundPEL = false;
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800473
474 if (fullPEL && !hexDump)
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800475 {
476 plugins = getPlugins();
477 }
Miguel Gomez011ccae2021-03-25 23:42:09 +0000478 auto buildJSON = [&listStr, &hidden, &includeInfo, &critSysTerm, &fullPEL,
479 &foundPEL, &scrubRegex, &plugins,
480 &hexDump](const auto& i) {
481 listStr += genPELJSON(i, hidden, includeInfo, critSysTerm, fullPEL,
482 foundPEL, scrubRegex, plugins, hexDump);
Aatir37822f62019-12-10 14:40:27 -0600483 };
Aatir7b291ec2019-11-19 10:37:37 -0600484 if (order)
485 {
486 std::for_each(PELs.rbegin(), PELs.rend(), buildJSON);
487 }
488 else
489 {
490 std::for_each(PELs.begin(), PELs.end(), buildJSON);
491 }
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800492 if (hexDump)
493 {
494 return;
495 }
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800496 if (foundPEL)
Aatir7b291ec2019-11-19 10:37:37 -0600497 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800498 if (fullPEL)
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800499 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800500 std::cout << "]" << std::endl;
501 }
502 else
503 {
504 std::size_t found;
505 found = listStr.rfind(",");
506 if (found != std::string::npos)
507 {
508 listStr.replace(found, 1, "");
509 listStr += "}\n";
510 printf("%s", listStr.c_str());
511 }
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800512 }
513 }
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800514 else
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800515 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800516 std::string emptyJSON = fullPEL ? "[]" : "{}";
517 std::cout << emptyJSON << std::endl;
Aatir7b291ec2019-11-19 10:37:37 -0600518 }
519}
Aatir186ce8c2019-10-20 15:13:39 -0500520
Matt Spinler27de6f32020-02-21 08:35:57 -0600521/**
522 * @brief Calls the function passed in on the PEL with the ID
523 * passed in.
524 *
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800525 * @param[in] id - The string version of the PEL or BMC Log ID, either with or
Matt Spinler27de6f32020-02-21 08:35:57 -0600526 * without the 0x prefix.
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800527 * @param[in] func - The std::function<void(const PEL&, bool hexDump)> function
528 * to run.
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800529 * @param[in] useBMC - if true, search by BMC Log ID, else search by PEL ID
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800530 * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON
Matt Spinler27de6f32020-02-21 08:35:57 -0600531 */
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800532void callFunctionOnPEL(const std::string& id, const PELFunc& func,
533 bool useBMC = false, bool hexDump = false)
Matt Spinler27de6f32020-02-21 08:35:57 -0600534{
535 std::string pelID{id};
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800536 if (!useBMC)
Matt Spinler27de6f32020-02-21 08:35:57 -0600537 {
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800538 std::transform(pelID.begin(), pelID.end(), pelID.begin(), toupper);
539
540 if (pelID.find("0X") == 0)
541 {
542 pelID.erase(0, 2);
543 }
Matt Spinler27de6f32020-02-21 08:35:57 -0600544 }
545
546 bool found = false;
547
William A. Kennington IIIb6b25572021-05-19 17:09:41 -0700548 for (auto it = fs::directory_iterator(pelLogDir());
Matt Spinler27de6f32020-02-21 08:35:57 -0600549 it != fs::directory_iterator(); ++it)
550 {
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800551 // The PEL ID is part of the filename, so use that to find the PEL if
552 // "useBMC" is set to false, otherwise we have to search within the PEL
Matt Spinler27de6f32020-02-21 08:35:57 -0600553
554 if (!fs::is_regular_file((*it).path()))
555 {
556 continue;
557 }
558
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800559 if ((ends_with((*it).path(), pelID) && !useBMC) || useBMC)
Matt Spinler27de6f32020-02-21 08:35:57 -0600560 {
Matt Spinler27de6f32020-02-21 08:35:57 -0600561 auto data = getFileData((*it).path());
562 if (!data.empty())
563 {
564 PEL pel{data};
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800565 if (!useBMC ||
566 (useBMC && pel.obmcLogID() == std::stoul(id, nullptr, 0)))
Matt Spinler27de6f32020-02-21 08:35:57 -0600567 {
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800568 found = true;
569 try
570 {
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800571 func(pel, hexDump);
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800572 break;
573 }
574 catch (std::exception& e)
575 {
576 std::cerr << " Internal function threw an exception: "
577 << e.what() << "\n";
578 exit(1);
579 }
Matt Spinler27de6f32020-02-21 08:35:57 -0600580 }
581 }
582 else
583 {
584 std::cerr << "Could not read PEL file\n";
585 exit(1);
586 }
Matt Spinler27de6f32020-02-21 08:35:57 -0600587 }
588 }
589
590 if (!found)
591 {
592 std::cerr << "PEL not found\n";
593 exit(1);
594 }
595}
596
597/**
Matt Spinler25d986c2021-02-10 13:26:18 -0600598 * @brief Delete a PEL file.
Matt Spinler27de6f32020-02-21 08:35:57 -0600599 *
Matt Spinler25d986c2021-02-10 13:26:18 -0600600 * @param[in] id - The PEL ID to delete.
Matt Spinler27de6f32020-02-21 08:35:57 -0600601 */
Matt Spinler25d986c2021-02-10 13:26:18 -0600602void deletePEL(const std::string& id)
Matt Spinler27de6f32020-02-21 08:35:57 -0600603{
Matt Spinler25d986c2021-02-10 13:26:18 -0600604 std::string pelID{id};
Matt Spinler27de6f32020-02-21 08:35:57 -0600605
Matt Spinler25d986c2021-02-10 13:26:18 -0600606 std::transform(pelID.begin(), pelID.end(), pelID.begin(), toupper);
607
608 if (pelID.find("0X") == 0)
Matt Spinler27de6f32020-02-21 08:35:57 -0600609 {
Matt Spinler25d986c2021-02-10 13:26:18 -0600610 pelID.erase(0, 2);
Matt Spinler27de6f32020-02-21 08:35:57 -0600611 }
Matt Spinler25d986c2021-02-10 13:26:18 -0600612
William A. Kennington IIIb6b25572021-05-19 17:09:41 -0700613 for (auto it = fs::directory_iterator(pelLogDir());
Matt Spinler25d986c2021-02-10 13:26:18 -0600614 it != fs::directory_iterator(); ++it)
Matt Spinler27de6f32020-02-21 08:35:57 -0600615 {
Matt Spinler25d986c2021-02-10 13:26:18 -0600616 if (ends_with((*it).path(), pelID))
617 {
618 fs::remove((*it).path());
619 }
Matt Spinler27de6f32020-02-21 08:35:57 -0600620 }
621}
622
623/**
Matt Spinler25d986c2021-02-10 13:26:18 -0600624 * @brief Delete all PEL files.
Matt Spinler27de6f32020-02-21 08:35:57 -0600625 */
626void deleteAllPELs()
627{
Matt Spinler25d986c2021-02-10 13:26:18 -0600628 log<level::INFO>("peltool deleting all event logs");
Matt Spinler27de6f32020-02-21 08:35:57 -0600629
William A. Kennington IIIb6b25572021-05-19 17:09:41 -0700630 for (const auto& entry : fs::directory_iterator(pelLogDir()))
Matt Spinler27de6f32020-02-21 08:35:57 -0600631 {
Matt Spinler25d986c2021-02-10 13:26:18 -0600632 fs::remove(entry.path());
Matt Spinler27de6f32020-02-21 08:35:57 -0600633 }
634}
635
Matt Spinler1b420bc2020-02-21 08:54:25 -0600636/**
637 * @brief Display a single PEL
638 *
639 * @param[in] pel - the PEL to display
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800640 * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON
Matt Spinler1b420bc2020-02-21 08:54:25 -0600641 */
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800642void displayPEL(const PEL& pel, bool hexDump)
Matt Spinler1b420bc2020-02-21 08:54:25 -0600643{
644 if (pel.valid())
645 {
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800646 if (hexDump)
647 {
648 std::string dstr =
649 dumpHex(std::data(pel.data()), pel.size(), 0, false);
650 std::cout << dstr << std::endl;
651 }
652 else
653 {
654 auto plugins = getPlugins();
655 pel.toJSON(registry, plugins);
656 }
Matt Spinler1b420bc2020-02-21 08:54:25 -0600657 }
658 else
659 {
660 std::cerr << "PEL was malformed\n";
661 exit(1);
662 }
663}
664
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800665/**
666 * @brief Print number of PELs
667 * @param[in] hidden - Bool to include hidden logs
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800668 * @param[in] includeInfo - Bool to include informational logs
Miguel Gomez011ccae2021-03-25 23:42:09 +0000669 * @param[in] critSysTerm - Bool to include CritSysTerm
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800670 * @param[in] scrubRegex - SRC regex object
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800671 */
Miguel Gomez011ccae2021-03-25 23:42:09 +0000672void printPELCount(bool hidden, bool includeInfo, bool critSysTerm,
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800673 const std::optional<std::regex>& scrubRegex)
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800674{
675 std::size_t count = 0;
William A. Kennington IIIb6b25572021-05-19 17:09:41 -0700676
677 for (auto it = fs::directory_iterator(pelLogDir());
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800678 it != fs::directory_iterator(); ++it)
679 {
680 if (!fs::is_regular_file((*it).path()))
681 {
682 continue;
683 }
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800684 std::vector<uint8_t> data = getFileData((*it).path());
685 if (data.empty())
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800686 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800687 continue;
688 }
689 PEL pel{data};
690 if (!pel.valid())
691 {
692 continue;
693 }
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800694 if (!includeInfo && pel.userHeader().severity() == 0)
695 {
696 continue;
697 }
Miguel Gomez011ccae2021-03-25 23:42:09 +0000698 if (critSysTerm && pel.userHeader().severity() != critSysTermSeverity)
699 {
700 continue;
701 }
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800702 std::bitset<16> actionFlags{pel.userHeader().actionFlags()};
703 if (!hidden && actionFlags.test(hiddenFlagBit))
704 {
705 continue;
706 }
707 if (pel.primarySRC() && scrubRegex)
708 {
709 std::string val = pel.primarySRC().value()->asciiString();
710 if (std::regex_search(trimEnd(val), scrubRegex.value(),
711 std::regex_constants::match_not_null))
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800712 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800713 continue;
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800714 }
715 }
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800716 count++;
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800717 }
718 std::cout << "{\n"
719 << " \"Number of PELs found\": "
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800720 << getNumberString("%d", count) << "\n}\n";
721}
722
723/**
724 * @brief Generate regex pattern object from file contents
725 * @param[in] scrubFile - File containing regex pattern
726 * @return std::regex - SRC regex object
727 */
728std::regex genRegex(std::string& scrubFile)
729{
730 std::string pattern;
731 std::ifstream contents(scrubFile);
732 if (contents.fail())
733 {
734 std::cerr << "Can't open \"" << scrubFile << "\"\n";
735 exit(1);
736 }
737 std::string line;
738 while (std::getline(contents, line))
739 {
740 if (!line.empty())
741 {
742 pattern.append(line + "|");
743 }
744 }
745 try
746 {
747 std::regex scrubRegex(pattern, std::regex::icase);
748 return scrubRegex;
749 }
750 catch (std::regex_error& e)
751 {
752 if (e.code() == std::regex_constants::error_collate)
753 std::cerr << "Invalid collating element request\n";
754 else if (e.code() == std::regex_constants::error_ctype)
755 std::cerr << "Invalid character class\n";
756 else if (e.code() == std::regex_constants::error_escape)
757 std::cerr << "Invalid escape character or trailing escape\n";
758 else if (e.code() == std::regex_constants::error_backref)
759 std::cerr << "Invalid back reference\n";
760 else if (e.code() == std::regex_constants::error_brack)
761 std::cerr << "Mismatched bracket ([ or ])\n";
762 else if (e.code() == std::regex_constants::error_paren)
763 {
764 // to catch return code error_badrepeat when error_paren is retured
765 // instead
766 size_t pos = pattern.find_first_of("*+?{");
767 while (pos != std::string::npos)
768 {
769 if (pos == 0 || pattern.substr(pos - 1, 1) == "|")
770 {
771 std::cerr
772 << "A repetition character (*, ?, +, or {) was not "
773 "preceded by a valid regular expression\n";
774 exit(1);
775 }
776 pos = pattern.find_first_of("*+?{", pos + 1);
777 }
778 std::cerr << "Mismatched parentheses (( or ))\n";
779 }
780 else if (e.code() == std::regex_constants::error_brace)
781 std::cerr << "Mismatched brace ({ or })\n";
782 else if (e.code() == std::regex_constants::error_badbrace)
783 std::cerr << "Invalid range inside a { }\n";
784 else if (e.code() == std::regex_constants::error_range)
785 std::cerr << "Invalid character range (e.g., [z-a])\n";
786 else if (e.code() == std::regex_constants::error_space)
787 std::cerr << "Insufficient memory to handle regular expression\n";
788 else if (e.code() == std::regex_constants::error_badrepeat)
789 std::cerr << "A repetition character (*, ?, +, or {) was not "
790 "preceded by a valid regular expression\n";
791 else if (e.code() == std::regex_constants::error_complexity)
792 std::cerr << "The requested match is too complex\n";
793 else if (e.code() == std::regex_constants::error_stack)
794 std::cerr << "Insufficient memory to evaluate a match\n";
795 exit(1);
796 }
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800797}
798
Aatir186ce8c2019-10-20 15:13:39 -0500799static void exitWithError(const std::string& help, const char* err)
800{
801 std::cerr << "ERROR: " << err << std::endl << help << std::endl;
802 exit(-1);
803}
804
805int main(int argc, char** argv)
806{
807 CLI::App app{"OpenBMC PEL Tool"};
808 std::string fileName;
Aatire340c132019-12-09 14:19:29 -0600809 std::string idPEL;
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800810 std::string bmcId;
Matt Spinler27de6f32020-02-21 08:35:57 -0600811 std::string idToDelete;
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800812 std::string scrubFile;
813 std::optional<std::regex> scrubRegex;
Aatire340c132019-12-09 14:19:29 -0600814 bool listPEL = false;
815 bool listPELDescOrd = false;
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800816 bool hidden = false;
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800817 bool includeInfo = false;
Miguel Gomez011ccae2021-03-25 23:42:09 +0000818 bool critSysTerm = false;
Matt Spinler27de6f32020-02-21 08:35:57 -0600819 bool deleteAll = false;
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800820 bool showPELCount = false;
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800821 bool fullPEL = false;
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800822 bool hexDump = false;
Matt Spinler27de6f32020-02-21 08:35:57 -0600823
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800824 app.set_help_flag("--help", "Print this help message and exit");
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800825 app.add_option("--file", fileName, "Display a PEL using its Raw PEL file");
Aatire340c132019-12-09 14:19:29 -0600826 app.add_option("-i, --id", idPEL, "Display a PEL based on its ID");
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800827 app.add_option("--bmc-id", bmcId,
828 "Display a PEL based on its BMC Event ID");
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800829 app.add_flag("-a", fullPEL, "Display all PELs");
Aatirbad5f8a2019-12-10 15:27:16 -0600830 app.add_flag("-l", listPEL, "List PELs");
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800831 app.add_flag("-n", showPELCount, "Show number of PELs");
Aatir7b291ec2019-11-19 10:37:37 -0600832 app.add_flag("-r", listPELDescOrd, "Reverse order of output");
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800833 app.add_flag("-h", hidden, "Include hidden PELs");
Harisuddin Mohamed Isa0c57a672020-03-27 14:16:28 +0800834 app.add_flag("-f,--info", includeInfo, "Include informational PELs");
Miguel Gomez011ccae2021-03-25 23:42:09 +0000835 app.add_flag("-t, --termination", critSysTerm,
836 "List only critical system terminating PELs");
Matt Spinler27de6f32020-02-21 08:35:57 -0600837 app.add_option("-d, --delete", idToDelete, "Delete a PEL based on its ID");
838 app.add_flag("-D, --delete-all", deleteAll, "Delete all PELs");
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800839 app.add_option("-s, --scrub", scrubFile,
840 "File containing SRC regular expressions to ignore");
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800841 app.add_flag("-x", hexDump, "Display PEL(s) in hexdump instead of JSON");
Matt Spinler27de6f32020-02-21 08:35:57 -0600842
Aatir186ce8c2019-10-20 15:13:39 -0500843 CLI11_PARSE(app, argc, argv);
844
845 if (!fileName.empty())
846 {
847 std::vector<uint8_t> data = getFileData(fileName);
848 if (!data.empty())
849 {
850 PEL pel{data};
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800851 if (hexDump)
852 {
853 std::string dstr =
854 dumpHex(std::data(pel.data()), pel.size(), 0, false);
855 std::cout << dstr << std::endl;
856 }
857 else
858 {
859 auto plugins = getPlugins();
860 pel.toJSON(registry, plugins);
861 }
Aatir186ce8c2019-10-20 15:13:39 -0500862 }
863 else
864 {
865 exitWithError(app.help("", CLI::AppFormatMode::All),
866 "Raw PEL file can't be read.");
867 }
868 }
Aatire340c132019-12-09 14:19:29 -0600869 else if (!idPEL.empty())
870 {
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800871 callFunctionOnPEL(idPEL, displayPEL, false, hexDump);
Harisuddin Mohamed Isa58d3a982020-09-17 19:48:05 +0800872 }
873 else if (!bmcId.empty())
874 {
Harisuddin Mohamed Isaed32c8d2020-10-01 18:12:39 +0800875 callFunctionOnPEL(bmcId, displayPEL, true, hexDump);
Aatire340c132019-12-09 14:19:29 -0600876 }
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800877 else if (fullPEL || listPEL)
Aatir7b291ec2019-11-19 10:37:37 -0600878 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800879 if (!scrubFile.empty())
880 {
881 scrubRegex = genRegex(scrubFile);
882 }
Miguel Gomez011ccae2021-03-25 23:42:09 +0000883 printPELs(listPELDescOrd, hidden, includeInfo, critSysTerm, fullPEL,
884 scrubRegex, hexDump);
Harisuddin Mohamed Isad4002f32020-02-26 16:19:58 +0800885 }
886 else if (showPELCount)
887 {
Harisuddin Mohamed Isa6f005192020-03-10 17:39:53 +0800888 if (!scrubFile.empty())
889 {
890 scrubRegex = genRegex(scrubFile);
891 }
Miguel Gomez011ccae2021-03-25 23:42:09 +0000892 printPELCount(hidden, includeInfo, critSysTerm, scrubRegex);
Aatir7b291ec2019-11-19 10:37:37 -0600893 }
Matt Spinler27de6f32020-02-21 08:35:57 -0600894 else if (!idToDelete.empty())
895 {
Matt Spinler25d986c2021-02-10 13:26:18 -0600896 deletePEL(idToDelete);
Matt Spinler27de6f32020-02-21 08:35:57 -0600897 }
898 else if (deleteAll)
899 {
900 deleteAllPELs();
901 }
Aatir186ce8c2019-10-20 15:13:39 -0500902 else
903 {
Harisuddin Mohamed Isaa214ed32020-02-28 15:58:23 +0800904 std::cout << app.help("", CLI::AppFormatMode::All) << std::endl;
Aatir186ce8c2019-10-20 15:13:39 -0500905 }
Harisuddin Mohamed Isaf67bafd2020-07-06 17:51:21 +0800906 Py_Finalize();
Aatir186ce8c2019-10-20 15:13:39 -0500907 return 0;
908}