{% if item.remote_log_path | d() or item.remote_sub_path | d() %}
{%   if item.remote_log_path | d() %}
{%     set __remote_log_path = item.remote_log_path %}
{%   else %}
{%     set __remote_log_path = __rsyslog_system_log_dir ~ item.remote_sub_path %}
{%   endif %}
{%   if item.comment | d() %}
# {{ item.comment }}
{%   endif %}
template(
  name="{{ item.name }}_template"
  type="string"
  string="{{ __remote_log_path }}"
)
ruleset(name="{{ item.name }}"
        queue.type="{{ logging_server_queue_type }}"
        queue.size="{{ logging_server_queue_size }}"
        queue.workerThreads="{{ logging_server_threads }}") {
    # Store remote logs in separate logfiles
{%   if item.property | d() %}
    :{{ item.property }}, {{ item.property_op | d('contains') }}, "{{ item.property_value | d('error') }}" action(name="{{ item.name }}" type="omfile" DynaFile="{{ item.name }}_template" DynaFileCacheSize="{{ item.client_count | d(10) }}" ioBufferSize="{{ item.io_buffer_size | d('65536') }}" asyncWriting="{{ 'on' if item.async_writing | d(false) | bool else 'off' }}")
{%   elif item.exclude | d([]) %}
    {{ item.facility | d('*') }}.{{ item.severity | d('*') }};{{ item.exclude | join(';') }} action(name="{{ item.name }}" type="omfile" DynaFile="{{ item.name }}_template" DynaFileCacheSize="{{ item.client_count | d(10) }}" ioBufferSize="{{ item.io_buffer_size | d('65536') }}" asyncWriting="{{ 'on' if item.async_writing | d(false) | bool else 'off' }}")
{%   else %}
    {{ item.facility | d('*') }}.{{ item.severity | d('*') }} action(name="{{ item.name }}" type="omfile" DynaFile="{{ item.name }}_template" DynaFileCacheSize="{{ item.client_count | d(10) }}" ioBufferSize="{{ item.io_buffer_size | d('65536') }}" asyncWriting="{{ 'on' if item.async_writing | d(false) | bool else 'off' }}")
{%   endif %}
}
{% else %}
{%   set __remote_log_path = __rsyslog_system_log_dir ~ '/remote' %}
# Per-Host Templates for Remote Systems
template(
  name="RemoteMessage"
  type="string"
  string="{{ __remote_log_path }}/msg/%FROMHOST%/%PROGRAMNAME:::secpath-replace%.log"
)

# Template for Remote host auth logs
template(
  name="RemoteHostAuthLog"
  type="string"
  string="{{ __remote_log_path }}/auth/%FROMHOST%/%PROGRAMNAME:::secpath-replace%.log"
)

# Template for Remote host cron logs
template(
  name="RemoteHostCronLog"
  type="string"
  string="{{ __remote_log_path }}/cron/%FROMHOST%/%PROGRAMNAME:::secpath-replace%.log"
)

# Template for Remote service mail logs
template(
  name="RemoteHostMailLog"
  type="string"
  string="{{ __remote_log_path }}/mail/%FROMHOST%/%PROGRAMNAME:::secpath-replace%.log"
)

ruleset(name="{{ item.name }}") {
    # Store remote logs in separate logfiles
    authpriv.*   action(name="remote_authpriv_host_log" type="omfile" DynaFile="RemoteHostAuthLog")
    *.info;mail.none;authpriv.none;cron.none action(name="remote_message" type="omfile" DynaFile="RemoteMessage")
    cron.*       action(name="remote_cron_log" type="omfile" DynaFile="RemoteHostCronLog")
    mail.*       action(name="remote_mail_service_log" type="omfile" DynaFile="RemoteHostMailLog")
}
{% endif %}
