blob: 493b443368ed6a6cb9229dd7592ea56c57785333 [file] [log] [blame]
Jason M. Bills5e049d32018-10-19 12:59:38 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#include <systemd/sd-journal.h>
17
Jason M. Billsc4a336f2019-04-23 10:43:10 -070018#include <boost/algorithm/string.hpp>
Ed Tanousc3526342023-03-06 13:37:53 -080019#include <boost/asio/io_context.hpp>
Jason M. Bills5e049d32018-10-19 12:59:38 -070020#include <boost/container/flat_map.hpp>
21#include <boost/container/flat_set.hpp>
Zhikui Ren672bdfc2020-07-14 11:37:01 -070022#include <pulse_event_monitor.hpp>
23#include <sdbusplus/asio/object_server.hpp>
24#include <sel_logger.hpp>
25#include <threshold_event_monitor.hpp>
Charles Hsudbd77b92020-10-29 11:20:34 +080026#include <watchdog_event_monitor.hpp>
Jonico Eustaquio9c495c62024-07-02 16:35:14 -050027#ifdef SEL_LOGGER_ENABLE_SEL_DELETE
28#include <xyz/openbmc_project/Common/error.hpp>
29#endif
George Hung486e42e2021-04-14 20:20:42 +080030#ifdef SEL_LOGGER_MONITOR_THRESHOLD_ALARM_EVENTS
31#include <threshold_alarm_event_monitor.hpp>
32#endif
JinFuLin7c2810b2022-12-02 13:55:28 +080033#ifdef SEL_LOGGER_MONITOR_HOST_ERROR_EVENTS
34#include <host_error_event_monitor.hpp>
35#endif
Zhikui Ren672bdfc2020-07-14 11:37:01 -070036
Jason M. Billsc4a336f2019-04-23 10:43:10 -070037#include <filesystem>
38#include <fstream>
Jason M. Bills5e049d32018-10-19 12:59:38 -070039#include <iomanip>
40#include <iostream>
Jason M. Bills5e049d32018-10-19 12:59:38 -070041#include <sstream>
Jason M. Bills5e049d32018-10-19 12:59:38 -070042
43struct DBusInternalError final : public sdbusplus::exception_t
44{
Zhikui Ren672bdfc2020-07-14 11:37:01 -070045 const char* name() const noexcept override
Jason M. Bills5e049d32018-10-19 12:59:38 -070046 {
47 return "org.freedesktop.DBus.Error.Failed";
Patrick Williamsa138ebd2021-09-08 15:46:34 -050048 }
Zhikui Ren672bdfc2020-07-14 11:37:01 -070049 const char* description() const noexcept override
Jason M. Bills5e049d32018-10-19 12:59:38 -070050 {
51 return "internal error";
Patrick Williamsa138ebd2021-09-08 15:46:34 -050052 }
Zhikui Ren672bdfc2020-07-14 11:37:01 -070053 const char* what() const noexcept override
Jason M. Bills5e049d32018-10-19 12:59:38 -070054 {
55 return "org.freedesktop.DBus.Error.Failed: "
56 "internal error";
Patrick Williamsa138ebd2021-09-08 15:46:34 -050057 }
58
59 int get_errno() const noexcept override
60 {
61 return EACCES;
62 }
Jason M. Bills5e049d32018-10-19 12:59:38 -070063};
64
Lei YUe526b862020-12-03 15:41:59 +080065#ifndef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
Zhikui Ren672bdfc2020-07-14 11:37:01 -070066static bool getSELLogFiles(std::vector<std::filesystem::path>& selLogFiles)
Jason M. Billsc4a336f2019-04-23 10:43:10 -070067{
68 // Loop through the directory looking for ipmi_sel log files
Zhikui Ren672bdfc2020-07-14 11:37:01 -070069 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Billsc4a336f2019-04-23 10:43:10 -070070 std::filesystem::directory_iterator(selLogDir))
71 {
72 std::string filename = dirEnt.path().filename();
73 if (boost::starts_with(filename, selLogFilename))
74 {
75 // If we find an ipmi_sel log file, save the path
76 selLogFiles.emplace_back(selLogDir / filename);
77 }
78 }
79 // As the log files rotate, they are appended with a ".#" that is higher for
80 // the older logs. Since we don't expect more than 10 log files, we
81 // can just sort the list to get them in order from newest to oldest
82 std::sort(selLogFiles.begin(), selLogFiles.end());
83
84 return !selLogFiles.empty();
85}
86
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -060087static void saveClearSelTimestamp()
88{
89 int fd = open("/var/lib/ipmi/sel_erase_time",
90 O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
91 if (fd < 0)
92 {
93 std::cerr << "Failed to open file\n";
94 return;
95 }
96
97 if (futimens(fd, NULL) < 0)
98 {
99 std::cerr << "Failed to update SEL cleared timestamp: "
100 << std::string(strerror(errno));
101 }
102 close(fd);
103}
104
105#ifdef SEL_LOGGER_ENABLE_SEL_DELETE
106std::vector<uint16_t> nextRecordsCache;
107
108static void backupCacheToFile()
109{
110 std::ofstream nextRecordStream(selLogDir / nextRecordFilename);
111 for (auto recordIds : nextRecordsCache)
112 {
113 nextRecordStream << recordIds << '\n';
114 }
115}
116
117static uint16_t getNewRecordId()
118{
119 uint16_t nextRecordId = nextRecordsCache.back();
120 // Check if SEL is full
121 if (nextRecordId == selInvalidRecID)
122 {
123 return nextRecordId;
124 }
125 nextRecordsCache.pop_back();
126 if (nextRecordsCache.empty())
127 {
128 nextRecordsCache.push_back(nextRecordId + 1);
129 }
130 backupCacheToFile();
131 return nextRecordId;
132}
133
134static void initializeRecordId()
135{
136 std::ifstream nextRecordStream(selLogDir / nextRecordFilename);
137 if (!nextRecordStream.is_open())
138 {
139 std::ofstream newStream(selLogDir / nextRecordFilename);
140 newStream << '1' << '\n';
141 newStream.close();
142 nextRecordStream.open(selLogDir / nextRecordFilename);
143 }
144 std::string line;
145 while (std::getline(nextRecordStream, line))
146 {
147 nextRecordsCache.push_back(std::stoi(line));
148 }
149}
150
151void clearSelLogFiles()
152{
153 saveClearSelTimestamp();
154
155 // Clear the SEL by deleting the log files
156 std::vector<std::filesystem::path> selLogFiles;
157 if (getSELLogFiles(selLogFiles))
158 {
159 for (const std::filesystem::path& file : selLogFiles)
160 {
161 std::error_code ec;
162 std::filesystem::remove(file, ec);
163 }
164 }
165 // Reload rsyslog so it knows to start new log files
166 boost::asio::io_context io;
167 auto dbus = std::make_shared<sdbusplus::asio::connection>(io);
168 sdbusplus::message_t rsyslogReload = dbus->new_method_call(
169 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
170 "org.freedesktop.systemd1.Manager", "ReloadUnit");
171 rsyslogReload.append("rsyslog.service", "replace");
172 try
173 {
174 sdbusplus::message_t reloadResponse = dbus->call(rsyslogReload);
175 }
176 catch (const sdbusplus::exception_t& e)
177 {
178 std::cerr << e.what() << "\n";
179 }
180 // Set next record to 1
181 nextRecordsCache.clear();
182 nextRecordsCache.push_back(1);
183 // Update backup file as well
184 std::ofstream nextRecordStream(selLogDir / nextRecordFilename);
185 nextRecordStream << '1' << '\n';
186}
187
188static bool selDeleteTargetRecord(const uint16_t& targetId)
189{
190 bool targetEntryFound = false;
191 // Check if the ipmi_sel exist and save the path
192 std::vector<std::filesystem::path> selLogFiles;
193 if (!getSELLogFiles(selLogFiles))
194 {
195 return targetEntryFound;
196 }
197
198 // Go over all the ipmi_sel files to remove the entry with the target ID
199 for (const std::filesystem::path& file : selLogFiles)
200 {
201 std::fstream logStream(file, std::ios::in);
202 std::fstream tempFile(selLogDir / "temp", std::ios::out);
203 if (!logStream.is_open())
204 {
205 return targetEntryFound;
206 }
207 std::string line;
208 while (std::getline(logStream, line))
209 {
210 // Get the recordId of the current entry
211 int left = line.find(" ");
212 int right = line.find(",");
213 int recordLen = right - left;
214 std::string recordId = line.substr(left, recordLen);
215 int newRecordId = std::stoi(recordId);
216
217 if (newRecordId != targetId)
218 {
219 // Copy the entry from the original ipmi_sel to the temp file
220 tempFile << line << '\n';
221 }
222 else
223 {
224 // Skip copying the target entry
225 targetEntryFound = true;
226 }
227 }
228 logStream.close();
229 tempFile.close();
230 if (targetEntryFound)
231 {
232 std::fstream logStream(file, std::ios::out);
233 std::fstream tempFile(selLogDir / "temp", std::ios::in);
234 while (std::getline(tempFile, line))
235 {
236 logStream << line << '\n';
237 }
238 logStream.close();
239 tempFile.close();
240 std::error_code ec;
241 if (!std::filesystem::remove(selLogDir / "temp", ec))
242 {
243 std::cerr << ec.message() << std::endl;
244 }
245 break;
246 }
247 }
248 return targetEntryFound;
249}
250
Jonico Eustaquio9c495c62024-07-02 16:35:14 -0500251static void selDeleteRecord(const uint16_t& recordId)
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600252{
253 std::filesystem::file_time_type prevAddTime =
254 std::filesystem::last_write_time(selLogDir / selLogFilename);
255 bool targetEntryFound = selDeleteTargetRecord(recordId);
256
257 // Check if the Record Id was found
258 if (!targetEntryFound)
259 {
Jonico Eustaquio9c495c62024-07-02 16:35:14 -0500260 throw sdbusplus::xyz::openbmc_project::Common::Error::
261 ResourceNotFound();
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600262 }
263 // Add to next record cache for reuse
264 nextRecordsCache.push_back(recordId);
265 // Add to backup file
266 std::ofstream nextRecordStream(selLogDir / nextRecordFilename,
267 std::ios::app);
268 nextRecordStream << recordId << '\n';
269 // Keep Last Add Time the same
270 std::filesystem::last_write_time(selLogDir / selLogFilename, prevAddTime);
271 // Update Last Del Time
272 saveClearSelTimestamp();
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600273}
274#else
Jonico Eustaquio0acff272024-04-23 15:12:06 -0500275static unsigned int initializeRecordId()
Jason M. Bills5e049d32018-10-19 12:59:38 -0700276{
Jason M. Billsc4a336f2019-04-23 10:43:10 -0700277 std::vector<std::filesystem::path> selLogFiles;
278 if (!getSELLogFiles(selLogFiles))
Jason M. Bills5e049d32018-10-19 12:59:38 -0700279 {
Jonico Eustaquio0acff272024-04-23 15:12:06 -0500280 return 0;
Jason M. Bills5e049d32018-10-19 12:59:38 -0700281 }
Jason M. Billsc4a336f2019-04-23 10:43:10 -0700282 std::ifstream logStream(selLogFiles.front());
283 if (!logStream.is_open())
Jason M. Bills5e049d32018-10-19 12:59:38 -0700284 {
Jonico Eustaquio0acff272024-04-23 15:12:06 -0500285 return 0;
Jason M. Billsc4a336f2019-04-23 10:43:10 -0700286 }
287 std::string line;
288 std::string newestEntry;
289 while (std::getline(logStream, line))
290 {
291 newestEntry = line;
292 }
Jason M. Bills5e049d32018-10-19 12:59:38 -0700293
Jason M. Billsc4a336f2019-04-23 10:43:10 -0700294 std::vector<std::string> newestEntryFields;
295 boost::split(newestEntryFields, newestEntry, boost::is_any_of(" ,"),
296 boost::token_compress_on);
297 if (newestEntryFields.size() < 4)
298 {
Jonico Eustaquio0acff272024-04-23 15:12:06 -0500299 return 0;
Jason M. Bills5e049d32018-10-19 12:59:38 -0700300 }
Jason M. Billsc4a336f2019-04-23 10:43:10 -0700301
302 return std::stoul(newestEntryFields[1]);
Jason M. Bills5e049d32018-10-19 12:59:38 -0700303}
304
Charles Boyer9f476e82021-07-29 16:33:01 -0500305static unsigned int recordId = initializeRecordId();
306
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600307static unsigned int getNewRecordId()
Alexander Hansen8c023192023-09-26 09:15:18 +0200308{
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600309 if (++recordId >= selInvalidRecID)
Alexander Hansen8c023192023-09-26 09:15:18 +0200310 {
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600311 recordId = selInvalidRecID;
Alexander Hansen8c023192023-09-26 09:15:18 +0200312 }
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600313 return recordId;
Alexander Hansen8c023192023-09-26 09:15:18 +0200314}
315
Charles Boyer9f476e82021-07-29 16:33:01 -0500316void clearSelLogFiles()
317{
Alexander Hansen8c023192023-09-26 09:15:18 +0200318 saveClearSelTimestamp();
319
Charles Boyer9f476e82021-07-29 16:33:01 -0500320 // Clear the SEL by deleting the log files
321 std::vector<std::filesystem::path> selLogFiles;
322 if (getSELLogFiles(selLogFiles))
323 {
324 for (const std::filesystem::path& file : selLogFiles)
325 {
326 std::error_code ec;
327 std::filesystem::remove(file, ec);
328 }
329 }
330
Jonico Eustaquio0acff272024-04-23 15:12:06 -0500331 recordId = 0;
Charles Boyer9f476e82021-07-29 16:33:01 -0500332
333 // Reload rsyslog so it knows to start new log files
Ed Tanousc3526342023-03-06 13:37:53 -0800334 boost::asio::io_context io;
Charles Boyer9f476e82021-07-29 16:33:01 -0500335 auto dbus = std::make_shared<sdbusplus::asio::connection>(io);
Patrick Williamsccef2272022-07-22 19:26:54 -0500336 sdbusplus::message_t rsyslogReload = dbus->new_method_call(
Charles Boyer9f476e82021-07-29 16:33:01 -0500337 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
338 "org.freedesktop.systemd1.Manager", "ReloadUnit");
339 rsyslogReload.append("rsyslog.service", "replace");
340 try
341 {
Patrick Williamsccef2272022-07-22 19:26:54 -0500342 sdbusplus::message_t reloadResponse = dbus->call(rsyslogReload);
Charles Boyer9f476e82021-07-29 16:33:01 -0500343 }
Patrick Williams3f4cd972021-10-06 12:42:50 -0500344 catch (const sdbusplus::exception_t& e)
Charles Boyer9f476e82021-07-29 16:33:01 -0500345 {
346 std::cerr << e.what() << "\n";
347 }
348}
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600349#endif
Lei YUe526b862020-12-03 15:41:59 +0800350#endif
Jason M. Bills5e049d32018-10-19 12:59:38 -0700351
Zhikui Ren672bdfc2020-07-14 11:37:01 -0700352static void toHexStr(const std::vector<uint8_t>& data, std::string& hexStr)
Jason M. Bills5e049d32018-10-19 12:59:38 -0700353{
354 std::stringstream stream;
355 stream << std::hex << std::uppercase << std::setfill('0');
William A. Kennington III2e437262021-07-30 12:04:19 -0700356 for (int v : data)
Jason M. Bills5e049d32018-10-19 12:59:38 -0700357 {
358 stream << std::setw(2) << v;
359 }
360 hexStr = stream.str();
361}
362
Jason M. Bills97be3532018-11-02 13:09:16 -0700363template <typename... T>
Vincent Chou92721502024-01-24 15:09:24 -0600364static uint16_t selAddSystemRecord(
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000365 [[maybe_unused]] std::shared_ptr<sdbusplus::asio::connection> conn,
366 [[maybe_unused]] const std::string& message, const std::string& path,
367 const std::vector<uint8_t>& selData, const bool& assert,
368 const uint16_t& genId, [[maybe_unused]] T&&... metadata)
Jason M. Bills5e049d32018-10-19 12:59:38 -0700369{
370 // Only 3 bytes of SEL event data are allowed in a system record
371 if (selData.size() > selEvtDataMaxSize)
372 {
373 throw std::invalid_argument("Event data too large");
374 }
375 std::string selDataStr;
376 toHexStr(selData, selDataStr);
377
Lei YUe526b862020-12-03 15:41:59 +0800378#ifdef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000379 sdbusplus::message_t AddToLog = conn->new_method_call(
380 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
381 "xyz.openbmc_project.Logging.Create", "Create");
382
Patrick Williams5a18f102024-08-16 15:20:38 -0400383 std::string journalMsg(
384 message + " from " + path + ": " +
385 " RecordType=" + std::to_string(selSystemType) +
386 ", GeneratorID=" + std::to_string(genId) +
387 ", EventDir=" + std::to_string(assert) + ", EventData=" + selDataStr);
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000388
Patrick Williams5a18f102024-08-16 15:20:38 -0400389 AddToLog.append(
390 journalMsg, "xyz.openbmc_project.Logging.Entry.Level.Informational",
391 std::map<std::string, std::string>(
392 {{"SENSOR_PATH", path},
393 {"GENERATOR_ID", std::to_string(genId)},
394 {"RECORD_TYPE", std::to_string(selSystemType)},
395 {"EVENT_DIR", std::to_string(assert)},
396 {"SENSOR_DATA", selDataStr}}));
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000397 conn->call(AddToLog);
Vincent Chou92721502024-01-24 15:09:24 -0600398 return 0;
Lei YUe526b862020-12-03 15:41:59 +0800399#else
Jason M. Bills5e049d32018-10-19 12:59:38 -0700400 unsigned int recordId = getNewRecordId();
Jonico Eustaquio0acff272024-04-23 15:12:06 -0500401 if (recordId < selInvalidRecID)
402 {
403 sd_journal_send(
404 "MESSAGE=%s", message.c_str(), "PRIORITY=%i", selPriority,
405 "MESSAGE_ID=%s", selMessageId, "IPMI_SEL_RECORD_ID=%d", recordId,
406 "IPMI_SEL_RECORD_TYPE=%x", selSystemType,
407 "IPMI_SEL_GENERATOR_ID=%x", genId, "IPMI_SEL_SENSOR_PATH=%s",
408 path.c_str(), "IPMI_SEL_EVENT_DIR=%x", assert, "IPMI_SEL_DATA=%s",
409 selDataStr.c_str(), std::forward<T>(metadata)..., NULL);
410 }
Vincent Chou92721502024-01-24 15:09:24 -0600411 return recordId;
Lei YUe526b862020-12-03 15:41:59 +0800412#endif
Jason M. Bills5e049d32018-10-19 12:59:38 -0700413}
414
Vincent Chou92721502024-01-24 15:09:24 -0600415static uint16_t selAddOemRecord(
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000416 [[maybe_unused]] std::shared_ptr<sdbusplus::asio::connection> conn,
417 [[maybe_unused]] const std::string& message,
418 const std::vector<uint8_t>& selData, const uint8_t& recordType)
Jason M. Bills5e049d32018-10-19 12:59:38 -0700419{
420 // A maximum of 13 bytes of SEL event data are allowed in an OEM record
421 if (selData.size() > selOemDataMaxSize)
422 {
423 throw std::invalid_argument("Event data too large");
424 }
425 std::string selDataStr;
426 toHexStr(selData, selDataStr);
427
Lei YUe526b862020-12-03 15:41:59 +0800428#ifdef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000429 sdbusplus::message_t AddToLog = conn->new_method_call(
430 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
431 "xyz.openbmc_project.Logging.Create", "Create");
432
433 std::string journalMsg(
434 message + ": " + " RecordType=" + std::to_string(recordType) +
435 ", GeneratorID=" + std::to_string(0) +
436 ", EventDir=" + std::to_string(0) + ", EventData=" + selDataStr);
437
Patrick Williams5a18f102024-08-16 15:20:38 -0400438 AddToLog.append(
439 journalMsg, "xyz.openbmc_project.Logging.Entry.Level.Informational",
440 std::map<std::string, std::string>(
441 {{"SENSOR_PATH", ""},
442 {"GENERATOR_ID", std::to_string(0)},
443 {"RECORD_TYPE", std::to_string(recordType)},
444 {"EVENT_DIR", std::to_string(0)},
445 {"SENSOR_DATA", selDataStr}}));
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000446 conn->call(AddToLog);
Vincent Chou92721502024-01-24 15:09:24 -0600447 return 0;
Lei YUe526b862020-12-03 15:41:59 +0800448#else
Jason M. Bills5e049d32018-10-19 12:59:38 -0700449 unsigned int recordId = getNewRecordId();
Jonico Eustaquio0acff272024-04-23 15:12:06 -0500450 if (recordId < selInvalidRecID)
451 {
452 sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i",
453 selPriority, "MESSAGE_ID=%s", selMessageId,
454 "IPMI_SEL_RECORD_ID=%d", recordId,
455 "IPMI_SEL_RECORD_TYPE=%x", recordType,
456 "IPMI_SEL_DATA=%s", selDataStr.c_str(), NULL);
457 }
Vincent Chou92721502024-01-24 15:09:24 -0600458 return recordId;
Lei YUe526b862020-12-03 15:41:59 +0800459#endif
Jason M. Bills5e049d32018-10-19 12:59:38 -0700460}
461
William A. Kennington IIId585c592021-07-30 12:10:25 -0700462int main(int, char*[])
Jason M. Bills5e049d32018-10-19 12:59:38 -0700463{
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600464#ifndef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
465#ifdef SEL_LOGGER_ENABLE_SEL_DELETE
466 initializeRecordId();
467#endif
468#endif
Jason M. Bills5e049d32018-10-19 12:59:38 -0700469 // setup connection to dbus
Ed Tanousc3526342023-03-06 13:37:53 -0800470 boost::asio::io_context io;
Jason M. Bills5e049d32018-10-19 12:59:38 -0700471 auto conn = std::make_shared<sdbusplus::asio::connection>(io);
472
473 // IPMI SEL Object
474 conn->request_name(ipmiSelObject);
475 auto server = sdbusplus::asio::object_server(conn);
476
477 // Add SEL Interface
478 std::shared_ptr<sdbusplus::asio::dbus_interface> ifaceAddSel =
479 server.add_interface(ipmiSelPath, ipmiSelAddInterface);
480
481 // Add a new SEL entry
482 ifaceAddSel->register_method(
Konstantin Aladyshev6f5342d2023-04-19 09:23:11 +0000483 "IpmiSelAdd",
484 [conn](const std::string& message, const std::string& path,
485 const std::vector<uint8_t>& selData, const bool& assert,
486 const uint16_t& genId) {
Patrick Williams5a18f102024-08-16 15:20:38 -0400487 return selAddSystemRecord(conn, message, path, selData, assert,
488 genId);
489 });
Jason M. Bills5e049d32018-10-19 12:59:38 -0700490 // Add a new OEM SEL entry
Patrick Williams5a18f102024-08-16 15:20:38 -0400491 ifaceAddSel->register_method(
492 "IpmiSelAddOem",
493 [conn](const std::string& message, const std::vector<uint8_t>& selData,
494 const uint8_t& recordType) {
495 return selAddOemRecord(conn, message, selData, recordType);
496 });
Charles Boyer9f476e82021-07-29 16:33:01 -0500497
Charles Boyer9f476e82021-07-29 16:33:01 -0500498#ifndef SEL_LOGGER_SEND_TO_LOGGING_SERVICE
499 // Clear SEL entries
500 ifaceAddSel->register_method("Clear", []() { clearSelLogFiles(); });
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600501#ifdef SEL_LOGGER_ENABLE_SEL_DELETE
502 // Delete a SEL entry
Jonico Eustaquio9c495c62024-07-02 16:35:14 -0500503 ifaceAddSel->register_method("SELDelete", [](const uint16_t& recordId) {
Jonico Eustaquio9fa224c2024-01-10 13:08:52 -0600504 return selDeleteRecord(recordId);
505 });
506#endif
Charles Boyer9f476e82021-07-29 16:33:01 -0500507#endif
Jason M. Bills5e049d32018-10-19 12:59:38 -0700508 ifaceAddSel->initialize();
509
510#ifdef SEL_LOGGER_MONITOR_THRESHOLD_EVENTS
Patrick Williamsccef2272022-07-22 19:26:54 -0500511 sdbusplus::bus::match_t thresholdAssertMonitor =
Zhikui Ren25b26e12020-06-26 20:18:19 -0700512 startThresholdAssertMonitor(conn);
Jason M. Bills5e049d32018-10-19 12:59:38 -0700513#endif
514
Nikhil Potadeafbaa092019-03-06 16:18:13 -0800515#ifdef REDFISH_LOG_MONITOR_PULSE_EVENTS
Patrick Williamsccef2272022-07-22 19:26:54 -0500516 sdbusplus::bus::match_t pulseEventMonitor = startPulseEventMonitor(conn);
Nikhil Potadeafbaa092019-03-06 16:18:13 -0800517#endif
518
Charles Hsudbd77b92020-10-29 11:20:34 +0800519#ifdef SEL_LOGGER_MONITOR_WATCHDOG_EVENTS
Patrick Williamsccef2272022-07-22 19:26:54 -0500520 sdbusplus::bus::match_t watchdogEventMonitor =
Charles Hsudbd77b92020-10-29 11:20:34 +0800521 startWatchdogEventMonitor(conn);
522#endif
George Hung486e42e2021-04-14 20:20:42 +0800523
524#ifdef SEL_LOGGER_MONITOR_THRESHOLD_ALARM_EVENTS
525 startThresholdAlarmMonitor(conn);
526#endif
JinFuLin7c2810b2022-12-02 13:55:28 +0800527
528#ifdef SEL_LOGGER_MONITOR_HOST_ERROR_EVENTS
529 startHostErrorEventMonitor(conn);
530#endif
Jason M. Bills5e049d32018-10-19 12:59:38 -0700531 io.run();
532
533 return 0;
534}