selcommands: change logging command to lg2commit
Add capability to create structured logs for UnifySel and compatible
with Redfish Events.
Tested: "7": {
"additional_data": {
"EVENT": "SEL Entry: FRU: 1, Record: Facebook Unified SEL
(0xFB), GeneralInfo: POST(0x28), POST Failure Event: System
PXE boot fail, Fail Type: IPv6 fail, Error Code: 0x15",
"RAW_EVENT": "0000FB280000000000FFFFFFFF0615FF",
"SOURCE": "/xyz/openbmc_project/state/host0",
"_CODE_FILE": "/usr/src/debug/fb-ipmi-
oem/0.1+git/src/selcommands.cpp",
"_CODE_FUNC": "ipmi::storage::ipmiStorageAddSELEntry(
ipmi::Context::ptr, std::vector<unsigned char>)::<lambda()>",
"_CODE_LINE": "1671",
"_PID": "703"
},
"event_id": "",
"message": "com.meta.IPMI.UnifiedSEL.UnifiedSELEvent",
"redfish": {
"args": [
"/xyz/openbmc_project/state/host0",
"SEL Entry: FRU: 1, Record: Facebook Unified SEL (0xFB),
GeneralInfo: POST(0x28), POST Failure Event: System PXE
boot fail, Fail Type: IPv6 fail, Error Code: 0x15"
],
"id": "OpenBMC_MetaIPMIUnifiedSEL.UnifiedSELEvent",
"message": "Unified SEL received from
'/xyz/openbmc_project/state/host0': SEL Entry: FRU: 1, Record:
Facebook Unified SEL (0xFB), GeneralInfo: POST(0x28),
POST Failure Event:
System PXE boot fail, Fail Type: IPv6 fail, Error Code: 0x15"
},
"resolution": "",
"resolved": false,
"severity": "xyz.openbmc_project.Logging.Entry.Level.Critical",
"timestamp": "2025-03-25T03:26:13.121000000Z",
"updated_timestamp": "2025-03-25T03:26:13.121000000Z"
}
Change-Id: I91b0f2f15bb99da3386aedbccd157b3d1dfb910a
Signed-off-by: Peter Yin <peter.yin@quantatw.com>
diff --git a/src/selcommands.cpp b/src/selcommands.cpp
index 515c241..def9940 100644
--- a/src/selcommands.cpp
+++ b/src/selcommands.cpp
@@ -17,8 +17,10 @@
#include <boost/algorithm/string/join.hpp>
#include <boost/container/flat_map.hpp>
+#include <com/meta/IPMI/UnifiedSEL/event.hpp>
#include <ipmid/api.hpp>
#include <nlohmann/json.hpp>
+#include <phosphor-logging/commit.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/message/types.hpp>
#include <sdbusplus/timer.hpp>
@@ -1627,47 +1629,6 @@
}
}
-// Retry function to log the SEL entry message and make D-Bus call
-bool logWithRetry(
- const std::string& journalMsg, const std::string& messageID,
- const std::string& logErr, const std::string& severity,
- const std::map<std::string, std::string>& ad, int maxRetries = 10,
- std::chrono::milliseconds waitTimeMs = std::chrono::milliseconds(100))
-{
- // Attempt to log the SEL entry message
- lg2::info(
- "SEL Entry Added: {IPMI_RAW}, IPMISEL_MESSAGE_ID={MESSAGE_ID}, IPMISEL_MESSAGE_ARGS={LOG_ERR}",
- "IPMI_RAW", journalMsg, "MESSAGE_ID", messageID, "LOG_ERR", logErr);
-
- int attempts = 0;
- while (attempts < maxRetries)
- {
- // Create D-Bus call
- auto bus = sdbusplus::bus::new_default();
- auto reqMsg = bus.new_method_call(
- "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
- "xyz.openbmc_project.Logging.Create", "Create");
- reqMsg.append(logErr, severity, ad);
-
- try
- {
- // Attempt to make the D-Bus call
- bus.call(reqMsg);
- return true; // D-Bus call successful, exit the loop
- }
- catch (sdbusplus::exception_t& e)
- {
- lg2::error("D-Bus call failed: {ERROR}", "ERROR", e);
- }
-
- // Wait before retrying
- std::this_thread::sleep_for(std::chrono::milliseconds(waitTimeMs));
- attempts++;
- }
-
- return false; // Failed after max retries
-}
-
// Main function to add SEL entry
ipmi::RspType<uint16_t> ipmiStorageAddSELEntry(ipmi::Context::ptr ctx,
std::vector<uint8_t> data)
@@ -1688,25 +1649,12 @@
/* Parse sel data and get an error log to be filed */
fb_oem::ipmi::sel::parseSelData((ctx->hostIdx + 1), data, logErr);
- static const std::string openBMCMessageRegistryVersion("0.1");
- std::string messageID =
- "OpenBMC." + openBMCMessageRegistryVersion + ".SELEntryAdded";
-
- /* Log the Raw SEL message to the journal */
- std::string journalMsg = "SEL Entry Added: " + ipmiRaw;
-
- std::map<std::string, std::string> ad;
- std::string severity = "xyz.openbmc_project.Logging.Entry.Level.Critical";
- ad.emplace("IPMI_RAW", ipmiRaw);
-
+ std::string source = "/xyz/openbmc_project/state/host0";
// Launch the logging thread
std::thread([=]() {
- bool success =
- logWithRetry(journalMsg, messageID, logErr, severity, ad);
- if (!success)
- {
- lg2::error("Failed to log SEL entry added event after retries.");
- }
+ namespace Errors = sdbusplus::error::com::meta::ipmi::UnifiedSEL;
+ lg2::commit(Errors::UnifiedSELEvent("SOURCE", source, "EVENT", logErr,
+ "RAW_EVENT", ipmiRaw));
}).detach();
int responseID = selObj.addEntry(ipmiRaw.c_str());