From 06c0d2f2f9f4b9c97eb9868df166d787ca367ee7 Mon Sep 17 00:00:00 2001 From: zsdc Date: Tue, 7 Jun 2022 14:34:49 +0300 Subject: event-handler: T3083: Extended event-handler features * Added the ability to filter by a syslog identifier * Added the ability to pass arguments to a script * Added the ability to pass preconfigured environment variables to a script * A message that triggered a script is now passed in the `message` variable and can be used in a script * Replaced `call()` to `run()`, since stdout are not need to be printed --- src/conf_mode/service_event_handler.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/conf_mode/service_event_handler.py') diff --git a/src/conf_mode/service_event_handler.py b/src/conf_mode/service_event_handler.py index cf4aba49b..bb12da11d 100755 --- a/src/conf_mode/service_event_handler.py +++ b/src/conf_mode/service_event_handler.py @@ -18,7 +18,7 @@ import json from pathlib import Path from vyos.config import Config -from vyos.util import call +from vyos.util import call, dict_search from vyos import ConfigError from vyos import airbag @@ -48,9 +48,16 @@ def verify(config): return None for name, event_config in config.items(): - if 'pattern' not in event_config or 'script' not in event_config: + if not dict_search('filter.pattern', event_config) or not dict_search( + 'script.path', event_config): raise ConfigError( - 'Event-handler: both pattern and script items are mandatory!') + 'Event-handler: both pattern and script path items are mandatory' + ) + + if dict_search('script.environment.message', event_config): + raise ConfigError( + 'Event-handler: "message" environment variable is reserved for log message text' + ) def generate(config): -- cgit v1.2.3