blob: e6714af4db2193efcb13d4ed52beeef38ad5177a [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"
Patrick Venturef18bf832018-10-26 18:14:00 -07005#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
6
7#include <list>
8#include <phosphor-logging/log.hpp>
9#include <sdbusplus/bus.hpp>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060010
11namespace phosphor
12{
13namespace logging
14{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060015
Patrick Venturef18bf832018-10-26 18:14:00 -070016extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
17extern const std::map<std::string, level> g_errLevelMap;
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060018
Patrick Venturef18bf832018-10-26 18:14:00 -070019using DeleteAllIface = sdbusplus::server::object::object<
20 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050021
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060022namespace details
23{
24
25template <typename T>
26using ServerObject = typename sdbusplus::server::object::object<T>;
27
28using ManagerIface =
29 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
30
31} // namespace details
32
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050033namespace internal
34{
35
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060036/** @class Manager
37 * @brief OpenBMC logging manager implementation.
38 * @details A concrete implementation for the
39 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
40 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060041class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060042{
Patrick Venturef18bf832018-10-26 18:14:00 -070043 public:
44 Manager() = delete;
45 Manager(const Manager&) = delete;
46 Manager& operator=(const Manager&) = delete;
47 Manager(Manager&&) = delete;
48 Manager& operator=(Manager&&) = delete;
49 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060050
Patrick Venturef18bf832018-10-26 18:14:00 -070051 /** @brief Constructor to put object onto bus at a dbus path.
52 * @param[in] bus - Bus to attach to.
53 * @param[in] path - Path to attach at.
54 */
55 Manager(sdbusplus::bus::bus& bus, const char* objPath) :
56 details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
57 entryId(0), fwVersion(readFWVersion()){};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060058
Patrick Venturef18bf832018-10-26 18:14:00 -070059 /*
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
Patrick Venturef18bf832018-10-26 18:14:00 -070071 /*
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
Patrick Venturef18bf832018-10-26 18:14:00 -070085 /** @brief Erase specified entry d-bus object
86 *
87 * @param[in] entryId - unique identifier of the entry
88 */
89 void erase(uint32_t entryId);
Deepak Kodihalli99a85492017-03-31 06:01:57 -050090
Patrick Venturef18bf832018-10-26 18:14:00 -070091 /** @brief Construct error d-bus objects from their persisted
92 * representations.
93 */
94 void restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -050095
Patrick Venturef18bf832018-10-26 18:14:00 -070096 /** @brief Erase all error log entries
97 *
98 */
99 void eraseAll()
100 {
101 auto iter = entries.begin();
102 while (iter != entries.end())
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500103 {
Patrick Venture34438962018-10-30 13:17:37 -0700104 auto e = iter->first;
Patrick Venturef18bf832018-10-26 18:14:00 -0700105 ++iter;
Patrick Venture34438962018-10-30 13:17:37 -0700106 erase(e);
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500107 }
Patrick Venturef18bf832018-10-26 18:14:00 -0700108 }
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500109
Patrick Venturef18bf832018-10-26 18:14:00 -0700110 /** @brief Returns the count of high severity errors
111 *
112 * @return int - count of real errors
113 */
114 int getRealErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500115
Patrick Venturef18bf832018-10-26 18:14:00 -0700116 /** @brief Returns the count of Info errors
117 *
118 * @return int - count of info errors
119 */
120 int getInfoErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500121
Patrick Venturef18bf832018-10-26 18:14:00 -0700122 private:
123 /*
124 * @fn _commit()
125 * @brief commit() helper
126 * @param[in] transactionId - Unique identifier of the journal entries
127 * to be committed.
128 * @param[in] errMsg - The error exception message associated with the
129 * error log to be committed.
130 * @param[in] errLvl - level of the error
131 */
132 void _commit(uint64_t transactionId, std::string&& errMsg,
133 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500134
Patrick Venturef18bf832018-10-26 18:14:00 -0700135 /** @brief Call metadata handler(s), if any. Handlers may create
136 * associations.
137 * @param[in] errorName - name of the error
138 * @param[in] additionalData - list of metadata (in key=value format)
139 * @param[out] objects - list of error's association objects
140 */
141 void processMetadata(const std::string& errorName,
142 const std::vector<std::string>& additionalData,
143 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600144
Patrick Venturef18bf832018-10-26 18:14:00 -0700145 /** @brief Synchronize unwritten journal messages to disk.
146 * @details This is the same implementation as the systemd command
147 * "journalctl --sync".
148 */
149 void journalSync();
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500150
Patrick Venturef18bf832018-10-26 18:14:00 -0700151 /** @brief Reads the BMC code level
152 *
153 * @return std::string - the version string
154 */
155 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500156
Patrick Venturef18bf832018-10-26 18:14:00 -0700157 /** @brief Persistent sdbusplus DBus bus connection. */
158 sdbusplus::bus::bus& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600159
Patrick Venturef18bf832018-10-26 18:14:00 -0700160 /** @brief Persistent map of Entry dbus objects and their ID */
161 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600162
Patrick Venturef18bf832018-10-26 18:14:00 -0700163 /** @brief List of error ids for high severity errors */
164 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600165
Patrick Venturef18bf832018-10-26 18:14:00 -0700166 /** @brief List of error ids for Info(and below) severity */
167 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500168
Patrick Venturef18bf832018-10-26 18:14:00 -0700169 /** @brief Id of last error log entry */
170 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500171
Patrick Venturef18bf832018-10-26 18:14:00 -0700172 /** @brief The BMC firmware version */
173 const std::string fwVersion;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600174};
175
Patrick Venturef18bf832018-10-26 18:14:00 -0700176} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500177
178/** @class Manager
179 * @brief Implementation for delete all error log entries.
180 * @details A concrete implementation for the
181 * xyz.openbmc_project.Collection.DeleteAll
182 */
183class Manager : public DeleteAllIface
184{
Patrick Venturef18bf832018-10-26 18:14:00 -0700185 public:
186 Manager() = delete;
187 Manager(const Manager&) = delete;
188 Manager& operator=(const Manager&) = delete;
189 Manager(Manager&&) = delete;
190 Manager& operator=(Manager&&) = delete;
191 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500192
Patrick Venturef18bf832018-10-26 18:14:00 -0700193 /** @brief Constructor to put object onto bus at a dbus path.
194 * Defer signal registration (pass true for deferSignal to the
195 * base class) until after the properties are set.
196 * @param[in] bus - Bus to attach to.
197 * @param[in] path - Path to attach at.
198 * @param[in] manager - Reference to internal manager object.
199 */
200 Manager(sdbusplus::bus::bus& bus, const std::string& path,
201 internal::Manager& manager) :
202 DeleteAllIface(bus, path.c_str(), true),
203 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500204
Patrick Venturef18bf832018-10-26 18:14:00 -0700205 /** @brief Delete all d-bus objects.
206 */
207 void deleteAll()
208 {
209 manager.eraseAll();
210 }
211
212 private:
213 /** @brief This is a reference to manager object */
214 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500215};
216
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600217} // namespace logging
218} // namespace phosphor