log-create: add CLI utility to create events
Add utility to allow creation of events from the command line and
shell scripts. The utility ensures that the correct data arguments
are passed, or else fails the creation.
Tested:
```
$ ./builddir/log-create xyz.openbmc_project.Sensor.Threshold.SensorFailure --json '{ "SENSOR_NAME": "Example-Sensor" }'
<3> OPENBMC_MESSAGE_ID={"xyz.openbmc_project.Sensor.Threshold.SensorFailure":{"SENSOR_NAME":"Example-Sensor","_SOURCE":{"COLUMN":45,"FILE":"../log_create_main.cpp","FUNCTION":"int generate_event(const std::string&, const nlohmann::json_abi_v3_11_2::json&)","LINE":34,"PID":264326}}}
/xyz/openbmc_project/logging/entry/1
$ busctl --user introspect xyz.openbmc_project.Logging /xyz/openbmc_project/logging/entry/1 -l | cat
xyz.openbmc_project.Logging.Entry interface - - -
.AdditionalData property as 5 "SENSOR_NAME=\"Example-Sensor\"" "_CODE_FILE=../log_create_main.cpp" "_CODE_FUNC=int generate_event(const std::string&, const nlohmann::json_abi_v3_11_2::json&)" "_CODE_LINE=34" "_PID=264326" emits-change writable
.Id property u 1 emits-change writable
.Message property s "xyz.openbmc_project.Sensor.Threshold.SensorFailure" emits-change writable
.Severity property s "xyz.openbmc_project.Logging.Entry.Level.Critical" emits-change writable
$ ./builddir/log-create xyz.openbmc_project.Sensor.Threshold.SensorFailure
terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::out_of_range'
what(): [json.exception.out_of_range.403] key 'SENSOR_NAME' not found
$ ./builddir/log-create xyz.openbmc_project.Invalid.Event.Name
Unknown event: xyz.openbmc_project.Invalid.Event.Name
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I357b453f8fecc9d224aa412ad7f3cc6b8c2a4ad8
diff --git a/meson.build b/meson.build
index ed2ea44..c4263c1 100644
--- a/meson.build
+++ b/meson.build
@@ -60,6 +60,15 @@
cereal_dep = cereal_proj.dependency('cereal')
endif
+# Get CLI11 dependency
+if cpp.has_header('CLI/CLI.hpp')
+ CLI11_dep = declare_dependency()
+else
+ CLI11_dep = dependency('CLI11')
+endif
+
+nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
+
# Generate sdbus++ files.
generated_sources = []
generated_others = []
@@ -152,6 +161,19 @@
],
install: true,
)
+
+executable('log-create',
+ 'log_create_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',
'logging_test.cpp',