blob: 93c73e9ddfbc6daefdb857fd389cd5d871e47542 [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"
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -05007#include "dump_types.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
Jayanth Othayothd0f00642017-09-04 06:26:30 -050027constexpr auto LOG_PATH = "/xyz/openbmc_project/logging";
Jayanth Othayothd0f00642017-09-04 06:26:30 -050028using Message = std::string;
Patrick Williams984a98f2020-05-13 17:53:32 -050029using Attributes = std::variant<Message>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050030using AttributeName = std::string;
31using AttributeMap = std::map<AttributeName, Attributes>;
32using PropertyName = std::string;
33using PropertyMap = std::map<PropertyName, AttributeMap>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050034
Patrick Williams9b18bf22022-07-22 19:26:55 -050035Watch::Watch(sdbusplus::bus_t& bus, IMgr& iMgr) :
Jayanth Othayoth24964822017-09-04 22:07:06 -050036 iMgr(iMgr),
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050037 addMatch(bus,
38 sdbusplus::bus::match::rules::interfacesAdded() +
39 sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
40 std::bind(std::mem_fn(&Watch::addCallback), this,
41 std::placeholders::_1)),
42 delMatch(bus,
43 sdbusplus::bus::match::rules::interfacesRemoved() +
44 sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
45 std::bind(std::mem_fn(&Watch::delCallback), this,
46 std::placeholders::_1))
Jayanth Othayoth24964822017-09-04 22:07:06 -050047{
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050048 std::filesystem::path file(ELOG_ID_PERSIST_PATH);
49 if (std::filesystem::exists(file))
Jayanth Othayoth24964822017-09-04 22:07:06 -050050 {
51 if (!deserialize(ELOG_ID_PERSIST_PATH, elogList))
52 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050053 lg2::error("Error occurred during error id deserialize");
Jayanth Othayoth24964822017-09-04 22:07:06 -050054 }
55 }
56}
57
Patrick Williams9b18bf22022-07-22 19:26:55 -050058void Watch::addCallback(sdbusplus::message_t& msg)
Jayanth Othayothd0f00642017-09-04 06:26:30 -050059{
Jayanth Othayothd0f00642017-09-04 06:26:30 -050060 using QuotaExceeded =
61 sdbusplus::xyz::openbmc_project::Dump::Create::Error::QuotaExceeded;
62
William A. Kennington III90d147a2018-06-12 16:42:33 -070063 sdbusplus::message::object_path objectPath;
64 PropertyMap propertyMap;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070065 try
66 {
William A. Kennington III90d147a2018-06-12 16:42:33 -070067 msg.read(objectPath, propertyMap);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070068 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050069 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070070 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050071 lg2::error("Failed to parse elog add signal, errormsg: {ERROR}, "
72 "REPLY_SIG: {REPLY_SIG}",
73 "ERROR", e, "REPLY_SIG", msg.get_signature());
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070074 return;
75 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050076
William A. Kennington III90d147a2018-06-12 16:42:33 -070077 std::size_t found = objectPath.str.find("entry");
Jayanth Othayothd0f00642017-09-04 06:26:30 -050078 if (found == std::string::npos)
79 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050080 // Not a new error entry skip
Jayanth Othayothd0f00642017-09-04 06:26:30 -050081 return;
82 }
83
Jayanth Othayoth24964822017-09-04 22:07:06 -050084 auto eId = getEid(objectPath);
85
86 auto search = elogList.find(eId);
87 if (search != elogList.end())
88 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050089 // elog exists in the list, Skip the dump
Jayanth Othayoth24964822017-09-04 22:07:06 -050090 return;
91 }
92
William A. Kennington III90d147a2018-06-12 16:42:33 -070093 auto iter = propertyMap.find("xyz.openbmc_project.Logging.Entry");
94 if (iter == propertyMap.end())
Jayanth Othayothd0f00642017-09-04 06:26:30 -050095 {
96 return;
97 }
98
99 auto attr = iter->second.find("Message");
100 if (attr == iter->second.end())
101 {
102 return;
103 }
104
Patrick Williams07f0f462020-05-13 11:58:11 -0500105 auto& data = std::get<PropertyName>(attr->second);
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500106 if (data.empty())
107 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500108 // No Message skip
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500109 return;
110 }
111
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -0500112 auto etype = findErrorType(data);
113 if (!etype.has_value())
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500114 {
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -0500115 // error not supported in the configuration
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500116 return;
117 }
118
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -0500119 auto errorType = etype.value();
120
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500121 std::vector<std::string> fullPaths;
122 fullPaths.push_back(objectPath);
123
124 try
125 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500126 // Save the elog information. This is to avoid dump requests
127 // in elog restore path.
Jayanth Othayoth24964822017-09-04 22:07:06 -0500128 elogList.insert(eId);
129
130 phosphor::dump::elog::serialize(elogList);
131
Patrick Williams78e88402023-05-10 07:50:48 -0500132 auto item = std::find_if(phosphor::dump::bmc::TypeMap.begin(),
133 phosphor::dump::bmc::TypeMap.end(),
134 [errorType](const auto& err) {
135 return (err.second == errorType);
136 });
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500137 if (item != phosphor::dump::bmc::TypeMap.end())
Marri Devender Rao0deb2872018-11-12 07:45:54 -0600138 {
139 iMgr.IMgr::create((*item).first, fullPaths);
140 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500141 }
Patrick Williams9d2d7222021-10-06 12:44:44 -0500142 catch (const QuotaExceeded& e)
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500143 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500144 // No action now
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500145 }
146 return;
147}
148
Patrick Williams9b18bf22022-07-22 19:26:55 -0500149void Watch::delCallback(sdbusplus::message_t& msg)
Jayanth Othayoth24964822017-09-04 22:07:06 -0500150{
William A. Kennington III90d147a2018-06-12 16:42:33 -0700151 sdbusplus::message::object_path objectPath;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700152 try
153 {
William A. Kennington III90d147a2018-06-12 16:42:33 -0700154 msg.read(objectPath);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700155 }
Patrick Williams9b18bf22022-07-22 19:26:55 -0500156 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700157 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -0500158 lg2::error("Failed to parse elog del signal, errormsg: {ERROR}, "
159 "REPLY_SIG: {REPLY_SIG}",
160 "ERROR", e, "REPLY_SIG", msg.get_signature());
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700161 return;
162 }
Jayanth Othayoth24964822017-09-04 22:07:06 -0500163
Andrew Geissler638b43f2020-04-16 13:33:33 -0500164 std::size_t found = objectPath.str.find("entry");
165 if (found == std::string::npos)
166 {
167 // Not a error entry so skip
168 return;
169 }
170
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500171 // Get elog id
Jayanth Othayoth24964822017-09-04 22:07:06 -0500172 auto eId = getEid(objectPath);
173
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500174 // Delete the elog entry from the list and serialize
Jayanth Othayoth24964822017-09-04 22:07:06 -0500175 auto search = elogList.find(eId);
176 if (search != elogList.end())
177 {
178 elogList.erase(search);
179 phosphor::dump::elog::serialize(elogList);
180 }
181}
182
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500183} // namespace elog
184} // namespace dump
185} // namespace phosphor