-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathelog_watch.cpp
186 lines (161 loc) · 4.98 KB
/
elog_watch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "config.h"
#include "elog_watch.hpp"
#include "dump_serialize.hpp"
#include "dump_types.hpp"
#include "xyz/openbmc_project/Dump/Create/error.hpp"
#include <cereal/cereal.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <xyz/openbmc_project/Dump/Create/common.hpp>
#include <fstream>
// Register class version with Cereal
CEREAL_CLASS_VERSION(phosphor::dump::elog::Watch, CLASS_VERSION)
namespace phosphor
{
namespace dump
{
namespace elog
{
using Message = std::string;
using Attributes = std::variant<Message>;
using AttributeName = std::string;
using AttributeMap = std::map<AttributeName, Attributes>;
using PropertyName = std::string;
using PropertyMap = std::map<PropertyName, AttributeMap>;
Watch::Watch(sdbusplus::bus_t& bus, Mgr& mgr) :
mgr(mgr),
addMatch(bus,
sdbusplus::bus::match::rules::interfacesAdded() +
sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
std::bind(std::mem_fn(&Watch::addCallback), this,
std::placeholders::_1)),
delMatch(bus,
sdbusplus::bus::match::rules::interfacesRemoved() +
sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
std::bind(std::mem_fn(&Watch::delCallback), this,
std::placeholders::_1))
{
std::filesystem::path file(ELOG_ID_PERSIST_PATH);
if (std::filesystem::exists(file))
{
if (!deserialize(ELOG_ID_PERSIST_PATH, elogList))
{
lg2::error("Error occurred during error id deserialize");
}
}
}
void Watch::addCallback(sdbusplus::message_t& msg)
{
using QuotaExceeded =
sdbusplus::xyz::openbmc_project::Dump::Create::Error::QuotaExceeded;
sdbusplus::message::object_path objectPath;
PropertyMap propertyMap;
try
{
msg.read(objectPath, propertyMap);
}
catch (const sdbusplus::exception_t& e)
{
lg2::error("Failed to parse elog add signal, errormsg: {ERROR}, "
"REPLY_SIG: {REPLY_SIG}",
"ERROR", e, "REPLY_SIG", msg.get_signature());
return;
}
std::size_t found = objectPath.str.find("entry");
if (found == std::string::npos)
{
// Not a new error entry skip
return;
}
auto eId = getEid(objectPath);
auto search = elogList.find(eId);
if (search != elogList.end())
{
// elog exists in the list, Skip the dump
return;
}
auto iter = propertyMap.find("xyz.openbmc_project.Logging.Entry");
if (iter == propertyMap.end())
{
return;
}
auto attr = iter->second.find("Message");
if (attr == iter->second.end())
{
return;
}
auto& data = std::get<PropertyName>(attr->second);
if (data.empty())
{
// No Message skip
return;
}
auto etype = findErrorType(data);
if (!etype.has_value())
{
// error not supported in the configuration
return;
}
auto errorType = etype.value();
DumpCreateParams params;
using DumpIntr = sdbusplus::common::xyz::openbmc_project::dump::Create;
using CreateParameters =
sdbusplus::common::xyz::openbmc_project::dump::Create::CreateParameters;
using DumpType =
sdbusplus::common::xyz::openbmc_project::dump::Create::DumpType;
params[DumpIntr::convertCreateParametersToString(
CreateParameters::FilePath)] = objectPath;
params[DumpIntr::convertCreateParametersToString(
CreateParameters::DumpType)] =
DumpIntr::convertDumpTypeToString(DumpType::ErrorLog);
params[DumpIntr::convertCreateParametersToString(
CreateParameters::ErrorType)] = errorType;
try
{
// Save the elog information. This is to avoid dump requests
// in elog restore path.
elogList.insert(eId);
phosphor::dump::elog::serialize(elogList);
mgr.Mgr::createDump(params);
}
catch (const QuotaExceeded& e)
{
// No action needed
lg2::warning("Skipping exception: QuotaExceeded during createDump");
}
return;
}
void Watch::delCallback(sdbusplus::message_t& msg)
{
sdbusplus::message::object_path objectPath;
try
{
msg.read(objectPath);
}
catch (const sdbusplus::exception_t& e)
{
lg2::error("Failed to parse elog del signal, errormsg: {ERROR}, "
"REPLY_SIG: {REPLY_SIG}",
"ERROR", e, "REPLY_SIG", msg.get_signature());
return;
}
std::size_t found = objectPath.str.find("entry");
if (found == std::string::npos)
{
// Not a error entry so skip
return;
}
// Get elog id
auto eId = getEid(objectPath);
// Delete the elog entry from the list and serialize
auto search = elogList.find(eId);
if (search != elogList.end())
{
elogList.erase(search);
phosphor::dump::elog::serialize(elogList);
}
}
} // namespace elog
} // namespace dump
} // namespace phosphor