blob: 2c903c2a98ae77bc60e9054a0403bb7c6efc3380 [file] [log] [blame]
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05001#include "config.h"
2
3#include "elog_watch.hpp"
4
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05005#include "dump_serialize.hpp"
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -05006#include "dump_types.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05007#include "xyz/openbmc_project/Dump/Create/error.hpp"
8
Vishwanatha Subbanna31085972017-10-05 17:06:37 +05309#include <cereal/cereal.hpp>
Jayanth Othayothd0f00642017-09-04 06:26:30 -050010#include <phosphor-logging/elog.hpp>
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050011#include <phosphor-logging/lg2.hpp>
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070012#include <sdbusplus/exception.hpp>
Dhruvaraj Subhashchandran1615b822023-05-31 15:29:15 -050013#include <xyz/openbmc_project/Dump/Create/common.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 -050027using Message = std::string;
Patrick Williams984a98f2020-05-13 17:53:32 -050028using Attributes = std::variant<Message>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050029using AttributeName = std::string;
30using AttributeMap = std::map<AttributeName, Attributes>;
31using PropertyName = std::string;
32using PropertyMap = std::map<PropertyName, AttributeMap>;
Jayanth Othayothd0f00642017-09-04 06:26:30 -050033
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050034Watch::Watch(sdbusplus::bus_t& bus, Mgr& mgr) :
35 mgr(mgr),
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050036 addMatch(bus,
37 sdbusplus::bus::match::rules::interfacesAdded() +
38 sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
39 std::bind(std::mem_fn(&Watch::addCallback), this,
40 std::placeholders::_1)),
41 delMatch(bus,
42 sdbusplus::bus::match::rules::interfacesRemoved() +
43 sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING),
44 std::bind(std::mem_fn(&Watch::delCallback), this,
45 std::placeholders::_1))
Jayanth Othayoth24964822017-09-04 22:07:06 -050046{
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050047 std::filesystem::path file(ELOG_ID_PERSIST_PATH);
48 if (std::filesystem::exists(file))
Jayanth Othayoth24964822017-09-04 22:07:06 -050049 {
50 if (!deserialize(ELOG_ID_PERSIST_PATH, elogList))
51 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050052 lg2::error("Error occurred during error id deserialize");
Jayanth Othayoth24964822017-09-04 22:07:06 -050053 }
54 }
55}
56
Patrick Williams9b18bf22022-07-22 19:26:55 -050057void Watch::addCallback(sdbusplus::message_t& msg)
Jayanth Othayothd0f00642017-09-04 06:26:30 -050058{
Jayanth Othayothd0f00642017-09-04 06:26:30 -050059 using QuotaExceeded =
60 sdbusplus::xyz::openbmc_project::Dump::Create::Error::QuotaExceeded;
61
William A. Kennington III90d147a2018-06-12 16:42:33 -070062 sdbusplus::message::object_path objectPath;
63 PropertyMap propertyMap;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070064 try
65 {
William A. Kennington III90d147a2018-06-12 16:42:33 -070066 msg.read(objectPath, propertyMap);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070067 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050068 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070069 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050070 lg2::error("Failed to parse elog add signal, errormsg: {ERROR}, "
71 "REPLY_SIG: {REPLY_SIG}",
72 "ERROR", e, "REPLY_SIG", msg.get_signature());
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070073 return;
74 }
Jayanth Othayothd0f00642017-09-04 06:26:30 -050075
William A. Kennington III90d147a2018-06-12 16:42:33 -070076 std::size_t found = objectPath.str.find("entry");
Jayanth Othayothd0f00642017-09-04 06:26:30 -050077 if (found == std::string::npos)
78 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050079 // Not a new error entry skip
Jayanth Othayothd0f00642017-09-04 06:26:30 -050080 return;
81 }
82
Jayanth Othayoth24964822017-09-04 22:07:06 -050083 auto eId = getEid(objectPath);
84
85 auto search = elogList.find(eId);
86 if (search != elogList.end())
87 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050088 // elog exists in the list, Skip the dump
Jayanth Othayoth24964822017-09-04 22:07:06 -050089 return;
90 }
91
William A. Kennington III90d147a2018-06-12 16:42:33 -070092 auto iter = propertyMap.find("xyz.openbmc_project.Logging.Entry");
93 if (iter == propertyMap.end())
Jayanth Othayothd0f00642017-09-04 06:26:30 -050094 {
95 return;
96 }
97
98 auto attr = iter->second.find("Message");
99 if (attr == iter->second.end())
100 {
101 return;
102 }
103
Patrick Williams07f0f462020-05-13 11:58:11 -0500104 auto& data = std::get<PropertyName>(attr->second);
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500105 if (data.empty())
106 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500107 // No Message skip
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500108 return;
109 }
110
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -0500111 auto etype = findErrorType(data);
112 if (!etype.has_value())
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500113 {
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -0500114 // error not supported in the configuration
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500115 return;
116 }
117
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -0500118 auto errorType = etype.value();
119
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -0500120 DumpCreateParams params;
121 using DumpIntr = sdbusplus::common::xyz::openbmc_project::dump::Create;
122 using CreateParameters =
123 sdbusplus::common::xyz::openbmc_project::dump::Create::CreateParameters;
124 using DumpType =
125 sdbusplus::common::xyz::openbmc_project::dump::Create::DumpType;
126 params[DumpIntr::convertCreateParametersToString(
127 CreateParameters::FilePath)] = objectPath;
128 params[DumpIntr::convertCreateParametersToString(
129 CreateParameters::DumpType)] =
130 DumpIntr::convertDumpTypeToString(DumpType::ErrorLog);
131 params[DumpIntr::convertCreateParametersToString(
132 CreateParameters::ErrorType)] = errorType;
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500133 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);
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -0500140 mgr.Mgr::createDump(params);
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 Othayoth316a2272024-11-25 21:23:59 -0600144 // No action needed
145 lg2::warning("Skipping exception: QuotaExceeded during createDump");
Jayanth Othayothd0f00642017-09-04 06:26:30 -0500146 }
147 return;
148}
149
Patrick Williams9b18bf22022-07-22 19:26:55 -0500150void Watch::delCallback(sdbusplus::message_t& msg)
Jayanth Othayoth24964822017-09-04 22:07:06 -0500151{
William A. Kennington III90d147a2018-06-12 16:42:33 -0700152 sdbusplus::message::object_path objectPath;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700153 try
154 {
William A. Kennington III90d147a2018-06-12 16:42:33 -0700155 msg.read(objectPath);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700156 }
Patrick Williams9b18bf22022-07-22 19:26:55 -0500157 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700158 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -0500159 lg2::error("Failed to parse elog del signal, errormsg: {ERROR}, "
160 "REPLY_SIG: {REPLY_SIG}",
161 "ERROR", e, "REPLY_SIG", msg.get_signature());
William A. Kennington III15cd3ce2018-05-15 11:34:44 -0700162 return;
163 }
Jayanth Othayoth24964822017-09-04 22:07:06 -0500164
Andrew Geissler638b43f2020-04-16 13:33:33 -0500165 std::size_t found = objectPath.str.find("entry");
166 if (found == std::string::npos)
167 {
168 // Not a error entry so skip
169 return;
170 }
171
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500172 // Get elog id
Jayanth Othayoth24964822017-09-04 22:07:06 -0500173 auto eId = getEid(objectPath);
174
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500175 // Delete the elog entry from the list and serialize
Jayanth Othayoth24964822017-09-04 22:07:06 -0500176 auto search = elogList.find(eId);
177 if (search != elogList.end())
178 {
179 elogList.erase(search);
180 phosphor::dump::elog::serialize(elogList);
181 }
182}
183
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -0500184} // namespace elog
185} // namespace dump
186} // namespace phosphor