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