blob: d62a25e0f666e4fae8cbf8ee1e88d1f135ec45d1 [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#pragma once
2
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -05003#include <list>
Adriana Kobylakf477fe22017-01-06 11:56:41 -06004#include <sdbusplus/bus.hpp>
Adriana Kobylakd722b3a2017-02-28 12:10:44 -06005#include <phosphor-logging/log.hpp>
Adriana Kobylakdf995fa2017-01-08 15:14:02 -06006#include "elog_entry.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06007#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -05008#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06009
10namespace phosphor
11{
12namespace logging
13{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060014
15extern const std::map<std::string,std::vector<std::string>> g_errMetaMap;
16extern const std::map<std::string,level> g_errLevelMap;
17
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050018using DeleteAllIface = sdbusplus::server::object::object <
19 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll >;
20
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060021namespace details
22{
23
24template <typename T>
25using ServerObject = typename sdbusplus::server::object::object<T>;
26
27using ManagerIface =
28 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
29
30} // namespace details
31
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050032namespace internal
33{
34
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060035/** @class Manager
36 * @brief OpenBMC logging manager implementation.
37 * @details A concrete implementation for the
38 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
39 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060040class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060041{
42 public:
43 Manager() = delete;
44 Manager(const Manager&) = delete;
45 Manager& operator=(const Manager&) = delete;
Adriana Kobylakf477fe22017-01-06 11:56:41 -060046 Manager(Manager&&) = delete;
47 Manager& operator=(Manager&&) = delete;
48 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060049
Adriana Kobylakf477fe22017-01-06 11:56:41 -060050 /** @brief Constructor to put object onto bus at a dbus path.
51 * @param[in] bus - Bus to attach to.
52 * @param[in] path - Path to attach at.
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060053 */
Adriana Kobylak4ea7f312017-01-10 12:52:34 -060054 Manager(sdbusplus::bus::bus& bus, const char* objPath) :
55 details::ServerObject<details::ManagerIface>(bus, objPath),
56 busLog(bus),
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -060057 entryId(0){};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060058
59 /*
60 * @fn commit()
61 * @brief sd_bus Commit method implementation callback.
62 * @details Create an error/event log based on transaction id and
63 * error message.
64 * @param[in] transactionId - Unique identifier of the journal entries
65 * to be committed.
66 * @param[in] errMsg - The error exception message associated with the
67 * error log to be committed.
68 */
69 void commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060070
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -050071 /*
72 * @fn commit()
73 * @brief sd_bus CommitWithLvl method implementation callback.
74 * @details Create an error/event log based on transaction id and
75 * error message.
76 * @param[in] transactionId - Unique identifier of the journal entries
77 * to be committed.
78 * @param[in] errMsg - The error exception message associated with the
79 * error log to be committed.
80 * @param[in] errLvl - level of the error
81 */
82 void commitWithLvl(uint64_t transactionId, std::string errMsg,
83 uint32_t errLvl) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060084
Deepak Kodihalli99a85492017-03-31 06:01:57 -050085 /** @brief Erase specified entry d-bus object
86 *
87 * @param[in] entryId - unique identifier of the entry
88 */
89 void erase(uint32_t entryId);
90
Deepak Kodihalli72654f12017-06-12 04:33:29 -050091 /** @brief Construct error d-bus objects from their persisted
92 * representations.
93 */
94 void restore();
95
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050096 /** @brief Erase all error log entries
97 *
98 */
99 void eraseAll()
100 {
101 auto iter = entries.begin();
102 while (iter != entries.end())
103 {
104 auto entry = iter->first;
105 ++iter;
106 erase(entry);
107 }
108 }
109
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600110 private:
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500111 /*
112 * @fn _commit()
113 * @brief commit() helper
114 * @param[in] transactionId - Unique identifier of the journal entries
115 * to be committed.
116 * @param[in] errMsg - The error exception message associated with the
117 * error log to be committed.
118 * @param[in] errLvl - level of the error
119 */
120 void _commit(uint64_t transactionId, std::string&& errMsg,
121 Entry::Level errLvl);
122
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600123 /** @brief Call metadata handler(s), if any. Handlers may create
124 * associations.
125 * @param[in] errorName - name of the error
126 * @param[in] additionalData - list of metadata (in key=value format)
127 * @param[out] objects - list of error's association objects
128 */
129 void processMetadata(const std::string& errorName,
130 const std::vector<std::string>& additionalData,
131 AssociationList& objects) const;
132
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500133 /** @brief Synchronize unwritten journal messages to disk.
134 * @details This is the same implementation as the systemd command
135 * "journalctl --sync".
136 */
137 void journalSync();
138
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600139 /** @brief Persistent sdbusplus DBus bus connection. */
140 sdbusplus::bus::bus& busLog;
141
142 /** @brief Persistent map of Entry dbus objects and their ID */
143 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600144
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600145 /** @brief List of error ids for high severity errors */
146 std::list<uint32_t> realErrors;
147
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500148 /** @brief List of error ids for Info(and below) severity */
149 std::list<uint32_t> infoErrors;
150
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600151 /** @brief Id of last error log entry */
152 uint32_t entryId;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600153};
154
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500155} //namespace internal
156
157/** @class Manager
158 * @brief Implementation for delete all error log entries.
159 * @details A concrete implementation for the
160 * xyz.openbmc_project.Collection.DeleteAll
161 */
162class Manager : public DeleteAllIface
163{
164 public:
165 Manager() = delete;
166 Manager(const Manager&) = delete;
167 Manager& operator=(const Manager&) = delete;
168 Manager(Manager&&) = delete;
169 Manager& operator=(Manager&&) = delete;
170 virtual ~Manager() = default;
171
172 /** @brief Constructor to put object onto bus at a dbus path.
173 * Defer signal registration (pass true for deferSignal to the
174 * base class) until after the properties are set.
175 * @param[in] bus - Bus to attach to.
176 * @param[in] path - Path to attach at.
177 * @param[in] manager - Reference to internal manager object.
178 */
179 Manager(sdbusplus::bus::bus& bus,
180 const std::string& path,
181 internal::Manager& manager) :
182 DeleteAllIface(bus, path.c_str(), true),
183 manager(manager) {};
184
185 /** @brief Delete all d-bus objects.
186 */
187 void deleteAll()
188 {
189 manager.eraseAll();
190 }
191 private:
192 /** @brief This is a reference to manager object */
193 internal::Manager& manager;
194};
195
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600196} // namespace logging
197} // namespace phosphor