blob: fd3670cfe24b3ddb5531743238974a0228913105 [file] [log] [blame]
Matt Spinler4e8078c2019-07-09 13:22:32 -05001#include "manager.hpp"
2
3#include "additional_data.hpp"
Matt Spinler89fa0822019-07-17 13:54:30 -05004#include "pel.hpp"
5
6#include <filesystem>
7#include <fstream>
Matt Spinler4e8078c2019-07-09 13:22:32 -05008
9namespace openpower
10{
11namespace pels
12{
13
14using namespace phosphor::logging;
Matt Spinler89fa0822019-07-17 13:54:30 -050015namespace fs = std::filesystem;
Matt Spinler4e8078c2019-07-09 13:22:32 -050016
17namespace additional_data
18{
19constexpr auto rawPEL = "RAWPEL";
20}
21
22void 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
42void Manager::addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID)
43{
Matt Spinler89fa0822019-07-17 13:54:30 -050044 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 }
Matt Spinler4e8078c2019-07-09 13:22:32 -050093}
94
95void Manager::erase(uint32_t obmcLogID)
96{
Matt Spinler475e5742019-07-18 16:09:49 -050097 Repository::LogID id{Repository::LogID::Obmc(obmcLogID)};
98
99 _repo.remove(id);
Matt Spinler4e8078c2019-07-09 13:22:32 -0500100}
101
102bool Manager::isDeleteProhibited(uint32_t obmcLogID)
103{
104 return false;
105}
106
107void 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{
Matt Spinler367144c2019-09-19 15:33:52 -0500113 // TODO: look up the error in _registry and create a PEL
Matt Spinler4e8078c2019-07-09 13:22:32 -0500114}
115
116} // namespace pels
117} // namespace openpower