blob: 00c6dc904ece484bc736ce31b611416df81e9c4d [file] [log] [blame]
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05001#include "config.h"
2
3#include "elog_watch.hpp"
4
5#include "dump_internal.hpp"
6#include "dump_serialize.hpp"
Marri Devender Rao0deb2872018-11-12 07:45:54 -06007#include "errors_map.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05008#include "xyz/openbmc_project/Dump/Create/error.hpp"
9
Vishwanatha Subbanna31085972017-10-05 17:06:37 +053010#include <cereal/cereal.hpp>
Jayanth Othayothd0f00642017-09-04 06:26:30 -050011#include <phosphor-logging/elog.hpp>
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050012#include <phosphor-logging/lg2.hpp>
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070013#include <sdbusplus/exception.hpp>
Jayanth Othayothd0f00642017-09-04 06:26:30 -050014
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050015#include <fstream>
16
Vishwanatha Subbanna31085972017-10-05 17:06:37 +053017// Register class version with Cereal
Ramesh Iyyarbb410df2020-08-03 03:13:04 -050018CEREAL_CLASS_VERSION(phosphor::dump::elog::Watch, CLASS_VERSION)
Jayanth Othayothd0f00642017-09-04 06:26:30 -050019
20namespace phosphor
21{
22namespace dump
23{
24namespace elog
25{
26
27using namespace phosphor::logging;
28constexpr auto LOG_PATH = "/xyz/openbmc_project/logging";
Jayanth Othayothd0f00642017-09-04 06:26:30 -050029using Message = std::string;
Patrick Williams984a98f2020-05-13 17:53:32 -050030using Attributes = std::variant<Message>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050031using AttributeName = std::string;
32using AttributeMap = std::map<AttributeName, Attributes>;
33using PropertyName = std::string;
34using PropertyMap = std::map<PropertyName, AttributeMap>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050035
Patrick Williams9b18bf22022-07-22 19:26:55 -050036Watch::Watch(sdbusplus::bus_t& bus, IMgr& iMgr) :
Jayanth Othayoth24964822017-09-04 22:07:06 -050037 iMgr(iMgr),
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050038 addMatch(bus,
39 sdbusplus::bus::match::rules::interfacesAdded() +
40 sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
41 std::bind(std::mem_fn(&Watch::addCallback), this,
42 std::placeholders::_1)),
43 delMatch(bus,
44 sdbusplus::bus::match::rules::interfacesRemoved() +
45 sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
46 std::bind(std::mem_fn(&Watch::delCallback), this,
47 std::placeholders::_1))
Jayanth Othayoth24964822017-09-04 22:07:06 -050048{
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050049 std::filesystem::path file(ELOG_ID_PERSIST_PATH);
50 if (std::filesystem::exists(file))
Jayanth Othayoth24964822017-09-04 22:07:06 -050051 {
52 if (!deserialize(ELOG_ID_PERSIST_PATH, elogList))
53 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050054 lg2::error("Error occurred during error id deserialize");
Jayanth Othayoth24964822017-09-04 22:07:06 -050055 }
56 }
57}
58
Patrick Williams9b18bf22022-07-22 19:26:55 -050059void Watch::addCallback(sdbusplus::message_t& msg)
Jayanth Othayothd0f00642017-09-04 06:26:30 -050060{
Jayanth Othayothd0f00642017-09-04 06:26:30 -050061 using QuotaExceeded =
62 sdbusplus::xyz::openbmc_project::Dump::Create::Error::QuotaExceeded;
63
William A. Kennington III90d147a2018-06-12 16:42:33 -070064 sdbusplus::message::object_path objectPath;
65 PropertyMap propertyMap;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070066 try
67 {
William A. Kennington III90d147a2018-06-12 16:42:33 -070068 msg.read(objectPath, propertyMap);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070069 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050070 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070071 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050072 lg2::error("Failed to parse elog add signal, errormsg: {ERROR}, "
73 "REPLY_SIG: {REPLY_SIG}",
74 "ERROR", e, "REPLY_SIG", msg.get_signature());
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070075 return;
76 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050077
William A. Kennington III90d147a2018-06-12 16:42:33 -070078 std::size_t found = objectPath.str.find("entry");
Jayanth Othayothd0f00642017-09-04 06:26:30 -050079 if (found == std::string::npos)
80 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050081 // Not a new error entry skip
Jayanth Othayothd0f00642017-09-04 06:26:30 -050082 return;
83 }
84
Jayanth Othayoth24964822017-09-04 22:07:06 -050085 auto eId = getEid(objectPath);
86
87 auto search = elogList.find(eId);
88 if (search != elogList.end())
89 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050090 // elog exists in the list, Skip the dump
Jayanth Othayoth24964822017-09-04 22:07:06 -050091 return;
92 }
93
William A. Kennington III90d147a2018-06-12 16:42:33 -070094 auto iter = propertyMap.find("xyz.openbmc_project.Logging.Entry");
95 if (iter == propertyMap.end())
Jayanth Othayothd0f00642017-09-04 06:26:30 -050096 {
97 return;
98 }
99
100 auto attr = iter->second.find("Message");
101 if (attr == iter->second.end())
102 {
103 return;
104 }
105
Patrick Williams07f0f462020-05-13 11:58:11 -0500106 auto& data = std::get<PropertyName>(attr->second);
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500107 if (data.empty())
108 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500109 // No Message skip
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500110 return;
111 }
112
Marri Devender Rao0deb2872018-11-12 07:45:54 -0600113 EType errorType;
114 for (const auto& [type, errorList] : errorMap)
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500115 {
Marri Devender Rao0deb2872018-11-12 07:45:54 -0600116 auto error = std::find(errorList.begin(), errorList.end(), data);
117 if (error != errorList.end())
118 {
119 errorType = type;
120 break;
121 }
122 }
123
124 // error not supported in the configuration
125 if (errorType.empty())
126 {
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500127 return;
128 }
129
130 std::vector<std::string> fullPaths;
131 fullPaths.push_back(objectPath);
132
133 try
134 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500135 // Save the elog information. This is to avoid dump requests
136 // in elog restore path.
Jayanth Othayoth24964822017-09-04 22:07:06 -0500137 elogList.insert(eId);
138
139 phosphor::dump::elog::serialize(elogList);
140
Patrick Williams78e88402023-05-10 07:50:48 -0500141 auto item = std::find_if(phosphor::dump::bmc::TypeMap.begin(),
142 phosphor::dump::bmc::TypeMap.end(),
143 [errorType](const auto& err) {
144 return (err.second == errorType);
145 });
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500146 if (item != phosphor::dump::bmc::TypeMap.end())
Marri Devender Rao0deb2872018-11-12 07:45:54 -0600147 {
148 iMgr.IMgr::create((*item).first, fullPaths);
149 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500150 }
Patrick Williams9d2d7222021-10-06 12:44:44 -0500151 catch (const QuotaExceeded& e)
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500152 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500153 // No action now
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500154 }
155 return;
156}
157
Patrick Williams9b18bf22022-07-22 19:26:55 -0500158void Watch::delCallback(sdbusplus::message_t& msg)
Jayanth Othayoth24964822017-09-04 22:07:06 -0500159{
William A. Kennington III90d147a2018-06-12 16:42:33 -0700160 sdbusplus::message::object_path objectPath;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700161 try
162 {
William A. Kennington III90d147a2018-06-12 16:42:33 -0700163 msg.read(objectPath);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700164 }
Patrick Williams9b18bf22022-07-22 19:26:55 -0500165 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700166 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -0500167 lg2::error("Failed to parse elog del signal, errormsg: {ERROR}, "
168 "REPLY_SIG: {REPLY_SIG}",
169 "ERROR", e, "REPLY_SIG", msg.get_signature());
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700170 return;
171 }
Jayanth Othayoth24964822017-09-04 22:07:06 -0500172
Andrew Geissler638b43f2020-04-16 13:33:33 -0500173 std::size_t found = objectPath.str.find("entry");
174 if (found == std::string::npos)
175 {
176 // Not a error entry so skip
177 return;
178 }
179
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500180 // Get elog id
Jayanth Othayoth24964822017-09-04 22:07:06 -0500181 auto eId = getEid(objectPath);
182
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500183 // Delete the elog entry from the list and serialize
Jayanth Othayoth24964822017-09-04 22:07:06 -0500184 auto search = elogList.find(eId);
185 if (search != elogList.end())
186 {
187 elogList.erase(search);
188 phosphor::dump::elog::serialize(elogList);
189 }
190}
191
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500192} // namespace elog
193} // namespace dump
194} // namespace phosphor