blob: 9ab100d741d5b3a36ab4ff650297b763acfc7d84 [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#pragma once
2
Adriana Kobylakdf995fa2017-01-08 15:14:02 -06003#include "elog_entry.hpp"
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -05004#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Matt Spinler3fb83b32019-07-26 11:22:44 -05005#include "xyz/openbmc_project/Logging/Create/server.hpp"
6#include "xyz/openbmc_project/Logging/Entry/server.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07007#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
8
9#include <list>
10#include <phosphor-logging/log.hpp>
11#include <sdbusplus/bus.hpp>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060012
13namespace phosphor
14{
15namespace logging
16{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060017
Patrick Venturef18bf832018-10-26 18:14:00 -070018extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
19extern const std::map<std::string, level> g_errLevelMap;
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060020
Matt Spinler3fb83b32019-07-26 11:22:44 -050021using CreateIface = sdbusplus::xyz::openbmc_project::Logging::server::Create;
22using DeleteAllIface =
23 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050024
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060025namespace details
26{
Matt Spinler3fb83b32019-07-26 11:22:44 -050027template <typename... T>
28using ServerObject = typename sdbusplus::server::object::object<T...>;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060029
30using ManagerIface =
31 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
32
33} // namespace details
34
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050035namespace internal
36{
37
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060038/** @class Manager
39 * @brief OpenBMC logging manager implementation.
40 * @details A concrete implementation for the
41 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
42 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060043class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060044{
Patrick Venturef18bf832018-10-26 18:14:00 -070045 public:
46 Manager() = delete;
47 Manager(const Manager&) = delete;
48 Manager& operator=(const Manager&) = delete;
49 Manager(Manager&&) = delete;
50 Manager& operator=(Manager&&) = delete;
51 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060052
Patrick Venturef18bf832018-10-26 18:14:00 -070053 /** @brief Constructor to put object onto bus at a dbus path.
54 * @param[in] bus - Bus to attach to.
55 * @param[in] path - Path to attach at.
56 */
57 Manager(sdbusplus::bus::bus& bus, const char* objPath) :
58 details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
59 entryId(0), fwVersion(readFWVersion()){};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060060
Patrick Venturef18bf832018-10-26 18:14:00 -070061 /*
62 * @fn commit()
63 * @brief sd_bus Commit method implementation callback.
64 * @details Create an error/event log based on transaction id and
65 * error message.
66 * @param[in] transactionId - Unique identifier of the journal entries
67 * to be committed.
68 * @param[in] errMsg - The error exception message associated with the
69 * error log to be committed.
70 */
71 void commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060072
Patrick Venturef18bf832018-10-26 18:14:00 -070073 /*
74 * @fn commit()
75 * @brief sd_bus CommitWithLvl method implementation callback.
76 * @details Create an error/event log based on transaction id and
77 * error message.
78 * @param[in] transactionId - Unique identifier of the journal entries
79 * to be committed.
80 * @param[in] errMsg - The error exception message associated with the
81 * error log to be committed.
82 * @param[in] errLvl - level of the error
83 */
84 void commitWithLvl(uint64_t transactionId, std::string errMsg,
85 uint32_t errLvl) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060086
Patrick Venturef18bf832018-10-26 18:14:00 -070087 /** @brief Erase specified entry d-bus object
88 *
89 * @param[in] entryId - unique identifier of the entry
90 */
91 void erase(uint32_t entryId);
Deepak Kodihalli99a85492017-03-31 06:01:57 -050092
Patrick Venturef18bf832018-10-26 18:14:00 -070093 /** @brief Construct error d-bus objects from their persisted
94 * representations.
95 */
96 void restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -050097
Patrick Venturef18bf832018-10-26 18:14:00 -070098 /** @brief Erase all error log entries
99 *
100 */
101 void eraseAll()
102 {
103 auto iter = entries.begin();
104 while (iter != entries.end())
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500105 {
Patrick Venture34438962018-10-30 13:17:37 -0700106 auto e = iter->first;
Patrick Venturef18bf832018-10-26 18:14:00 -0700107 ++iter;
Patrick Venture34438962018-10-30 13:17:37 -0700108 erase(e);
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500109 }
Patrick Venturef18bf832018-10-26 18:14:00 -0700110 }
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500111
Patrick Venturef18bf832018-10-26 18:14:00 -0700112 /** @brief Returns the count of high severity errors
113 *
114 * @return int - count of real errors
115 */
116 int getRealErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500117
Patrick Venturef18bf832018-10-26 18:14:00 -0700118 /** @brief Returns the count of Info errors
119 *
120 * @return int - count of info errors
121 */
122 int getInfoErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500123
Matt Spinler8ebfd312019-06-03 12:43:59 -0500124 sdbusplus::bus::bus& getBus()
125 {
126 return busLog;
127 }
128
Matt Spinler3fb83b32019-07-26 11:22:44 -0500129 /** @brief Creates an event log
130 *
131 * This is an alternative to the _commit() API. It doesn't use
132 * the journal to look up event log metadata like _commit does.
133 *
134 * @param[in] errMsg - The error exception message associated with the
135 * error log to be committed.
136 * @param[in] severity - level of the error
137 * @param[in] additionalData - The AdditionalData property for the error
138 */
139 void create(
140 const std::string& message,
141 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
142 const std::map<std::string, std::string>& additionalData);
143
Patrick Venturef18bf832018-10-26 18:14:00 -0700144 private:
145 /*
146 * @fn _commit()
147 * @brief commit() helper
148 * @param[in] transactionId - Unique identifier of the journal entries
149 * to be committed.
150 * @param[in] errMsg - The error exception message associated with the
151 * error log to be committed.
152 * @param[in] errLvl - level of the error
153 */
154 void _commit(uint64_t transactionId, std::string&& errMsg,
155 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500156
Patrick Venturef18bf832018-10-26 18:14:00 -0700157 /** @brief Call metadata handler(s), if any. Handlers may create
158 * associations.
159 * @param[in] errorName - name of the error
160 * @param[in] additionalData - list of metadata (in key=value format)
161 * @param[out] objects - list of error's association objects
162 */
163 void processMetadata(const std::string& errorName,
164 const std::vector<std::string>& additionalData,
165 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600166
Patrick Venturef18bf832018-10-26 18:14:00 -0700167 /** @brief Synchronize unwritten journal messages to disk.
168 * @details This is the same implementation as the systemd command
169 * "journalctl --sync".
170 */
171 void journalSync();
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500172
Patrick Venturef18bf832018-10-26 18:14:00 -0700173 /** @brief Reads the BMC code level
174 *
175 * @return std::string - the version string
176 */
177 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500178
Matt Spinler99c2b402019-05-23 14:29:16 -0500179 /** @brief Call any create() functions provided by any extensions.
180 * This is called right after an event log is created to allow
181 * extensions to create their own log based on this one.
182 *
183 * @param[in] entry - the new event log entry
184 */
185 void doExtensionLogCreate(const Entry& entry);
186
Matt Spinlerb60e7552019-07-24 15:28:08 -0500187 /** @brief Common wrapper for creating an Entry object
188 *
189 * @param[in] errMsg - The error exception message associated with the
190 * error log to be committed.
191 * @param[in] errLvl - level of the error
192 * @param[in] additionalData - The AdditionalData property for the error
193 */
194 void createEntry(std::string errMsg, Entry::Level errLvl,
195 std::vector<std::string> additionalData);
196
Patrick Venturef18bf832018-10-26 18:14:00 -0700197 /** @brief Persistent sdbusplus DBus bus connection. */
198 sdbusplus::bus::bus& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600199
Patrick Venturef18bf832018-10-26 18:14:00 -0700200 /** @brief Persistent map of Entry dbus objects and their ID */
201 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600202
Patrick Venturef18bf832018-10-26 18:14:00 -0700203 /** @brief List of error ids for high severity errors */
204 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600205
Patrick Venturef18bf832018-10-26 18:14:00 -0700206 /** @brief List of error ids for Info(and below) severity */
207 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500208
Patrick Venturef18bf832018-10-26 18:14:00 -0700209 /** @brief Id of last error log entry */
210 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500211
Patrick Venturef18bf832018-10-26 18:14:00 -0700212 /** @brief The BMC firmware version */
213 const std::string fwVersion;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600214};
215
Patrick Venturef18bf832018-10-26 18:14:00 -0700216} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500217
218/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500219 * @brief Implementation for deleting all error log entries and
220 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500221 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500222 * xyz.openbmc_project.Collection.DeleteAll and
223 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500224 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500225class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500226{
Patrick Venturef18bf832018-10-26 18:14:00 -0700227 public:
228 Manager() = delete;
229 Manager(const Manager&) = delete;
230 Manager& operator=(const Manager&) = delete;
231 Manager(Manager&&) = delete;
232 Manager& operator=(Manager&&) = delete;
233 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500234
Patrick Venturef18bf832018-10-26 18:14:00 -0700235 /** @brief Constructor to put object onto bus at a dbus path.
236 * Defer signal registration (pass true for deferSignal to the
237 * base class) until after the properties are set.
238 * @param[in] bus - Bus to attach to.
239 * @param[in] path - Path to attach at.
240 * @param[in] manager - Reference to internal manager object.
241 */
242 Manager(sdbusplus::bus::bus& bus, const std::string& path,
243 internal::Manager& manager) :
Matt Spinler3fb83b32019-07-26 11:22:44 -0500244 details::ServerObject<DeleteAllIface, CreateIface>(bus, path.c_str(),
245 true),
Patrick Venturef18bf832018-10-26 18:14:00 -0700246 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500247
Patrick Venturef18bf832018-10-26 18:14:00 -0700248 /** @brief Delete all d-bus objects.
249 */
250 void deleteAll()
251 {
252 manager.eraseAll();
253 }
254
Matt Spinler3fb83b32019-07-26 11:22:44 -0500255 /** @brief D-Bus method call implementation to create an event log.
256 *
257 * @param[in] errMsg - The error exception message associated with the
258 * error log to be committed.
259 * @param[in] severity - Level of the error
260 * @param[in] additionalData - The AdditionalData property for the error
261 */
262 void create(
263 std::string message,
264 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
265 std::map<std::string, std::string> additionalData) override
266 {
267 manager.create(message, severity, additionalData);
268 }
269
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500270 void createWithFFDCFiles(
271 std::string message,
272 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
273 std::map<std::string, std::string> additionalData,
274 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
275 sdbusplus::message::unix_fd>>
276 ffdc) override
277 {
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500278 }
279
Patrick Venturef18bf832018-10-26 18:14:00 -0700280 private:
281 /** @brief This is a reference to manager object */
282 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500283};
284
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600285} // namespace logging
286} // namespace phosphor