Add helper log-resolve CLI
Add ability to resolve log entries from
command line.
Tested:
Create a log using log-create and then resolve it using
both the --id and --path mechanisms
```
root@bmc:~# log-create xyz.openbmc_project.Sensor.Threshold.SensorFailure -j '{"SENSOR_NAME": "Hello1"}'
<3> OPENBMC_MESSAGE_ID={"xyz.openbmc_project.Sensor.Threshold.SensorFailure":{"SENSOR_NAME":"Hello1", <snip>
/xyz/openbmc_project/logging/entry/11
root@bmc:~# log-resolve --id 11
<3> LOGPATH: /xyz/openbmc_project/logging/entry/11 Resolved
root@bmc:~# busctl introspect xyz.openbmc_project.Logging /xyz/openbmc_project/logging/entry/11 | grep Resolved
.Resolved property b true emits-change writable
root@bmc:~# log-create xyz.openbmc_project.Sensor.Threshold.SensorFailure -j '{"SENSOR_NAME": "Hello2"}'
<3> OPENBMC_MESSAGE_ID={"xyz.openbmc_project.Sensor.Threshold.SensorFailure":{"SENSOR_NAME":"Hello2" <snip>
/xyz/openbmc_project/logging/entry/12
root@bmc:~# log-resolve --path /xyz/openbmc_project/logging/entry/12
<3> LOGPATH: /xyz/openbmc_project/logging/entry/12 Resolved
root@bmc:~# busctl introspect xyz.openbmc_project.Logging /xyz/openbmc_project/logging/entry/12 | grep Resolved
.Resolved property b true emits-change writable
```
Change-Id: Ieac6c43f2497ea97b43b2a885e929e248f669e4c
Signed-off-by: Amithash Prasad <amithash@meta.com>
diff --git a/log_resolve_main.cpp b/log_resolve_main.cpp
new file mode 100644
index 0000000..fee3afa
--- /dev/null
+++ b/log_resolve_main.cpp
@@ -0,0 +1,44 @@
+#include <CLI/CLI.hpp>
+#include <phosphor-logging/commit.hpp>
+#include <xyz/openbmc_project/Logging/Entry/client.hpp>
+
+#include <iostream>
+#include <string>
+
+using Proxy = sdbusplus::client::xyz::openbmc_project::logging::Entry<>;
+
+int main(int argc, char** argv)
+{
+ CLI::App app{"log-resolve"};
+
+ size_t id = 0;
+ std::string path{};
+ auto logIdGroup = app.add_option_group("Log Identifier");
+ auto idOpt = logIdGroup->add_option("-i,--id", id, "Log Entry index");
+ auto pathOpt =
+ logIdGroup->add_option("-p,--path", path, "DBus path of the log entry");
+ logIdGroup->require_option(1);
+
+ CLI11_PARSE(app, argc, argv);
+
+ try
+ {
+ if (*idOpt)
+ {
+ path = std::string(Proxy::namespace_path::value) + "/" +
+ std::string(Proxy::namespace_path::entry) + "/" +
+ std::to_string(id);
+ lg2::resolve(path);
+ }
+ else if (*pathOpt)
+ {
+ lg2::resolve(path);
+ }
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Unable to resolve: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
diff --git a/meson.build b/meson.build
index daaf83b..4b544b0 100644
--- a/meson.build
+++ b/meson.build
@@ -197,6 +197,19 @@
install: true,
)
+executable(
+ 'log-resolve',
+ 'log_resolve_main.cpp',
+ dependencies: [
+ CLI11_dep,
+ nlohmann_json_dep,
+ pdi_dep,
+ phosphor_logging_dep,
+ sdbusplus_dep,
+ ],
+ install: true,
+)
+
# Generate test executables which run in obmc env (qemu, real hardware).
executable(
'logging-test',