Skip to content

Commit

Permalink
better log forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
tazend committed Jun 3, 2024
1 parent f7cc57f commit e680981
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 79 deletions.
3 changes: 2 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
dest: /etc/rsyslog.d/{{ rsyslog_forward_rule_name }}.conf
mode: "0644"
when:
- not rsyslog_deploy_default_config
- rsyslog_remotes is defined
- rsyslog_remotes | length
notify:
- Restart rsyslog

Expand Down
35 changes: 0 additions & 35 deletions templates/advanced_rsyslog.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,3 @@ include(file="/etc/rsyslog.d/*.conf" mode="optional")
{{ item.rule }} {{ item.logpath }}
{% endfor %}
{% endif %}

##########################
#### FORWARDING RULES ####
##########################

# The statement between the begin and end comments define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!

# An on-disk queue is created for these actions. If the remote host is
# down, messages are spooled to disk and sent when it is up again.

# Example
# *.* action(type="omfwd" Target="logging.server.net" Port="514" Protocol="tcp")

{% for remote in rsyslog_remotes %}
### begin forwarding rule ###
# Uncomment the lines below if you wish to configure further.
#queue.filename="fwdRule1" # unique name prefix for spool files
#queue.maxdiskspace="1g" # 1gb space limit (use as much as possible)
#queue.saveonshutdown="on" # save messages to disk on shutdown
#queue.type="LinkedList" # run asynchronously
#action.resumeRetryCount="-1" # infinite retries if host is down
{{ remote.selector }} action(type="omfwd" Target="{{ remote.hostname }}"
{% if remote.port %}
Port="{{ remote.port }}"
{% endif %}
Protocol="{{ 'tcp' if remote.tcp else 'udp' }}"
{% if remote.template %}
Template="{{ remote.template }}"
{% endif %}
KeepAlive="on")
### end forwarding rule ###

{% endfor %}
26 changes: 10 additions & 16 deletions templates/forward_rule.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,36 @@
# Example
# *.* @@logging.server.net:514

{% for remote in rsyslog_remotes %}
### begin forwarding rule ###
# Uncomment the lines below if you wish to configure further.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList # run asynchronously
#$ActionResumeRetryCount -1 # infinite retries if host is down
{{ remote.selector }} {{ '@@' if remote.tcp else '@' }}{{ remote.hostname }}{{ ':' if remote.port }}{{ remote.port }}
### end forwarding rule ###

{% for remote in rsyslog_remotes %}
{{ remote.selector }} {{ '@@' if remote.protocol is defined and remote.protocol == 'tcp' else '@' }}{{ remote.hostname }}{{ ':' if remote.port is defined }}{{ remote.port | default(":514") }}
{% endfor %}
### end forwarding rule ###
{% endif %}

{% if rsyslog_config_file_format == 'advanced' %}
# Example
# *.* action(type="omfwd" Target="logging.server.net" Port="514" Protocol="tcp")

{% for remote in rsyslog_remotes %}
### begin forwarding rule ###
# Uncomment the lines below if you wish to configure further.
#queue.filename="fwdRule1" # unique name prefix for spool files
#queue.maxdiskspace="1g" # 1gb space limit (use as much as possible)
#queue.saveonshutdown="on" # save messages to disk on shutdown
#queue.type="LinkedList" # run asynchronously
#action.resumeRetryCount="-1" # infinite retries if host is down
{{ remote.selector }} action(type="omfwd" Target="{{ remote.hostname }}"
{% if remote.port %}
Port="{{ remote.port }}"
{% endif %}
Protocol="{{ 'tcp' if remote.tcp else 'udp' }}"
{% if remote.template %}
Template="{{ remote.template }}"
{% endif %}
KeepAlive="on")
### end forwarding rule ###

{% for remote in rsyslog_remotes %}
{{ remote.selector }} action(type="omfwd" Target="{{ remote.hostname }}" Port="{{ remote.port | default(514) }}" Protocol="{{ remote.protocol | default('tcp') }}"
{%- if remote.template is defined %}
Template="{{ remote.template }}"
{%- endif %}
KeepAlive="on")
{% endfor %}
### end forwarding rule ###
{% endif %}
27 changes: 0 additions & 27 deletions templates/legacy_rsyslog.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,3 @@ $PreserveFQDN on
{{ item.rule }} {{ item.logpath }}
{% endfor %}
{% endif %}

##########################
#### FORWARDING RULES ####
##########################

# The statement between the begin and end comments define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!

# An on-disk queue is created for these actions. If the remote host is
# down, messages are spooled to disk and sent when it is up again.

# Example
# *.* @@logging.server.net:514

{% for remote in rsyslog_remotes %}
### begin forwarding rule ###
# Uncomment the lines below if you wish to configure further.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList # run asynchronously
#$ActionResumeRetryCount -1 # infinite retries if host is down
{{ remote.selector }} {{ '@@' if remote.tcp else '@' }}{{ remote.hostname }}{{ ':' if remote.port }}{{ remote.port }}
### end forwarding rule ###

{% endfor %}

0 comments on commit e680981

Please sign in to comment.