1 #include "elog-errors.hpp" 2 #include "error-HostEvent.hpp" 3 #include "sensorhandler.hpp" 4 #include "storagehandler.hpp" 5 #include "types.hpp" 6 7 #include <ipmid/api.h> 8 #include <mapper.h> 9 #include <systemd/sd-bus.h> 10 11 #include <algorithm> 12 #include <cstdlib> 13 #include <cstring> 14 #include <fstream> 15 #include <iostream> 16 #include <memory> 17 #include <phosphor-logging/elog.hpp> 18 #include <vector> 19 #include <xyz/openbmc_project/Logging/Entry/server.hpp> 20 21 using namespace std; 22 using namespace phosphor::logging; 23 using namespace sdbusplus::xyz::openbmc_project::Logging::server; 24 25 std::string readESEL(const char* fileName) 26 { 27 std::string content; 28 std::ifstream handle(fileName); 29 30 if (handle.fail()) 31 { 32 log<level::ERR>("Failed to open eSEL", entry("FILENAME=%s", fileName)); 33 return content; 34 } 35 36 handle.seekg(0, std::ios::end); 37 content.resize(handle.tellg()); 38 handle.seekg(0, std::ios::beg); 39 handle.read(&content[0], content.size()); 40 handle.close(); 41 42 return content; 43 } 44 45 void createProcedureLogEntry(uint8_t procedureNum) 46 { 47 // Read the eSEL data from the file. 48 static constexpr auto eSELFile = "/tmp/esel"; 49 auto eSELData = readESEL(eSELFile); 50 51 // Each byte in eSEL is formatted as %02x with a space between bytes and 52 // insert '/0' at the end of the character array. 53 static constexpr auto byteSeparator = 3; 54 std::unique_ptr<char[]> data( 55 new char[(eSELData.size() * byteSeparator) + 1]()); 56 57 for (size_t i = 0; i < eSELData.size(); i++) 58 { 59 sprintf(&data[i * byteSeparator], "%02x ", eSELData[i]); 60 } 61 data[eSELData.size() * byteSeparator] = '\0'; 62 63 using error = sdbusplus::org::open_power::Host::Error::MaintenanceProcedure; 64 using metadata = org::open_power::Host::MaintenanceProcedure; 65 66 report<error>(metadata::ESEL(data.get()), 67 metadata::PROCEDURE(static_cast<uint32_t>(procedureNum))); 68 } 69