Skip to content

Commit b220c21

Browse files
committed
RFE - support template, severity and facility options
- template options to the files & formats output - severity and facility options to the files input (issue #271)
1 parent 06dd3b7 commit b220c21

File tree

12 files changed

+149
-44
lines changed

12 files changed

+149
-44
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Available options:
117117

118118
Available options:
119119
- `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`.
120+
`facility`: Facility to filter the inputs from the files.
121+
`severity`: Severity to filter the inputs from the files.
120122

121123
#### ovirt type
122124

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

251+
logging_files_template_format: Set default template for the files output.
252+
Allowed values are `traditional`, `syslog`, and `modern`. Default to `modern`.
253+
249254
**Note:** Selector options and property-based filter options are exclusive. If Property-based filter options are defined, selector options will be ignored.
250255

251256
**Note:** Unless the above options are given, these local file outputs are configured.
@@ -278,6 +283,10 @@ Available options:
278283
- `tls`: Set to `true` to encrypt the connection using the default TLS implementation used by the provider. Default to `false`.
279284
- `pki_authmode`: Specifying the default network driver authentication mode. `x509/name`, `x509/fingerprint`, or `anon` is accepted. Default to `x509/name`.
280285
- `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 }}`
286+
- `template`: Template format for the particular forwards output. Allowed values are `traditional`, `syslog`, and `modern`. Default to `modern`.
287+
288+
logging_forwards_template_format: Set default template for the forwards output.
289+
Allowed values are `traditional`, `syslog`, and `modern`. Default to `modern`.
281290
282291
**Note:** Selector options and property-based filter options are exclusive. If Property-based filter options are defined, selector options will be ignored.
283292

defaults/main.yml

+8
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,11 @@ logging_domain: '{{ ansible_domain if ansible_domain else ansible_hostname }}'
8181
#
8282
# Password to pass to the elasticsearch output
8383
logging_elasticsearch_password: ""
84+
85+
# Output file format
86+
# Allowed values: "traditional", "syslog", or "modern"; default to "modern"
87+
logging_files_template_format: ""
88+
89+
# Output forward format
90+
# Allowed values: "traditional", "syslog", or "modern"; default to "modern"
91+
logging_forwards_template_format: ""

roles/rsyslog/defaults/main.yml

-6
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,3 @@ rsyslog_extra_packages: []
3131
# List of additional custom config files.
3232
# Each element: full paths to the files to be deployed.
3333
rsyslog_custom_config_files: []
34-
35-
# rsyslog_basics_use_traditional_timestamp_format
36-
#
37-
# Traditional timestamp format looks like 'Mar 27 14:16:47'
38-
# By setting false, it'd change 2020-03-27T14:16:47.139796+00:00)
39-
rsyslog_basics_use_traditional_timestamp_format: true

roles/rsyslog/tasks/inputs/files/main.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
type: input
1919
state: "{{ __rsyslog_input.state | d('present') }}"
2020
sections:
21-
- options: |-
22-
input(type="imfile" file="{{ __rsyslog_input.input_log_path }}" tag="{{ __rsyslog_input.name }}")
23-
{{ lookup("template", "input_template.j2") }}
21+
- options: "{{ lookup('template', 'input_files.j2') }}"
2422
include_tasks:
2523
file: "{{ role_path }}/tasks/deploy.yml"
2624
when:
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
input(
2+
type="imfile"
3+
file="{{ __rsyslog_input.input_log_path }}"
4+
tag="{{ __rsyslog_input.name }}"
5+
{% if __rsyslog_input.severity is defined %}
6+
severity="{{ __rsyslog_input.severity }}"
7+
{% endif %}
8+
{% if __rsyslog_input.facility is defined %}
9+
facility="{{ __rsyslog_input.facility }}"
10+
{% endif %}
11+
)
12+
{{ lookup('template', 'input_template.j2') }}

roles/rsyslog/templates/output_forwards.j2

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ ruleset(name="{{ __rsyslog_output.name }}") {
2929
{% endif %}
3030
{% if __forwards_protocol != '' %}
3131
Protocol="{{ __forwards_protocol }}"
32+
{% endif %}
33+
{% if __rsyslog_output.template | d('') == 'traditional' %}
34+
Template="RSYSLOG_TraditionalForwardFormat"
35+
{% elif __rsyslog_output.template | d('') == 'syslog' %}
36+
Template="RSYSLOG_SyslogProtocol23Format"
37+
{% else %}
38+
Template="RSYSLOG_ForwardFormat"
3239
{% endif %}
3340
)
3441
}

