tools: add gen-eventfilter.py
Generate event filtering code for lg2::commit from an input json
file, so that system integrators can create default filtering rules
to omit undesired events and errors from their systems.
Tested:
Used `log-create` to create an event and observed it. Modified the
default event filter as follows and saw log was not created.
```
@@ -3,6 +3,9 @@
"default": "allowed"
},
"errors": {
- "default": "allowed"
+ "default": "allowed",
+ "ids": [
+ "xyz.openbmc_project.State.SMC.SMCFailed"
+ ]
}
}
```
```
$ ./builddir/log-create xyz.openbmc_project.State.SMC.SMCFailed --json '{ "IDENTIFIER": "/xyz/openbmc_project/inventory/SomeSMC", "FAILURE_TYPE": "Timeout for the SMC" }'
```
Change-Id: Ib6041481075758b994bb27a816dbf5e9f26c2841
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/lib/lg2_commit.cpp b/lib/lg2_commit.cpp
index a35b91e..a2ceb22 100644
--- a/lib/lg2_commit.cpp
+++ b/lib/lg2_commit.cpp
@@ -117,6 +117,16 @@
auto commit(sdbusplus::exception::generated_event_base&& t)
-> sdbusplus::message::object_path
{
+ // Check event filters first.
+ if ((t.severity() == LOG_INFO) && details::filterEvent(t.name()))
+ {
+ return {};
+ }
+ else if (details::filterError(t.name()))
+ {
+ return {};
+ }
+
if constexpr (LG2_COMMIT_JOURNAL)
{
lg2::error("OPENBMC_MESSAGE_ID={DATA}", "DATA", t.to_json().dump());
diff --git a/lib/lg2_commit.hpp b/lib/lg2_commit.hpp
index 1ab4302..9c76e04 100644
--- a/lib/lg2_commit.hpp
+++ b/lib/lg2_commit.hpp
@@ -20,4 +20,7 @@
-> std::tuple<std::string, Entry::Level,
std::map<std::string, std::string>>;
+bool filterEvent(const std::string&);
+bool filterError(const std::string&);
+
} // namespace lg2::details
diff --git a/lib/meson.build b/lib/meson.build
index 8446767..2679548 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -1,6 +1,19 @@
phosphor_logging_includes = include_directories('include')
-phosphor_logging_gen = []
+event_filter_json = get_option('event-filter')
+if event_filter_json == ''
+ event_filter_json = default_eventfilter_json
+endif
+
+lg2_eventfilter_cpp_gen = custom_target(
+ 'lg2_eventfilter.cpp',
+ input: [eventfilter_gen, template_eventfilter_gen, event_filter_json],
+ output: 'lg2_eventfilter.cpp',
+ command: [python_prog, '@INPUT0@', '@INPUT2@'],
+ capture: true,
+)
+
+phosphor_logging_gen = [lg2_eventfilter_cpp_gen]
subdir('include/phosphor-logging')
@@ -43,4 +56,3 @@
sources: phosphor_logging_gen,
dependencies: phosphor_logging_deps,
)
-