Skip to content

Commit

Permalink
RFE - support template, severity and facility options
Browse files Browse the repository at this point in the history
- template options to the files & formats output
- severity and facility options to the files input

(issue #271)
  • Loading branch information
nhosoi committed Apr 5, 2022
1 parent 06dd3b7 commit b220c21
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 44 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Available options:

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.

#### ovirt type

Expand Down Expand Up @@ -246,6 +248,9 @@ Available options:
- `property_value`: Value in property-based filter; default to `error`
- `path`: Path to the output file.

logging_files_template_format: Set default template for the files output.
Allowed values are `traditional`, `syslog`, and `modern`. Default to `modern`.

**Note:** Selector options and property-based filter options are exclusive. If Property-based filter options are defined, selector options will be ignored.

**Note:** Unless the above options are given, these local file outputs are configured.
Expand Down Expand Up @@ -278,6 +283,10 @@ Available options:
- `tls`: Set to `true` to encrypt the connection using the default TLS implementation used by the provider. Default to `false`.
- `pki_authmode`: Specifying the default network driver authentication mode. `x509/name`, `x509/fingerprint`, or `anon` is accepted. Default to `x509/name`.
- `permitted_server`: Hostname, IP address, fingerprint(sha1) or wildcard DNS domain of the server which this client will be allowed to connect and send logs over TLS. Default to `*.{{ logging_domain }}`
- `template`: Template format for the particular forwards output. Allowed values are `traditional`, `syslog`, and `modern`. Default to `modern`.
logging_forwards_template_format: Set default template for the forwards output.
Allowed values are `traditional`, `syslog`, and `modern`. Default to `modern`.
**Note:** Selector options and property-based filter options are exclusive. If Property-based filter options are defined, selector options will be ignored.
Expand Down
8 changes: 8 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,11 @@ logging_domain: '{{ ansible_domain if ansible_domain else ansible_hostname }}'
#
# Password to pass to the elasticsearch output
logging_elasticsearch_password: ""

# Output file format
# Allowed values: "traditional", "syslog", or "modern"; default to "modern"
logging_files_template_format: ""

# Output forward format
# Allowed values: "traditional", "syslog", or "modern"; default to "modern"
logging_forwards_template_format: ""
6 changes: 0 additions & 6 deletions roles/rsyslog/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ rsyslog_extra_packages: []
# List of additional custom config files.
# Each element: full paths to the files to be deployed.
rsyslog_custom_config_files: []

# rsyslog_basics_use_traditional_timestamp_format
#
# Traditional timestamp format looks like 'Mar 27 14:16:47'
# By setting false, it'd change 2020-03-27T14:16:47.139796+00:00)
rsyslog_basics_use_traditional_timestamp_format: true
4 changes: 1 addition & 3 deletions roles/rsyslog/tasks/inputs/files/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
type: input
state: "{{ __rsyslog_input.state | d('present') }}"
sections:
- options: |-
input(type="imfile" file="{{ __rsyslog_input.input_log_path }}" tag="{{ __rsyslog_input.name }}")
{{ lookup("template", "input_template.j2") }}
- options: "{{ lookup('template', 'input_files.j2') }}"
include_tasks:
file: "{{ role_path }}/tasks/deploy.yml"
when:
Expand Down
12 changes: 12 additions & 0 deletions roles/rsyslog/templates/input_files.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
input(
type="imfile"
file="{{ __rsyslog_input.input_log_path }}"
tag="{{ __rsyslog_input.name }}"
{% if __rsyslog_input.severity is defined %}
severity="{{ __rsyslog_input.severity }}"
{% endif %}
{% if __rsyslog_input.facility is defined %}
facility="{{ __rsyslog_input.facility }}"
{% endif %}
)
{{ lookup('template', 'input_template.j2') }}
7 changes: 7 additions & 0 deletions roles/rsyslog/templates/output_forwards.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ ruleset(name="{{ __rsyslog_output.name }}") {
{% endif %}
{% if __forwards_protocol != '' %}
Protocol="{{ __forwards_protocol }}"
{% endif %}
{% if __rsyslog_output.template | d('') == 'traditional' %}
Template="RSYSLOG_TraditionalForwardFormat"
{% elif __rsyslog_output.template | d('') == 'syslog' %}
Template="RSYSLOG_SyslogProtocol23Format"
{% else %}
Template="RSYSLOG_ForwardFormat"
{% endif %}
)
}
10 changes: 7 additions & 3 deletions roles/rsyslog/vars/outputs/files/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ __rsyslog_conf_files_output_modules:
type: 'modules'
sections:

- comment: 'Log messages into files with timestamp format either
traditional or default'
# yamllint disable rule:line-length
- comment: 'Log messages into files with traditional, syslog, or
default format'
options: |-
{% if rsyslog_basics_use_traditional_timestamp_format | d(true) %}
{% if logging_files_template_format == "traditional" %}
module(load="builtin:omfile" Template="RSYSLOG_TraditionalFileFormat")
{% elif logging_files_template_format == "syslog" %}
module(load="builtin:omfile" Template="RSYSLOG_SyslogProtocol23Format")
{% else %}
module(load="builtin:omfile")
{% endif %}
# yamllint enable rule:line-length
26 changes: 25 additions & 1 deletion roles/rsyslog/vars/outputs/forwards/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,28 @@

# List of rpm packages for Forwards output.
__rsyslog_forwards_output_packages: []
__rsyslog_forwards_output_rules: []

# Forwards Rsyslog output configuration rules
# -------------------------------------------
__rsyslog_forwards_output_rules:
- '{{ __rsyslog_conf_forwards_output_modules }}'

# __rsyslog_conf_forwards_output_modules:
__rsyslog_conf_forwards_output_modules:

- name: 'output-forwards-modules'
type: 'modules'
sections:

# yamllint disable rule:line-length
- comment: 'Log messages into files with traditional, syslog, or
default format'
options: |-
{% if logging_forwards_template_format == "traditional" %}
module(load="builtin:omfwd" Template="RSYSLOG_TraditionalForwardFormat")
{% elif logging_forwards_template_format == "syslog" %}
module(load="builtin:omfwd" Template="RSYSLOG_SyslogProtocol23Format")
{% else %}
module(load="builtin:omfwd")
{% endif %}
# yamllint enable rule:line-length
1 change: 1 addition & 0 deletions tests/tests_basics_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
Target="host.domain"
Port="1514"
Protocol="tcp"
Template="RSYSLOG_ForwardFormat"
)
}
mode: '0600'
Expand Down
19 changes: 19 additions & 0 deletions tests/tests_basics_forwards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
vars:
__test_files_conf: >-
/etc/rsyslog.d/30-output-files-default_files.conf
__test_forward_module_conf: /etc/rsyslog.d/10-output-forwards-modules.conf
__test_forward_conf_s_f: >-
/etc/rsyslog.d/30-output-forwards-forwards_severity_and_facility.conf
__test_forward_conf_f: >-
Expand All @@ -27,19 +28,24 @@
__expected_error: "Error: tls is enabled in forwards_severity_and_facility;
you must specify logging_pki_files ca_cert_src and/or ca_cert in the
playbook var section."
__test_template: RSYSLOG_ForwardFormat
__test_template_trad: RSYSLOG_TraditionalForwardFormat
__test_template_sys: RSYSLOG_SyslogProtocol23Format

tasks:
# TEST CASE 0
- name: "TEST CASE 0; Ensure that the logs from basics inputs
are sent to the forwards outputs and implicit files output"
vars:
logging_forwards_template_format: traditional
logging_outputs:
- name: forwards_severity_and_facility
type: forwards
facility: local1
severity: info
target: host.domain
tcp_port: 1514
template: syslog
- name: forwards_facility_only
type: forwards
facility: local2
Expand Down Expand Up @@ -112,6 +118,11 @@
- ca-certificates
include_tasks: tasks/check_packages.yml