roles/rsyslog/vars/outputs/files/main.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ __rsyslog_conf_files_output_modules:
1919
type: 'modules'
2020
sections:
2121

22-
- comment: 'Log messages into files with timestamp format either
23-
traditional or default'
22+
# yamllint disable rule:line-length
23+
- comment: 'Log messages into files with traditional, syslog, or
24+
default format'
2425
options: |-
25-
{% if rsyslog_basics_use_traditional_timestamp_format | d(true) %}
26+
{% if logging_files_template_format == "traditional" %}
2627
module(load="builtin:omfile" Template="RSYSLOG_TraditionalFileFormat")
28+
{% elif logging_files_template_format == "syslog" %}
29+
module(load="builtin:omfile" Template="RSYSLOG_SyslogProtocol23Format")
2730
{% else %}
2831
module(load="builtin:omfile")
2932
{% endif %}
33+
# yamllint enable rule:line-length

roles/rsyslog/vars/outputs/forwards/main.yml

+25-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,28 @@
66

77
# List of rpm packages for Forwards output.
88
__rsyslog_forwards_output_packages: []
9-
__rsyslog_forwards_output_rules: []
9+
10+
# Forwards Rsyslog output configuration rules
11+
# -------------------------------------------
12+
__rsyslog_forwards_output_rules:
13+
- '{{ __rsyslog_conf_forwards_output_modules }}'
14+
15+
# __rsyslog_conf_forwards_output_modules:
16+
__rsyslog_conf_forwards_output_modules:
17+
18+
- name: 'output-forwards-modules'
19+
type: 'modules'
20+
sections:
21+
22+
# yamllint disable rule:line-length
23+
- comment: 'Log messages into files with traditional, syslog, or
24+
default format'
25+
options: |-
26+
{% if logging_forwards_template_format == "traditional" %}
27+
module(load="builtin:omfwd" Template="RSYSLOG_TraditionalForwardFormat")
28+
{% elif logging_forwards_template_format == "syslog" %}
29+
module(load="builtin:omfwd" Template="RSYSLOG_SyslogProtocol23Format")
30+
{% else %}
31+
module(load="builtin:omfwd")
32+
{% endif %}
33+
# yamllint enable rule:line-length

tests/tests_basics_files.yml

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
Target="host.domain"
325325
Port="1514"
326326
Protocol="tcp"
327+
Template="RSYSLOG_ForwardFormat"
327328
)
328329
}
329330
mode: '0600'

tests/tests_basics_forwards.yml

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
vars:
66
__test_files_conf: >-
77
/etc/rsyslog.d/30-output-files-default_files.conf
8+
__test_forward_module_conf: /etc/rsyslog.d/10-output-forwards-modules.conf
89
__test_forward_conf_s_f: >-
910
/etc/rsyslog.d/30-output-forwards-forwards_severity_and_facility.conf
1011
__test_forward_conf_f: >-
@@ -27,19 +28,24 @@
2728
__expected_error: "Error: tls is enabled in forwards_severity_and_facility;
2829
you must specify logging_pki_files ca_cert_src and/or ca_cert in the
2930
playbook var section."
31+
__test_template: RSYSLOG_ForwardFormat
32+
__test_template_trad: RSYSLOG_TraditionalForwardFormat
33+
__test_template_sys: RSYSLOG_SyslogProtocol23Format
3034

3135
tasks:
3236
# TEST CASE 0
3337
- name: "TEST CASE 0; Ensure that the logs from basics inputs
3438
are sent to the forwards outputs and implicit files output"
3539
vars:
40+
logging_forwards_template_format: traditional
3641
logging_outputs:
3742
- name: forwards_severity_and_facility
3843
type: forwards
3944
facility: local1
4045
severity: info
4146
target: host.domain
4247
tcp_port: 1514
48+
template: syslog
4349
- name: forwards_facility_only
4450
type: forwards
4551
facility: local2
@@ -112,6 +118,11 @@
112118
- ca-certificates
113119
include_tasks: tasks/check_packages.yml
114120

