From 56fe0b55a39925140923fe8b1dca57ef1810936a Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Sun, 24 Jul 2022 17:40:27 -0700 Subject: [PATCH] Support startmsg.regex and endmsg.regex in the files inputs. Adds startmsg_regex and endmsg_regex options: `startmsg_regex`: The regular expression that matches the start part of a message. `endmsg_regex`: The regular expression that matches the last part of a message. --- README.md | 2 ++ roles/rsyslog/templates/input_files.j2 | 6 ++++++ tests/tests_combination.yml | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index b0a2a91c..b06a52d6 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,8 @@ Available options: - `input_log_path`: File name to be read by the imfile plugin. The value should be full path. Wildcard '\*' is allowed in the path. Default to `/var/log/containers/*.log`. `facility`: Facility to filter the inputs from the files. `severity`: Severity to filter the inputs from the files. +`startmsg_regex`: The regular expression that matches the start part of a message. +`endmsg_regex`: The regular expression that matches the last part of a message. #### ovirt type diff --git a/roles/rsyslog/templates/input_files.j2 b/roles/rsyslog/templates/input_files.j2 index 9b317b06..7da5093d 100644 --- a/roles/rsyslog/templates/input_files.j2 +++ b/roles/rsyslog/templates/input_files.j2 @@ -8,5 +8,11 @@ input( {% if __rsyslog_input.facility is defined %} facility="{{ __rsyslog_input.facility }}" {% endif %} +{% if __rsyslog_input.startmsg_regex is defined %} + startmsg.regex="{{ __rsyslog_input.startmsg_regex }}" +{% endif %} +{% if __rsyslog_input.endmsg_regex is defined %} + endmsg.regex="{{ __rsyslog_input.endmsg_regex }}" +{% endif %} ) {{ lookup('template', 'input_template.j2') }} diff --git a/tests/tests_combination.yml b/tests/tests_combination.yml index 19b2d15b..573a1c8a 100644 --- a/tests/tests_combination.yml +++ b/tests/tests_combination.yml @@ -52,6 +52,7 @@ - name: "{{ __test_tag }}" type: files input_log_path: "{{ __test_inputfiles_dir }}/*.log" + endmsg_regex: xyz - name: basic_input type: basics ratelimit_burst: 33333 @@ -165,6 +166,23 @@ changed_when: false # yamllint enable rule:line-length + # yamllint disable rule:line-length + - name: "Create a test log file with a log message in + {{ __test_inputfiles_dir }} which will not be logged + due to the regex condition" + shell: |- + set -euo pipefail + echo '<167>Jul 22 01:00:00 11.22.33.44 tag msgnum:00000000:24:test message 0123456789' > {{ __test_inputfiles_dir }}/test.log + changed_when: false + + - name: Check the fake second test log message is not in {{ __default_system_log }} + command: >- + /bin/grep '{{ __test_tag }} .*test message 0123456789$' {{ __default_system_log }} + register: __result + changed_when: false + failed_when: __result.rc != 1 + # yamllint enable rule:line-length + - name: END TEST CASE 0; Clean up the deployed config vars: logging_purge_confs: true