summaryrefslogtreecommitdiff
path: root/redfish-core/include/utils/eventlog_utils.hpp
AgeCommit message (Collapse)AuthorFilesLines
11 daysRefactor eventlog_utils respHandler lambdasYuvakumar Selvamani1-42/+50
The dBusEventLogEntryDelete and dBusLogServiceActionsClear functions each contained an inline respHandler lambda that triggered the long-lambda ast-grep rule, requiring an inline suppression (// ast-grep-ignore: long-lambda). This commit extracts each lambda into a separate named function, afterDBusEventLogEntryDelete and afterDBusLogServiceActionsClear respectively, and uses std::bind_front to handle the asynchronous callback. This aligns the code with the preferred bmcweb pattern for D-Bus callbacks, improves readability, and allows the removal of the static analysis suppressions. Tested on AST2600 SoC (with PACKAGECONFIG `redfish-dbus-log` enabled; disabled by default). - `DELETE .../EventLog/Entries/1` (real entry) Expected: HTTP 200 Base.1.19.Success, entry removed Actual: HTTP 200 Base.1.19.Success, entry removed - `DELETE .../EventLog/Entries/999` (nonexistent) Expected: HTTP 404 Base.1.19.ResourceNotFound Actual: HTTP 404 Base.1.19.ResourceNotFound - `POST .../EventLog/Actions/LogService.ClearLog` Expected: HTTP 200 Base.1.19.Success, all entries cleared Actual: HTTP 200 Base.1.19.Success, all entries cleared - RSV: 5845 Pass / 353 Warn / 0 Fail Change-Id: I323a0813fef4f04622a71f27258fe9b1930ec6cd Signed-off-by: Yuvakumar Selvamani <yuvakumars@ami.com>
2026-08-26clang-tidy fixes for log services headerOliver Brewka1-8/+12
Silent clang-tidy warnings: - remove unused header includes - switch <systemd/sd_bus.h> to <systemd/sd-bus-protocol> for sd_bus_error usage - change str.find usage to str.contains Tested: Code compiles. Change-Id: I814239d47e1586ebc28bccc00c08e41f711b9beb Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2026-07-11redfish: Return empty DBus EventLog collectionJoel Pullokaran Jesin1-1/+9
When the DBus-backed EventLog entry collection is unavailable, return an empty Redfish collection instead of an internal error for expected absence cases. Treat EBADR and host_unreachable from GetManagedObjects as optional backend unavailability. In those cases, populate Members with an empty array and set Members@odata.count to 0, while continuing to surface unexpected DBus errors as internal errors. Tested: - ninja -C build bmcweb Change-Id: Iffff05231927f8d2239b25bbbb98960d7b5d71e0 Signed-off-by: Joel Pullokaran Jesin <joelpj@ami.com>
2026-07-01Flag long lambdasEd Tanous1-0/+2
Long lambdas have been documented as an anti-pattern for some time.[1] Despite this being generally understood, bmcweb has a long ways to go cleaning these up, and routinely code is submitted in violation of this anti-pattern. Invent an ast-grep rule that can identify when new examples of this anti-pattern are added, and ignore the existing 200+ examples that are in the codebase already using ast-grep ignore. These flags will give us something to search for as we clean this up, and will help to prevent new instances from being added unintentionally. [1] https://github.com/openbmc/docs/blob/master/anti-patterns.md#very-long-lambda-callbacks Tested: Comment only change. ast-grep passes. Manually removing an ast-grep ignore flag shows as a failure in ast-grep scan Change-Id: I77d634a393884969f184d2c39c02cc08288d5a29 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2026-04-21Remove static variablesEd Tanous1-3/+4
These static variables have the potential to cause reentrancy issues. In practice, the conditions to cause issues would require someone to basically write incorrect code, but it makes sense to wrap this into a state tracker anyway to clean up the code. While we're here, convert to using std::chrono. Note, this changes the behavior such that the values produced are now no longer dependent on timezone. Functionally, Redfish only recently got the ability to set a timezone, so this is not expected to have any user facing impact, even though the unit tests need to change. Tested: RSV Passes Change-Id: Icb7cff1d289ae23790a5fb1db6604abd73dd68fd Signed-off-by: Ed Tanous <etanous@nvidia.com>
2026-04-21Deduplicate functionEd Tanous1-45/+3
These two functions differ in only one minor thing, how the first entry is handled. event_log::getUniqueEntryID is better unit tested, so move to it for all uses. Next commit will move the static variables out so the behavior of these two methods is identical. Tested: in next commit Change-Id: I7a27d3506a6fec1f62fe8f584dbceb0ac34893ac Signed-off-by: Ed Tanous <etanous@nvidia.com>
2026-04-15sdbusplus: use shorter type aliasesPatrick Williams1-3/+2
The sdbusplus headers provide shortened aliases for many types. Switch to using them to provide better code clarity and shorter lines. Possible replacements are for: * bus_t * exception_t * manager_t * match_t * message_t * object_t * slot_t * object_path Change-Id: Iace20f9ad26e8d9dc234979e7a4087d599da2641 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2026-04-11Expose date/time in local timezoneIgor Kanyuka1-2/+1
BMC now exposes DateTime property under the Manager/<ID> in timezone configured on the BMC (local TZ) and not in UTC, but the other date time properties are still in UTC. Convert date time fields to local timezone. Tested: 1. Redfish service validator 2. Built Facebook's Catalina image with this change, ran in QEMU and checked manually varioius endpoints. 3. Ran automated tests [1] from openbmc-test-automation repo. 4. Unit tests [1] https://gerrit.openbmc.org/c/openbmc/openbmc-test-automation/+/88659 Change-Id: I8e587c7a1030deff8e6a550651c5e62719fe5299 Signed-off-by: Igor Kanyuka <ifelmail@gmail.com> Signed-off-by: Ed Tanous <ed@tanous.net>
2026-03-20Allow to set Manager TZ and show its time in localIgor Kanyuka1-1/+2
Current code always return Date time in UTC, despite local timezone may differ. This change allows to set manager timezone via redfish and show manager's TZ and offset in manager's local timezone. When the DateTime is being patched, the provided date time gets converted from the provided TZ to the local timezone, but configured TZ does not get changed. A user must explicitly patch TimeZoneName to change Manager's TZ. Tested: 1. Built an image, ran in QEMU, changed TZ to PST8PDT (negative offset), UTC (0 offset), and Tokyo (positive offset). Made sure the patch works and all the touched fields have correct values. See [1]. 2. Unit tests 3. Redfish validator [1] ``` $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-03-19T11:03:16-07:00" "-07:00" "PST8PDT" $ curl -i -k -H 'Content-type: application/json' -u root:0penBmc -d '{"TimeZoneName": "UTC"}' -X PATCH https://localhost:8443/redfish/v1/Managers/bmc HTTP/1.1 204 No Content Allow: GET, PATCH OData-Version: 4.0 Strict-Transport-Security: max-age=31536000; includeSubdomains Pragma: no-cache Cache-Control: no-store, max-age=0 X-Content-Type-Options: nosniff Date: Thu, 19 Mar 2026 18:03:28 GMT Content-Length: 0 $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-03-19T18:03:53+00:00" "+00:00" "UTC" $ curl -i -k -H 'Content-type: application/json' -u root:0penBmc -d '{"TimeZoneName": "Asia/Tokyo"}' -X PATCH https://localhost:8443/redfish/v1/Managers/bmc HTTP/1.1 204 No Content Allow: GET, PATCH OData-Version: 4.0 Strict-Transport-Security: max-age=31536000; includeSubdomains Pragma: no-cache Cache-Control: no-store, max-age=0 X-Content-Type-Options: nosniff Date: Thu, 19 Mar 2026 18:04:20 GMT Content-Length: 0 $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-03-20T03:04:32+09:00" "+09:00" "Asia/Tokyo" $ curl -i -k -H 'Content-type: application/json' -u root:0penBmc -d '{"DateTime": "2026-01-02T11:03:16-07:00"}' -X PATCH https://localhost:8443/redfish/v1/Managers/bmc HTTP/1.1 204 No Content Allow: GET, PATCH OData-Version: 4.0 Strict-Transport-Security: max-age=31536000; includeSubdomains Pragma: no-cache Cache-Control: no-store, max-age=0 X-Content-Type-Options: nosniff Date: Fri, 02 Jan 2026 18:03:16 GMT Content-Length: 0 $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc | jq '.DateTime, .DateTimeLocalOffset, .TimeZoneName' "2026-01-03T03:03:21+09:00" "+09:00" "Asia/Tokyo" $ curl -s -k -H 'Content-type: application/json' -u root:0penBmc https://localhost:8443/redfish/v1/Managers/bmc/LogServices/Journal/Entries | jq '.Members[0]' { "@odata.id": "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/cz0zNTMzMTVkMTBjYWQ0ZTg5ODJiYjliZGVmOTc2NDE2MDtpPTE7Yj00YzU5NzY1NzQ0M2M0N2IzOWZjYTZiNzU1ZWVlY2NjOTttPTFlZjc1Yzg7dD02MzY0OGQxOTFhZTE0O3g9ZDU5MjYwNzJkZTgzMWYzYw==", "@odata.type": "#LogEntry.v1_9_0.LogEntry", "Created": "2025-05-29T16:30:41.794580+00:00", "EntryType": "Oem", "Id": "cz0zNTMzMTVkMTBjYWQ0ZTg5ODJiYjliZGVmOTc2NDE2MDtpPTE7Yj00YzU5NzY1NzQ0M2M0N2IzOWZjYTZiNzU1ZWVlY2NjOTttPTFlZjc1Yzg7dD02MzY0OGQxOTFhZTE0O3g9ZDU5MjYwNzJkZTgzMWYzYw==", "Message": "kernel: Booting Linux on physical CPU 0xf00", "Name": "BMC Journal Entry", "OemRecordFormat": "BMC Journal Entry", "Severity": "OK" } ``` Change-Id: I5a4567b9ca6a0f56dd9d1b971d418a19bf625a10 Signed-off-by: Igor Kanyuka <ifelmail@gmail.com>
2026-01-21Use boost::urls::formatBrad Bishop1-8/+8
boost::urls::format is specifically meant for URL construction. It handles encoding like percentage encoding which std::format does not. Change-Id: Ief7d574d1652096c2701979a9f8fe9897957f492 Signed-off-by: Brad Bishop <bradbish@qti.qualcomm.com>
2026-01-07Renaming of eventlog variables and functionsOliver Brewka1-73/+94
Following a comment on [1], fix some of the variable and function names, to match redfish terms. Tested: Unit tests pass. Validation succeeded. [1] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/83354/13 Change-Id: Ie52309126c798b17136be99fd4a3d6650721257e Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-11-23Dynamic DBus EventLog handlersOliver Brewka1-23/+58
In order to reuse handlers for DBus EventLog under Managers, add an additional argument that specifies the redfish resource. Tested: Code compiles. Redfish validation succeeds. Additionally the curl output with and without the changes has been diffed. No differences observed. Change-Id: I13ec2f6e54f078b5b1064fb62c5561daa50f881a Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-11-23Extract DBus EventLog common codeOliver Brewka1-0/+303
Extract all functions, that are either for utility purposes or will be called by both ComputerSystem EventLog and Managers EventLog in a follow-up patch. These functions now reside in the eventlog utility header. Tested: Only code extraction. Code compiles. Change-Id: I42632790d152ecdf71a769662a2a9eec2041879d Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-11-18Correct the version of Message IdThang Tran1-3/+24
Applications are logging Redfish Message ID to journal, but the version of some message ID are different with the definition of bmcweb. E.g: - psusensor is defining version of OpenBMC registry is "0.1" as [1]. - The bmcweb defines the version of OpenBMC registry is "0.5" as [2]. It makes the "MessageId" property of Event log's enties has different version with definition in the /redfish/v1/Registries. This commit corrects the version of Message ID. [1]: https://github.com/openbmc/dbus-sensors/blob/6b7123225fc4a5180faf89190e9f64a7e248e697/src/psu/PSUEvent.cpp#L121 [2]: https://github.com/openbmc/bmcweb/blob/master/redfish-core/include/registries/openbmc.json#L1678 Tested: Verify the version of Events are the same the version of Registries that are defined in the bmcweb. Change-Id: Ib862c8d0a62cae63082436cb4646a9ca45207872 Signed-off-by: Thang Tran <thuutran@amperecomputing.com>
2025-11-12Rename Journal EventLog handlersOliver Brewka1-3/+3
These handlers will serve both the ComputerSystem and the Managers resource. Give them a common name. Tested: Inspection only. Code compiles. Change-Id: Icbcde2d7cf3d8bd55084a7d2bfe7775a220b1bd1 Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-11-12Dynamic EventLogService handlerOliver Brewka1-2/+46
In order to reuse the handler for the EventLogService under Managers, extract the logic from the handler and put it into a separate function in the eventlog util. Add an additional argument that specifies the redfish resource, so we can handle Systems and Managers resource with the same handler. Tested: Code compiles. Redfish validation succeeds. Additionally the curl output with and without the changes has been diffed. No differences observed. Change-Id: I48825b55b41afeafa02283dc91cf4cb1cd4cd7c3 Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-11-12Dynamic Journal EventLog handlersOliver Brewka1-17/+106
In order to reuse handlers for Journal EventLog under Managers, add an additional argument that specifies the redfish resource. Tested: Code compiles. Redfish validation succeeds. Additionally the curl output with and without the changes has been diffed. No differences observed. Change-Id: I7816b2b7ddb68f79552341ea60b1ee7be360dca1 Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
2025-11-10Extract Journal EventLog common codeOliver Brewka1-0/+359
Extract all functions, that are either for utility purposes or will be called by both ComputerSystem EventLog and Managers EventLog in a follow-up patch. These functions now reside in a eventlog utility header. Tested: Only code extraction. Code compiles. Change-Id: I53bf207dd584939ebb4185e923e24902b9e75427 Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>