121+
- name: >-
122+
Check the module param template is set to "{{ __test_template_trad }}"
123+
command: >-
124+
grep '{{ __test_template_trad }}' '{{ __test_forward_module_conf }}'
125+
115126
- name: Generate a file to check severity_and_facility
116127
copy:
117128
dest: /tmp/__testfile__
@@ -125,6 +136,7 @@
125136
Target="host.domain"
126137
Port="1514"
127138
Protocol="tcp"
139+
Template="{{ __test_template_sys }}"
128140
)
129141
}
130142
mode: '0600'
@@ -146,6 +158,7 @@
146158
Target="host.domain"
147159
Port="2514"
148160
Protocol="tcp"
161+
Template="{{ __test_template }}"
149162
)
150163
}
151164
mode: '0600'
@@ -167,6 +180,7 @@
167180
Target="host.domain"
168181
Port="3514"
169182
Protocol="tcp"
183+
Template="{{ __test_template }}"
170184
)
171185
}
172186
mode: '0600'
@@ -188,6 +202,7 @@
188202
Target="host.domain"
189203
Port="4514"
190204
Protocol="tcp"
205+
Template="{{ __test_template }}"
191206
)
192207
}
193208
mode: '0600'
@@ -209,6 +224,7 @@
209224
Target="host.domain"
210225
Port="6514"
211226
Protocol="udp"
227+
Template="{{ __test_template }}"
212228
)
213229
}
214230
mode: '0600'
@@ -228,6 +244,7 @@
228244
*.* action(name="forwards_no_severity_and_facility_protocol_port"
229245
type="omfwd"
230246
Target="host.domain"
247+
Template="{{ __test_template }}"
231248
)
232249
}
233250
mode: '0600'
@@ -356,6 +373,7 @@
356373
StreamDriverPermittedPeers="*.example.com"
357374
Port="1514"
358375
Protocol="tcp"
376+
Template="{{ __test_template }}"
359377
)
360378
}
361379
mode: '0600'
@@ -479,6 +497,7 @@
479497
StreamDriverPermittedPeers="*.example.com"
480498
Port="1514"
481499
Protocol="tcp"
500+
Template="{{ __test_template }}"
482501
)
483502
}
484503
mode: '0600'

tests/tests_combination.yml

+24-14
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
Target="host.domain"
131131
Port="1514"
132132
Protocol="tcp"
133+
Template="RSYSLOG_ForwardFormat"
133134
)
134135
}
135136
mode: '0600'
@@ -145,13 +146,17 @@
145146
failed_when: not __result.stat.exists
146147

147148
- name: Check the input call with tag={{ __test_tag }}
148-
command: >-
149-
/bin/grep
150-
' *input(type="imfile"
151-
file="/var/log/inputdirectory/\*.log"
152-
tag="{{ __test_tag }}"'
153-
{{ __test_inputfiles_conf }}
154-
changed_when: false
149+
lineinfile:
150+
path: "{{ __test_inputfiles_conf }}"
151+
line: " {{ item }}"
152+
state: present
153+
check_mode: yes
154+
register: _result
155+
failed_when: _result.changed
156+
loop:
157+
- type="imfile"
158+
- file="/var/log/inputdirectory/*.log"
159+
- tag="{{ __test_tag }}"
155160

156161
# yamllint disable rule:line-length
157162
- name: "Create a test log file with a log message in
@@ -295,6 +300,7 @@
295300
Target="host.domain"
296301
Port="1514"
297302
Protocol="tcp"
303+
Template="RSYSLOG_ForwardFormat"
298304
)
299305
}
300306
mode: '0600'
@@ -310,13 +316,17 @@
310316
failed_when: not __result.stat.exists
311317

312318
- name: Check the input call with tag={{ __test_tag }}
313-
command: >-
314-
/bin/grep
315-
' *input(type="imfile"
316-
file="/var/log/inputdirectory/\*.log"
317-
tag="{{ __test_tag }}"'
318-
{{ __test_inputfiles_conf }}
319-
changed_when: false
319+
lineinfile:
320+
path: "{{ __test_inputfiles_conf }}"
321+
line: " {{ item }}"
322+
state: present
323+
check_mode: yes
324+
register: _result
325+
failed_when: _result.changed
326+
loop:
327+
- type="imfile"
328+
- file="/var/log/inputdirectory/*.log"
329+
- tag="{{ __test_tag }}"
320330

321331
# yamllint disable rule:line-length
322332
- name: "Create a test log file with a log message in

0 commit comments

Comments
 (0)