- name: >-
Check the module param template is set to "{{ __test_template_trad }}"
command: >-
grep '{{ __test_template_trad }}' '{{ __test_forward_module_conf }}'
- name: Generate a file to check severity_and_facility
copy:
dest: /tmp/__testfile__
Expand All @@ -125,6 +136,7 @@
Target="host.domain"
Port="1514"
Protocol="tcp"
Template="{{ __test_template_sys }}"
)
}
mode: '0600'
Expand All @@ -146,6 +158,7 @@
Target="host.domain"
Port="2514"
Protocol="tcp"
Template="{{ __test_template }}"
)
}
mode: '0600'
Expand All @@ -167,6 +180,7 @@
Target="host.domain"
Port="3514"
Protocol="tcp"
Template="{{ __test_template }}"
)
}
mode: '0600'
Expand All @@ -188,6 +202,7 @@
Target="host.domain"
Port="4514"
Protocol="tcp"
Template="{{ __test_template }}"
)
}
mode: '0600'
Expand All @@ -209,6 +224,7 @@
Target="host.domain"
Port="6514"
Protocol="udp"
Template="{{ __test_template }}"
)
}
mode: '0600'
Expand All @@ -228,6 +244,7 @@
*.* action(name="forwards_no_severity_and_facility_protocol_port"
type="omfwd"
Target="host.domain"
Template="{{ __test_template }}"
)
}
mode: '0600'
Expand Down Expand Up @@ -356,6 +373,7 @@
StreamDriverPermittedPeers="*.example.com"
Port="1514"
Protocol="tcp"
Template="{{ __test_template }}"
)
}
mode: '0600'
Expand Down Expand Up @@ -479,6 +497,7 @@
StreamDriverPermittedPeers="*.example.com"
Port="1514"
Protocol="tcp"
Template="{{ __test_template }}"
)
}
mode: '0600'
Expand Down
38 changes: 24 additions & 14 deletions tests/tests_combination.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
Target="host.domain"
Port="1514"
Protocol="tcp"
Template="RSYSLOG_ForwardFormat"
)
}
mode: '0600'
Expand All @@ -145,13 +146,17 @@
failed_when: not __result.stat.exists

- name: Check the input call with tag={{ __test_tag }}
command: >-
/bin/grep
' *input(type="imfile"
file="/var/log/inputdirectory/\*.log"
tag="{{ __test_tag }}"'
{{ __test_inputfiles_conf }}
changed_when: false
lineinfile:
path: "{{ __test_inputfiles_conf }}"
line: " {{ item }}"
state: present
check_mode: yes
register: _result
failed_when: _result.changed
loop:
- type="imfile"
- file="/var/log/inputdirectory/*.log"
- tag="{{ __test_tag }}"

# yamllint disable rule:line-length
- name: "Create a test log file with a log message in
Expand Down Expand Up @@ -295,6 +300,7 @@
Target="host.domain"
Port="1514"
Protocol="tcp"
Template="RSYSLOG_ForwardFormat"
)
}
mode: '0600'
Expand All @@ -310,13 +316,17 @@
failed_when: not __result.stat.exists

- name: Check the input call with tag={{ __test_tag }}
command: >-
/bin/grep
' *input(type="imfile"
file="/var/log/inputdirectory/\*.log"
tag="{{ __test_tag }}"'
{{ __test_inputfiles_conf }}
changed_when: false
lineinfile:
path: "{{ __test_inputfiles_conf }}"
line: " {{ item }}"
state: present
check_mode: yes
register: _result
failed_when: _result.changed
loop:
- type="imfile"
- file="/var/log/inputdirectory/*.log"
- tag="{{ __test_tag }}"

# yamllint disable rule:line-length
- name: "Create a test log file with a log message in
Expand Down
Loading

0 comments on commit b220c21

Please sign in to comment.