Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 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 | */ |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
| 18 | #include "../bcd_time.hpp" |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 19 | #include "../json_utils.hpp" |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 20 | #include "../paths.hpp" |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 21 | #include "../pel.hpp" |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 22 | #include "../pel_types.hpp" |
| 23 | #include "../pel_values.hpp" |
Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame^] | 24 | #include "trace.hpp" |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 25 | |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 26 | #include <Python.h> |
Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame^] | 27 | #include <fmt/format.h> |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 28 | |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 29 | #include <CLI/CLI.hpp> |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 30 | #include <bitset> |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 31 | #include <fstream> |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 32 | #include <iostream> |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 33 | #include <regex> |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 34 | #include <string> |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 35 | #include <xyz/openbmc_project/Common/File/error.hpp> |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 36 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 37 | #include "config_main.h" |
| 38 | |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 39 | namespace fs = std::filesystem; |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 40 | using namespace openpower::pels; |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 41 | namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error; |
| 42 | namespace message = openpower::pels::message; |
| 43 | namespace pv = openpower::pels::pel_values; |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 44 | |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 45 | const uint8_t critSysTermSeverity = 0x51; |
| 46 | |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 47 | using PELFunc = std::function<void(const PEL&, bool hexDump)>; |
Matt Spinler | 0d804ef | 2020-05-12 16:16:26 -0500 | [diff] [blame] | 48 | message::Registry registry(getPELReadOnlyDataPath() / message::registryFileName, |
Matt Spinler | d8e2900 | 2020-04-09 09:11:22 -0500 | [diff] [blame] | 49 | false); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 50 | namespace service |
| 51 | { |
| 52 | constexpr auto logging = "xyz.openbmc_project.Logging"; |
| 53 | } // namespace service |
| 54 | |
| 55 | namespace interface |
| 56 | { |
| 57 | constexpr auto deleteObj = "xyz.openbmc_project.Object.Delete"; |
| 58 | constexpr auto deleteAll = "xyz.openbmc_project.Collection.DeleteAll"; |
| 59 | } // namespace interface |
| 60 | |
| 61 | namespace object_path |
| 62 | { |
| 63 | constexpr auto logEntry = "/xyz/openbmc_project/logging/entry/"; |
| 64 | constexpr auto logging = "/xyz/openbmc_project/logging"; |
| 65 | } // namespace object_path |
| 66 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 67 | std::string pelLogDir() |
| 68 | { |
| 69 | return std::string(EXTENSION_PERSIST_DIR) + "/pels/logs"; |
| 70 | } |
| 71 | |
Aatir | e340c13 | 2019-12-09 14:19:29 -0600 | [diff] [blame] | 72 | /** |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 73 | * @brief helper function to get PEL commit timestamp from file name |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 74 | * @retrun uint64_t - PEL commit timestamp |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 75 | * @param[in] std::string - file name |
| 76 | */ |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 77 | uint64_t fileNameToTimestamp(const std::string& fileName) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 78 | { |
| 79 | std::string token = fileName.substr(0, fileName.find("_")); |
| 80 | int i = 0; |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 81 | uint64_t bcdTime = 0; |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 82 | if (token.length() >= 14) |
| 83 | { |
| 84 | try |
| 85 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 86 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 87 | bcdTime |= (static_cast<uint64_t>(tmp) << 56); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 88 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 89 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 90 | { |
| 91 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 92 | } |
| 93 | i += 2; |
| 94 | try |
| 95 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 96 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 97 | bcdTime |= (static_cast<uint64_t>(tmp) << 48); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 98 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 99 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 100 | { |
| 101 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 102 | } |
| 103 | i += 2; |
| 104 | try |
| 105 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 106 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 107 | bcdTime |= (static_cast<uint64_t>(tmp) << 40); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 108 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 109 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 110 | { |
| 111 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 112 | } |
| 113 | i += 2; |
| 114 | try |
| 115 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 116 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 117 | bcdTime |= (static_cast<uint64_t>(tmp) << 32); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 118 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 119 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 120 | { |
| 121 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 122 | } |
| 123 | i += 2; |
| 124 | try |
| 125 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 126 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 127 | bcdTime |= (tmp << 24); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 128 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 129 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 130 | { |
| 131 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 132 | } |
| 133 | i += 2; |
| 134 | try |
| 135 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 136 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 137 | bcdTime |= (tmp << 16); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 138 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 139 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 140 | { |
| 141 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 142 | } |
| 143 | i += 2; |
| 144 | try |
| 145 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 146 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 147 | bcdTime |= (tmp << 8); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 148 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 149 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 150 | { |
| 151 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 152 | } |
| 153 | i += 2; |
| 154 | try |
| 155 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 156 | auto tmp = std::stoul(token.substr(i, 2), 0, 16); |
| 157 | bcdTime |= tmp; |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 158 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 159 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 160 | { |
| 161 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 162 | } |
| 163 | } |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 164 | return bcdTime; |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @brief helper function to get PEL id from file name |
| 169 | * @retrun uint32_t - PEL id |
| 170 | * @param[in] std::string - file name |
| 171 | */ |
| 172 | uint32_t fileNameToPELId(const std::string& fileName) |
| 173 | { |
| 174 | uint32_t num = 0; |
| 175 | try |
| 176 | { |
Sumit Kumar | a1e4084 | 2021-06-23 09:52:25 -0500 | [diff] [blame] | 177 | num = std::stoul(fileName.substr(fileName.find("_") + 1), 0, 16); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 178 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 179 | catch (const std::exception& err) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 180 | { |
| 181 | std::cout << "Conversion failure: " << err.what() << std::endl; |
| 182 | } |
| 183 | return num; |
| 184 | } |
| 185 | |
| 186 | /** |
Aatir | e340c13 | 2019-12-09 14:19:29 -0600 | [diff] [blame] | 187 | * @brief helper function to check string suffix |
| 188 | * @retrun bool - true with suffix matches |
| 189 | * @param[in] std::string - string to check for suffix |
| 190 | * @param[in] std::string - suffix string |
| 191 | */ |
| 192 | bool ends_with(const std::string& str, const std::string& end) |
| 193 | { |
| 194 | size_t slen = str.size(), elen = end.size(); |
| 195 | if (slen < elen) |
| 196 | return false; |
| 197 | while (elen) |
| 198 | { |
| 199 | if (str[--slen] != end[--elen]) |
| 200 | return false; |
| 201 | } |
| 202 | return true; |
| 203 | } |
| 204 | |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 205 | /** |
| 206 | * @brief get data form raw PEL file. |
| 207 | * @param[in] std::string Name of file with raw PEL |
| 208 | * @return std::vector<uint8_t> char vector read from raw PEL file. |
| 209 | */ |
Aatir | bad5f8a | 2019-12-10 15:27:16 -0600 | [diff] [blame] | 210 | std::vector<uint8_t> getFileData(const std::string& name) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 211 | { |
| 212 | std::ifstream file(name, std::ifstream::in); |
| 213 | if (file.good()) |
| 214 | { |
| 215 | std::vector<uint8_t> data{std::istreambuf_iterator<char>(file), |
| 216 | std::istreambuf_iterator<char>()}; |
| 217 | return data; |
| 218 | } |
| 219 | else |
| 220 | { |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 221 | return {}; |
| 222 | } |
| 223 | } |
| 224 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 225 | /** |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 226 | * @brief Initialize Python interpreter and gather all UD parser modules under |
| 227 | * the paths found in Python sys.path and the current user directory. |
| 228 | * This is to prevent calling a non-existant module which causes Python |
| 229 | * to print an import error message and breaking JSON output. |
| 230 | * |
| 231 | * @return std::vector<std::string> Vector of plugins found in filesystem |
| 232 | */ |
| 233 | std::vector<std::string> getPlugins() |
| 234 | { |
| 235 | Py_Initialize(); |
| 236 | std::vector<std::string> plugins; |
| 237 | std::vector<std::string> siteDirs; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 238 | std::array<std::string, 2> parserDirs = {"udparsers", "srcparsers"}; |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 239 | PyObject* pName = PyUnicode_FromString("sys"); |
| 240 | PyObject* pModule = PyImport_Import(pName); |
| 241 | Py_XDECREF(pName); |
| 242 | PyObject* pDict = PyModule_GetDict(pModule); |
| 243 | Py_XDECREF(pModule); |
| 244 | PyObject* pResult = PyDict_GetItemString(pDict, "path"); |
| 245 | PyObject* pValue = PyUnicode_FromString("."); |
| 246 | PyList_Append(pResult, pValue); |
| 247 | Py_XDECREF(pValue); |
| 248 | auto list_size = PyList_Size(pResult); |
| 249 | for (auto i = 0; i < list_size; i++) |
| 250 | { |
| 251 | PyObject* item = PyList_GetItem(pResult, i); |
| 252 | PyObject* pBytes = PyUnicode_AsEncodedString(item, "utf-8", "~E~"); |
| 253 | const char* output = PyBytes_AS_STRING(pBytes); |
| 254 | Py_XDECREF(pBytes); |
| 255 | std::string tmpStr(output); |
| 256 | siteDirs.push_back(tmpStr); |
| 257 | } |
| 258 | for (const auto& dir : siteDirs) |
| 259 | { |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 260 | for (const auto& parserDir : parserDirs) |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 261 | { |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 262 | if (fs::exists(dir + "/" + parserDir)) |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 263 | { |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 264 | for (const auto& entry : |
| 265 | fs::directory_iterator(dir + "/" + parserDir)) |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 266 | { |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 267 | if (entry.is_directory() and |
| 268 | fs::exists(entry.path().string() + "/" + |
| 269 | entry.path().stem().string() + ".py")) |
| 270 | { |
| 271 | plugins.push_back(entry.path().stem()); |
| 272 | } |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | return plugins; |
| 278 | } |
| 279 | |
| 280 | /** |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 281 | * @brief Creates JSON string of a PEL entry if fullPEL is false or prints to |
| 282 | * stdout the full PEL in JSON if fullPEL is true |
| 283 | * @param[in] itr - std::map iterator of <uint32_t, BCDTime> |
| 284 | * @param[in] hidden - Boolean to include hidden PELs |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 285 | * @param[in] includeInfo - Boolean to include informational PELs |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 286 | * @param[in] critSysTerm - Boolean to include critical error and system |
| 287 | * termination PELs |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 288 | * @param[in] fullPEL - Boolean to print full JSON representation of PEL |
| 289 | * @param[in] foundPEL - Boolean to check if any PEL is present |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 290 | * @param[in] scrubRegex - SRC regex object |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 291 | * @param[in] plugins - Vector of strings of plugins found in filesystem |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 292 | * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 293 | * @return std::string - JSON string of PEL entry (empty if fullPEL is true) |
| 294 | */ |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 295 | template <typename T> |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 296 | std::string genPELJSON(T itr, bool hidden, bool includeInfo, bool critSysTerm, |
| 297 | bool fullPEL, bool& foundPEL, |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 298 | const std::optional<std::regex>& scrubRegex, |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 299 | const std::vector<std::string>& plugins, bool hexDump, |
| 300 | bool archive) |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 301 | { |
| 302 | std::size_t found; |
| 303 | std::string val; |
| 304 | char tmpValStr[50]; |
| 305 | std::string listStr; |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 306 | char name[51]; |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 307 | sprintf(name, "/%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X_%.8X", |
| 308 | static_cast<uint8_t>((itr.second >> 56) & 0xFF), |
| 309 | static_cast<uint8_t>((itr.second >> 48) & 0xFF), |
| 310 | static_cast<uint8_t>((itr.second >> 40) & 0xFF), |
| 311 | static_cast<uint8_t>((itr.second >> 32) & 0xFF), |
| 312 | static_cast<uint8_t>((itr.second >> 24) & 0xFF), |
| 313 | static_cast<uint8_t>((itr.second >> 16) & 0xFF), |
| 314 | static_cast<uint8_t>((itr.second >> 8) & 0xFF), |
| 315 | static_cast<uint8_t>(itr.second & 0xFF), itr.first); |
| 316 | |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 317 | auto fileName = (archive ? pelLogDir() + "/archive" : pelLogDir()) + name; |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 318 | try |
| 319 | { |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 320 | std::vector<uint8_t> data = getFileData(fileName); |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 321 | if (data.empty()) |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 322 | { |
Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame^] | 323 | trace::error(fmt::format("Empty PEL file {}", fileName)); |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 324 | return listStr; |
| 325 | } |
| 326 | PEL pel{data}; |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 327 | if (!pel.valid()) |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 328 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 329 | return listStr; |
| 330 | } |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 331 | if (!includeInfo && pel.userHeader().severity() == 0) |
| 332 | { |
| 333 | return listStr; |
| 334 | } |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 335 | if (critSysTerm && pel.userHeader().severity() != critSysTermSeverity) |
| 336 | { |
| 337 | return listStr; |
| 338 | } |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 339 | std::bitset<16> actionFlags{pel.userHeader().actionFlags()}; |
| 340 | if (!hidden && actionFlags.test(hiddenFlagBit)) |
| 341 | { |
| 342 | return listStr; |
| 343 | } |
| 344 | if (pel.primarySRC() && scrubRegex) |
| 345 | { |
| 346 | val = pel.primarySRC().value()->asciiString(); |
| 347 | if (std::regex_search(trimEnd(val), scrubRegex.value(), |
| 348 | std::regex_constants::match_not_null)) |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 349 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 350 | return listStr; |
| 351 | } |
| 352 | } |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 353 | if (hexDump) |
| 354 | { |
| 355 | std::cout << dumpHex(std::data(pel.data()), pel.size(), 0, false) |
| 356 | << std::endl; |
| 357 | } |
| 358 | else if (fullPEL) |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 359 | { |
| 360 | if (!foundPEL) |
| 361 | { |
| 362 | std::cout << "[\n"; |
| 363 | foundPEL = true; |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 364 | } |
| 365 | else |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 366 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 367 | std::cout << ",\n\n"; |
| 368 | } |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 369 | pel.toJSON(registry, plugins); |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 370 | } |
| 371 | else |
| 372 | { |
| 373 | // id |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 374 | listStr += " \"" + |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 375 | getNumberString("0x%X", pel.privateHeader().id()) + |
| 376 | "\": {\n"; |
| 377 | // ASCII |
| 378 | if (pel.primarySRC()) |
| 379 | { |
| 380 | val = pel.primarySRC().value()->asciiString(); |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 381 | jsonInsert(listStr, "SRC", trimEnd(val), 2); |
| 382 | |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 383 | // Registry message |
| 384 | auto regVal = pel.primarySRC().value()->getErrorDetails( |
| 385 | registry, DetailLevel::message, true); |
| 386 | if (regVal) |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 387 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 388 | val = regVal.value(); |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 389 | jsonInsert(listStr, "Message", val, 2); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 390 | } |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 391 | } |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 392 | else |
| 393 | { |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 394 | jsonInsert(listStr, "SRC", "No SRC", 2); |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 395 | } |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 396 | |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 397 | // platformid |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 398 | jsonInsert(listStr, "PLID", |
| 399 | getNumberString("0x%X", pel.privateHeader().plid()), 2); |
| 400 | |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 401 | // creatorid |
| 402 | std::string creatorID = |
| 403 | getNumberString("%c", pel.privateHeader().creatorID()); |
| 404 | val = pv::creatorIDs.count(creatorID) ? pv::creatorIDs.at(creatorID) |
| 405 | : "Unknown Creator ID"; |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 406 | jsonInsert(listStr, "CreatorID", val, 2); |
| 407 | |
| 408 | // subsystem |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 409 | std::string subsystem = pv::getValue(pel.userHeader().subsystem(), |
| 410 | pel_values::subsystemValues); |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 411 | jsonInsert(listStr, "Subsystem", subsystem, 2); |
| 412 | |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 413 | // commit time |
| 414 | sprintf(tmpValStr, "%02X/%02X/%02X%02X %02X:%02X:%02X", |
| 415 | pel.privateHeader().commitTimestamp().month, |
| 416 | pel.privateHeader().commitTimestamp().day, |
| 417 | pel.privateHeader().commitTimestamp().yearMSB, |
| 418 | pel.privateHeader().commitTimestamp().yearLSB, |
| 419 | pel.privateHeader().commitTimestamp().hour, |
| 420 | pel.privateHeader().commitTimestamp().minutes, |
| 421 | pel.privateHeader().commitTimestamp().seconds); |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 422 | jsonInsert(listStr, "Commit Time", tmpValStr, 2); |
| 423 | |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 424 | // severity |
| 425 | std::string severity = pv::getValue(pel.userHeader().severity(), |
| 426 | pel_values::severityValues); |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 427 | jsonInsert(listStr, "Sev", severity, 2); |
| 428 | |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 429 | // compID |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 430 | jsonInsert(listStr, "CompID", |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 431 | getNumberString( |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 432 | "0x%X", pel.privateHeader().header().componentID), |
| 433 | 2); |
| 434 | |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 435 | found = listStr.rfind(","); |
| 436 | if (found != std::string::npos) |
| 437 | { |
| 438 | listStr.replace(found, 1, ""); |
Matt Spinler | 3025d0b | 2021-06-02 15:12:52 -0600 | [diff] [blame] | 439 | listStr += " },\n"; |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 440 | } |
| 441 | foundPEL = true; |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 442 | } |
| 443 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 444 | catch (const std::exception& e) |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 445 | { |
Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame^] | 446 | trace::error(fmt::format("Hit exception when reading PEL file {}: {}", |
| 447 | fileName, e.what())); |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 448 | } |
| 449 | return listStr; |
| 450 | } |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 451 | |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 452 | /** |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 453 | * @brief Print a list of PELs or a JSON array of PELs |
| 454 | * @param[in] order - Boolean to print in reverse orser |
| 455 | * @param[in] hidden - Boolean to include hidden PELs |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 456 | * @param[in] includeInfo - Boolean to include informational PELs |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 457 | * @param[in] critSysTerm - Boolean to include critical error and system |
| 458 | * termination PELs |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 459 | * @param[in] fullPEL - Boolean to print full PEL into a JSON array |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 460 | * @param[in] scrubRegex - SRC regex object |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 461 | * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 462 | */ |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 463 | void printPELs(bool order, bool hidden, bool includeInfo, bool critSysTerm, |
| 464 | bool fullPEL, const std::optional<std::regex>& scrubRegex, |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 465 | bool hexDump, bool archive = false) |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 466 | { |
| 467 | std::string listStr; |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 468 | std::vector<std::pair<uint32_t, uint64_t>> PELs; |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 469 | std::vector<std::string> plugins; |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 470 | listStr = "{\n"; |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 471 | for (auto it = (archive ? fs::directory_iterator(pelLogDir() + "/archive") |
| 472 | : fs::directory_iterator(pelLogDir())); |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 473 | it != fs::directory_iterator(); ++it) |
| 474 | { |
| 475 | if (!fs::is_regular_file((*it).path())) |
| 476 | { |
| 477 | continue; |
| 478 | } |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 479 | else |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 480 | { |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 481 | PELs.emplace_back(fileNameToPELId((*it).path().filename()), |
| 482 | fileNameToTimestamp((*it).path().filename())); |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 483 | } |
| 484 | } |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 485 | |
Sumit Kumar | 104c796 | 2022-02-09 06:30:39 -0600 | [diff] [blame] | 486 | // Sort the pairs based on second time parameter |
| 487 | std::sort(PELs.begin(), PELs.end(), [](auto& left, auto& right) { |
| 488 | return left.second < right.second; |
| 489 | }); |
| 490 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 491 | bool foundPEL = false; |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 492 | |
| 493 | if (fullPEL && !hexDump) |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 494 | { |
| 495 | plugins = getPlugins(); |
| 496 | } |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 497 | auto buildJSON = [&listStr, &hidden, &includeInfo, &critSysTerm, &fullPEL, |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 498 | &foundPEL, &scrubRegex, &plugins, &hexDump, |
| 499 | &archive](const auto& i) { |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 500 | listStr += genPELJSON(i, hidden, includeInfo, critSysTerm, fullPEL, |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 501 | foundPEL, scrubRegex, plugins, hexDump, archive); |
Aatir | 37822f6 | 2019-12-10 14:40:27 -0600 | [diff] [blame] | 502 | }; |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 503 | if (order) |
| 504 | { |
| 505 | std::for_each(PELs.rbegin(), PELs.rend(), buildJSON); |
| 506 | } |
| 507 | else |
| 508 | { |
| 509 | std::for_each(PELs.begin(), PELs.end(), buildJSON); |
| 510 | } |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 511 | if (hexDump) |
| 512 | { |
| 513 | return; |
| 514 | } |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 515 | if (foundPEL) |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 516 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 517 | if (fullPEL) |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 518 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 519 | std::cout << "]" << std::endl; |
| 520 | } |
| 521 | else |
| 522 | { |
| 523 | std::size_t found; |
| 524 | found = listStr.rfind(","); |
| 525 | if (found != std::string::npos) |
| 526 | { |
| 527 | listStr.replace(found, 1, ""); |
| 528 | listStr += "}\n"; |
| 529 | printf("%s", listStr.c_str()); |
| 530 | } |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 531 | } |
| 532 | } |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 533 | else |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 534 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 535 | std::string emptyJSON = fullPEL ? "[]" : "{}"; |
| 536 | std::cout << emptyJSON << std::endl; |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 537 | } |
| 538 | } |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 539 | |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 540 | /** |
| 541 | * @brief Calls the function passed in on the PEL with the ID |
| 542 | * passed in. |
| 543 | * |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 544 | * @param[in] id - The string version of the PEL or BMC Log ID, either with or |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 545 | * without the 0x prefix. |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 546 | * @param[in] func - The std::function<void(const PEL&, bool hexDump)> function |
| 547 | * to run. |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 548 | * @param[in] useBMC - if true, search by BMC Log ID, else search by PEL ID |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 549 | * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 550 | */ |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 551 | void callFunctionOnPEL(const std::string& id, const PELFunc& func, |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 552 | bool useBMC = false, bool hexDump = false, |
| 553 | bool archive = false) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 554 | { |
| 555 | std::string pelID{id}; |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 556 | if (!useBMC) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 557 | { |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 558 | std::transform(pelID.begin(), pelID.end(), pelID.begin(), toupper); |
| 559 | |
| 560 | if (pelID.find("0X") == 0) |
| 561 | { |
| 562 | pelID.erase(0, 2); |
| 563 | } |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | bool found = false; |
| 567 | |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 568 | for (auto it = (archive ? fs::directory_iterator(pelLogDir() + "/archive") |
| 569 | : fs::directory_iterator(pelLogDir())); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 570 | it != fs::directory_iterator(); ++it) |
| 571 | { |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 572 | // The PEL ID is part of the filename, so use that to find the PEL if |
| 573 | // "useBMC" is set to false, otherwise we have to search within the PEL |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 574 | |
| 575 | if (!fs::is_regular_file((*it).path())) |
| 576 | { |
| 577 | continue; |
| 578 | } |
| 579 | |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 580 | if ((ends_with((*it).path(), pelID) && !useBMC) || useBMC) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 581 | { |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 582 | auto data = getFileData((*it).path()); |
| 583 | if (!data.empty()) |
| 584 | { |
| 585 | PEL pel{data}; |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 586 | if (!useBMC || |
| 587 | (useBMC && pel.obmcLogID() == std::stoul(id, nullptr, 0))) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 588 | { |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 589 | found = true; |
| 590 | try |
| 591 | { |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 592 | func(pel, hexDump); |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 593 | break; |
| 594 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 595 | catch (const std::exception& e) |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 596 | { |
| 597 | std::cerr << " Internal function threw an exception: " |
| 598 | << e.what() << "\n"; |
| 599 | exit(1); |
| 600 | } |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | else |
| 604 | { |
| 605 | std::cerr << "Could not read PEL file\n"; |
| 606 | exit(1); |
| 607 | } |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | if (!found) |
| 612 | { |
| 613 | std::cerr << "PEL not found\n"; |
| 614 | exit(1); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | /** |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 619 | * @brief Delete a PEL file. |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 620 | * |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 621 | * @param[in] id - The PEL ID to delete. |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 622 | */ |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 623 | void deletePEL(const std::string& id) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 624 | { |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 625 | std::string pelID{id}; |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 626 | |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 627 | std::transform(pelID.begin(), pelID.end(), pelID.begin(), toupper); |
| 628 | |
| 629 | if (pelID.find("0X") == 0) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 630 | { |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 631 | pelID.erase(0, 2); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 632 | } |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 633 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 634 | for (auto it = fs::directory_iterator(pelLogDir()); |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 635 | it != fs::directory_iterator(); ++it) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 636 | { |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 637 | if (ends_with((*it).path(), pelID)) |
| 638 | { |
| 639 | fs::remove((*it).path()); |
| 640 | } |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| 644 | /** |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 645 | * @brief Delete all PEL files. |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 646 | */ |
| 647 | void deleteAllPELs() |
| 648 | { |
Matt Spinler | 2ea96f6 | 2022-02-23 16:31:01 -0600 | [diff] [blame^] | 649 | trace::info("peltool deleting all event logs"); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 650 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 651 | for (const auto& entry : fs::directory_iterator(pelLogDir())) |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 652 | { |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 653 | if (!fs::is_regular_file(entry.path())) |
| 654 | { |
| 655 | continue; |
| 656 | } |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 657 | fs::remove(entry.path()); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
Matt Spinler | 1b420bc | 2020-02-21 08:54:25 -0600 | [diff] [blame] | 661 | /** |
| 662 | * @brief Display a single PEL |
| 663 | * |
| 664 | * @param[in] pel - the PEL to display |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 665 | * @param[in] hexDump - Boolean to print hexdump of PEL instead of JSON |
Matt Spinler | 1b420bc | 2020-02-21 08:54:25 -0600 | [diff] [blame] | 666 | */ |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 667 | void displayPEL(const PEL& pel, bool hexDump) |
Matt Spinler | 1b420bc | 2020-02-21 08:54:25 -0600 | [diff] [blame] | 668 | { |
| 669 | if (pel.valid()) |
| 670 | { |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 671 | if (hexDump) |
| 672 | { |
| 673 | std::string dstr = |
| 674 | dumpHex(std::data(pel.data()), pel.size(), 0, false); |
| 675 | std::cout << dstr << std::endl; |
| 676 | } |
| 677 | else |
| 678 | { |
| 679 | auto plugins = getPlugins(); |
| 680 | pel.toJSON(registry, plugins); |
| 681 | } |
Matt Spinler | 1b420bc | 2020-02-21 08:54:25 -0600 | [diff] [blame] | 682 | } |
| 683 | else |
| 684 | { |
| 685 | std::cerr << "PEL was malformed\n"; |
| 686 | exit(1); |
| 687 | } |
| 688 | } |
| 689 | |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 690 | /** |
| 691 | * @brief Print number of PELs |
| 692 | * @param[in] hidden - Bool to include hidden logs |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 693 | * @param[in] includeInfo - Bool to include informational logs |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 694 | * @param[in] critSysTerm - Bool to include CritSysTerm |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 695 | * @param[in] scrubRegex - SRC regex object |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 696 | */ |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 697 | void printPELCount(bool hidden, bool includeInfo, bool critSysTerm, |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 698 | const std::optional<std::regex>& scrubRegex) |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 699 | { |
| 700 | std::size_t count = 0; |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 701 | |
| 702 | for (auto it = fs::directory_iterator(pelLogDir()); |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 703 | it != fs::directory_iterator(); ++it) |
| 704 | { |
| 705 | if (!fs::is_regular_file((*it).path())) |
| 706 | { |
| 707 | continue; |
| 708 | } |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 709 | std::vector<uint8_t> data = getFileData((*it).path()); |
| 710 | if (data.empty()) |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 711 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 712 | continue; |
| 713 | } |
| 714 | PEL pel{data}; |
| 715 | if (!pel.valid()) |
| 716 | { |
| 717 | continue; |
| 718 | } |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 719 | if (!includeInfo && pel.userHeader().severity() == 0) |
| 720 | { |
| 721 | continue; |
| 722 | } |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 723 | if (critSysTerm && pel.userHeader().severity() != critSysTermSeverity) |
| 724 | { |
| 725 | continue; |
| 726 | } |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 727 | std::bitset<16> actionFlags{pel.userHeader().actionFlags()}; |
| 728 | if (!hidden && actionFlags.test(hiddenFlagBit)) |
| 729 | { |
| 730 | continue; |
| 731 | } |
| 732 | if (pel.primarySRC() && scrubRegex) |
| 733 | { |
| 734 | std::string val = pel.primarySRC().value()->asciiString(); |
| 735 | if (std::regex_search(trimEnd(val), scrubRegex.value(), |
| 736 | std::regex_constants::match_not_null)) |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 737 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 738 | continue; |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 739 | } |
| 740 | } |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 741 | count++; |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 742 | } |
| 743 | std::cout << "{\n" |
| 744 | << " \"Number of PELs found\": " |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 745 | << getNumberString("%d", count) << "\n}\n"; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * @brief Generate regex pattern object from file contents |
| 750 | * @param[in] scrubFile - File containing regex pattern |
| 751 | * @return std::regex - SRC regex object |
| 752 | */ |
| 753 | std::regex genRegex(std::string& scrubFile) |
| 754 | { |
| 755 | std::string pattern; |
| 756 | std::ifstream contents(scrubFile); |
| 757 | if (contents.fail()) |
| 758 | { |
| 759 | std::cerr << "Can't open \"" << scrubFile << "\"\n"; |
| 760 | exit(1); |
| 761 | } |
| 762 | std::string line; |
| 763 | while (std::getline(contents, line)) |
| 764 | { |
| 765 | if (!line.empty()) |
| 766 | { |
| 767 | pattern.append(line + "|"); |
| 768 | } |
| 769 | } |
| 770 | try |
| 771 | { |
| 772 | std::regex scrubRegex(pattern, std::regex::icase); |
| 773 | return scrubRegex; |
| 774 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 775 | catch (const std::regex_error& e) |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 776 | { |
| 777 | if (e.code() == std::regex_constants::error_collate) |
| 778 | std::cerr << "Invalid collating element request\n"; |
| 779 | else if (e.code() == std::regex_constants::error_ctype) |
| 780 | std::cerr << "Invalid character class\n"; |
| 781 | else if (e.code() == std::regex_constants::error_escape) |
| 782 | std::cerr << "Invalid escape character or trailing escape\n"; |
| 783 | else if (e.code() == std::regex_constants::error_backref) |
| 784 | std::cerr << "Invalid back reference\n"; |
| 785 | else if (e.code() == std::regex_constants::error_brack) |
| 786 | std::cerr << "Mismatched bracket ([ or ])\n"; |
| 787 | else if (e.code() == std::regex_constants::error_paren) |
| 788 | { |
| 789 | // to catch return code error_badrepeat when error_paren is retured |
| 790 | // instead |
| 791 | size_t pos = pattern.find_first_of("*+?{"); |
| 792 | while (pos != std::string::npos) |
| 793 | { |
| 794 | if (pos == 0 || pattern.substr(pos - 1, 1) == "|") |
| 795 | { |
| 796 | std::cerr |
| 797 | << "A repetition character (*, ?, +, or {) was not " |
| 798 | "preceded by a valid regular expression\n"; |
| 799 | exit(1); |
| 800 | } |
| 801 | pos = pattern.find_first_of("*+?{", pos + 1); |
| 802 | } |
| 803 | std::cerr << "Mismatched parentheses (( or ))\n"; |
| 804 | } |
| 805 | else if (e.code() == std::regex_constants::error_brace) |
| 806 | std::cerr << "Mismatched brace ({ or })\n"; |
| 807 | else if (e.code() == std::regex_constants::error_badbrace) |
| 808 | std::cerr << "Invalid range inside a { }\n"; |
| 809 | else if (e.code() == std::regex_constants::error_range) |
| 810 | std::cerr << "Invalid character range (e.g., [z-a])\n"; |
| 811 | else if (e.code() == std::regex_constants::error_space) |
| 812 | std::cerr << "Insufficient memory to handle regular expression\n"; |
| 813 | else if (e.code() == std::regex_constants::error_badrepeat) |
| 814 | std::cerr << "A repetition character (*, ?, +, or {) was not " |
| 815 | "preceded by a valid regular expression\n"; |
| 816 | else if (e.code() == std::regex_constants::error_complexity) |
| 817 | std::cerr << "The requested match is too complex\n"; |
| 818 | else if (e.code() == std::regex_constants::error_stack) |
| 819 | std::cerr << "Insufficient memory to evaluate a match\n"; |
| 820 | exit(1); |
| 821 | } |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 822 | } |
| 823 | |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 824 | static void exitWithError(const std::string& help, const char* err) |
| 825 | { |
| 826 | std::cerr << "ERROR: " << err << std::endl << help << std::endl; |
| 827 | exit(-1); |
| 828 | } |
| 829 | |
| 830 | int main(int argc, char** argv) |
| 831 | { |
| 832 | CLI::App app{"OpenBMC PEL Tool"}; |
| 833 | std::string fileName; |
Aatir | e340c13 | 2019-12-09 14:19:29 -0600 | [diff] [blame] | 834 | std::string idPEL; |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 835 | std::string bmcId; |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 836 | std::string idToDelete; |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 837 | std::string scrubFile; |
| 838 | std::optional<std::regex> scrubRegex; |
Aatir | e340c13 | 2019-12-09 14:19:29 -0600 | [diff] [blame] | 839 | bool listPEL = false; |
| 840 | bool listPELDescOrd = false; |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 841 | bool hidden = false; |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 842 | bool includeInfo = false; |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 843 | bool critSysTerm = false; |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 844 | bool deleteAll = false; |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 845 | bool showPELCount = false; |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 846 | bool fullPEL = false; |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 847 | bool hexDump = false; |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 848 | bool archive = false; |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 849 | |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 850 | app.set_help_flag("--help", "Print this help message and exit"); |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 851 | app.add_option("--file", fileName, "Display a PEL using its Raw PEL file"); |
Aatir | e340c13 | 2019-12-09 14:19:29 -0600 | [diff] [blame] | 852 | app.add_option("-i, --id", idPEL, "Display a PEL based on its ID"); |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 853 | app.add_option("--bmc-id", bmcId, |
| 854 | "Display a PEL based on its BMC Event ID"); |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 855 | app.add_flag("-a", fullPEL, "Display all PELs"); |
Aatir | bad5f8a | 2019-12-10 15:27:16 -0600 | [diff] [blame] | 856 | app.add_flag("-l", listPEL, "List PELs"); |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 857 | app.add_flag("-n", showPELCount, "Show number of PELs"); |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 858 | app.add_flag("-r", listPELDescOrd, "Reverse order of output"); |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 859 | app.add_flag("-h", hidden, "Include hidden PELs"); |
Harisuddin Mohamed Isa | 0c57a67 | 2020-03-27 14:16:28 +0800 | [diff] [blame] | 860 | app.add_flag("-f,--info", includeInfo, "Include informational PELs"); |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 861 | app.add_flag("-t, --termination", critSysTerm, |
| 862 | "List only critical system terminating PELs"); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 863 | app.add_option("-d, --delete", idToDelete, "Delete a PEL based on its ID"); |
| 864 | app.add_flag("-D, --delete-all", deleteAll, "Delete all PELs"); |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 865 | app.add_option("-s, --scrub", scrubFile, |
| 866 | "File containing SRC regular expressions to ignore"); |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 867 | app.add_flag("-x", hexDump, "Display PEL(s) in hexdump instead of JSON"); |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 868 | app.add_flag("--archive", archive, "List or display archived PELs"); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 869 | |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 870 | CLI11_PARSE(app, argc, argv); |
| 871 | |
| 872 | if (!fileName.empty()) |
| 873 | { |
| 874 | std::vector<uint8_t> data = getFileData(fileName); |
| 875 | if (!data.empty()) |
| 876 | { |
| 877 | PEL pel{data}; |
Harisuddin Mohamed Isa | ed32c8d | 2020-10-01 18:12:39 +0800 | [diff] [blame] | 878 | if (hexDump) |
| 879 | { |
| 880 | std::string dstr = |
| 881 | dumpHex(std::data(pel.data()), pel.size(), 0, false); |
| 882 | std::cout << dstr << std::endl; |
| 883 | } |
| 884 | else |
| 885 | { |
| 886 | auto plugins = getPlugins(); |
| 887 | pel.toJSON(registry, plugins); |
| 888 | } |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 889 | } |
| 890 | else |
| 891 | { |
| 892 | exitWithError(app.help("", CLI::AppFormatMode::All), |
| 893 | "Raw PEL file can't be read."); |
| 894 | } |
| 895 | } |
Aatir | e340c13 | 2019-12-09 14:19:29 -0600 | [diff] [blame] | 896 | else if (!idPEL.empty()) |
| 897 | { |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 898 | callFunctionOnPEL(idPEL, displayPEL, false, hexDump, archive); |
Harisuddin Mohamed Isa | 58d3a98 | 2020-09-17 19:48:05 +0800 | [diff] [blame] | 899 | } |
| 900 | else if (!bmcId.empty()) |
| 901 | { |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 902 | callFunctionOnPEL(bmcId, displayPEL, true, hexDump, archive); |
Aatir | e340c13 | 2019-12-09 14:19:29 -0600 | [diff] [blame] | 903 | } |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 904 | else if (fullPEL || listPEL) |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 905 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 906 | if (!scrubFile.empty()) |
| 907 | { |
| 908 | scrubRegex = genRegex(scrubFile); |
| 909 | } |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 910 | printPELs(listPELDescOrd, hidden, includeInfo, critSysTerm, fullPEL, |
Sumit Kumar | 1d8835b | 2021-06-07 09:35:30 -0500 | [diff] [blame] | 911 | scrubRegex, hexDump, archive); |
Harisuddin Mohamed Isa | d4002f3 | 2020-02-26 16:19:58 +0800 | [diff] [blame] | 912 | } |
| 913 | else if (showPELCount) |
| 914 | { |
Harisuddin Mohamed Isa | 6f00519 | 2020-03-10 17:39:53 +0800 | [diff] [blame] | 915 | if (!scrubFile.empty()) |
| 916 | { |
| 917 | scrubRegex = genRegex(scrubFile); |
| 918 | } |
Miguel Gomez | 011ccae | 2021-03-25 23:42:09 +0000 | [diff] [blame] | 919 | printPELCount(hidden, includeInfo, critSysTerm, scrubRegex); |
Aatir | 7b291ec | 2019-11-19 10:37:37 -0600 | [diff] [blame] | 920 | } |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 921 | else if (!idToDelete.empty()) |
| 922 | { |
Matt Spinler | 25d986c | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 923 | deletePEL(idToDelete); |
Matt Spinler | 27de6f3 | 2020-02-21 08:35:57 -0600 | [diff] [blame] | 924 | } |
| 925 | else if (deleteAll) |
| 926 | { |
| 927 | deleteAllPELs(); |
| 928 | } |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 929 | else |
| 930 | { |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 931 | std::cout << app.help("", CLI::AppFormatMode::All) << std::endl; |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 932 | } |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 933 | Py_Finalize(); |
Aatir | 186ce8c | 2019-10-20 15:13:39 -0500 | [diff] [blame] | 934 | return 0; |
| 935 | } |