1 #include "error-HostEvent.hpp" 2 #include "sensorhandler.hpp" 3 #include "storagehandler.hpp" 4 5 #include <systemd/sd-bus.h> 6 7 #include <ipmid/api.hpp> 8 #include <ipmid/types.hpp> 9 #include <phosphor-logging/elog-errors.hpp> 10 #include <phosphor-logging/elog.hpp> 11 #include <xyz/openbmc_project/Logging/Entry/server.hpp> 12 13 #include <algorithm> 14 #include <cstdlib> 15 #include <cstring> 16 #include <fstream> 17 #include <iostream> 18 #include <memory> 19 #include <vector> 20 21 using namespace std; 22 using namespace phosphor::logging; 23 using namespace sdbusplus::server::xyz::openbmc_project::logging; 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::error::org::open_power::host::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