1 #include "manager.hpp" 2 3 #include "additional_data.hpp" 4 #include "pel.hpp" 5 6 #include <filesystem> 7 #include <fstream> 8 9 namespace openpower 10 { 11 namespace pels 12 { 13 14 using namespace phosphor::logging; 15 namespace fs = std::filesystem; 16 17 namespace additional_data 18 { 19 constexpr auto rawPEL = "RAWPEL"; 20 } 21 22 void Manager::create(const std::string& message, uint32_t obmcLogID, 23 uint64_t timestamp, Entry::Level severity, 24 const std::vector<std::string>& additionalData, 25 const std::vector<std::string>& associations) 26 { 27 AdditionalData ad{additionalData}; 28 29 // If a PEL was passed in, use that. Otherwise, create one. 30 auto rawPelPath = ad.getValue(additional_data::rawPEL); 31 if (rawPelPath) 32 { 33 addRawPEL(*rawPelPath, obmcLogID); 34 } 35 else 36 { 37 createPEL(message, obmcLogID, timestamp, severity, additionalData, 38 associations); 39 } 40 } 41 42 void Manager::addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID) 43 { 44 if (fs::exists(rawPelPath)) 45 { 46 std::ifstream file(rawPelPath, std::ios::in | std::ios::binary); 47 48 auto data = std::vector<uint8_t>(std::istreambuf_iterator<char>(file), 49 std::istreambuf_iterator<char>()); 50 if (file.fail()) 51 { 52 log<level::ERR>("Filesystem error reading a raw PEL", 53 entry("PELFILE=%s", rawPelPath.c_str()), 54 entry("OBMCLOGID=%d", obmcLogID)); 55 // TODO, Decide what to do here. Maybe nothing. 56 return; 57 } 58 59 file.close(); 60 61 auto pel = std::make_unique<PEL>(data, obmcLogID); 62 if (pel->valid()) 63 { 64 // PELs created by others still need these fields set by us. 65 pel->assignID(); 66 pel->setCommitTime(); 67 68 try 69 { 70 _repo.add(pel); 71 } 72 catch (std::exception& e) 73 { 74 // Probably a full or r/o filesystem, not much we can do. 75 log<level::ERR>("Unable to add PEL to Repository", 76 entry("PEL_ID=0x%X", pel->id())); 77 } 78 } 79 else 80 { 81 log<level::ERR>("Invalid PEL found", 82 entry("PELFILE=%s", rawPelPath.c_str()), 83 entry("OBMCLOGID=%d", obmcLogID)); 84 // TODO, make a whole new OpenBMC event log + PEL 85 } 86 } 87 else 88 { 89 log<level::ERR>("Raw PEL file from BMC event log does not exist", 90 entry("PELFILE=%s", (rawPelPath).c_str()), 91 entry("OBMCLOGID=%d", obmcLogID)); 92 } 93 } 94 95 void Manager::erase(uint32_t obmcLogID) 96 { 97 Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; 98 99 _repo.remove(id); 100 } 101 102 bool Manager::isDeleteProhibited(uint32_t obmcLogID) 103 { 104 return false; 105 } 106 107 void Manager::createPEL(const std::string& message, uint32_t obmcLogID, 108 uint64_t timestamp, 109 phosphor::logging::Entry::Level severity, 110 const std::vector<std::string>& additionalData, 111 const std::vector<std::string>& associations) 112 { 113 } 114 115 } // namespace pels 116 } // namespace openpower 117