Skip to content

Commit

Permalink
Support startmsg.regex and endmsg.regex in the files inputs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nhosoi committed Jul 27, 2022
1 parent 60430bc commit 56fe0b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions roles/rsyslog/templates/input_files.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
18 changes: 18 additions & 0 deletions tests/tests_combination.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 56fe0b5

Please sign in to comment.