ruleset(name="{{ __rsyslog_output.name }}") {
    if (strlen($.omes) > 0) and (strlen($.omes!status) > 0) then {
        # retry case
        if ($.omes!status == 200) or ($.omes!status == 201) or (($.omes!status == 409) and ($.omes!writeoperation == "create")) then {
            stop # successful
        }
        if ($.omes!writeoperation == "unknown") or (strlen($.omes!error!type) == 0) or (strlen($.omes!error!reason) == 0) then {
            call error_es
            stop
        }
        if ($.omes!status == 400) or ($.omes!status < 200) then {
            call error_es
            stop
        }
        # else fall through to retry operation
    }
    if strlen($!es_msg_id) > 0 then {
        set $.es_msg_id = $!es_msg_id;
    } else if (strlen($.omes) > 0) and (strlen($.omes!_id) > 0) then {
        # retry
        set $.es_msg_id = $.omes!_id;
    } else {
        # NOTE: depends on rsyslog being compiled with --enable-uuid
        set $.es_msg_id = $uuid;
    }
    if (strlen($.omes) > 0) and (strlen($.omes!_index) > 0) then {
        # retry
        set $.index_name = $.omes!_index;
    } else {
        set $.index_name = exec_template("prefix_index_template");
    }
    if ($.input_type == "{{ __rsyslog_output.input_type | d('ovirt') }}") and ($.index_prefix startswith "{{ __rsyslog_output.index_prefix }}") then {
        action(
            type="omelasticsearch"
            name="{{ __rsyslog_output.name }}"
{% if __rsyslog_output.server_host is string %}
            server="{{ __rsyslog_output.server_host }}"
{% elif __rsyslog_output.server_host is sequence %}
            server=[{% for srv in __rsyslog_output.server_host %}"{{ srv }}"{{ '' if loop.last else ', ' }}{% endfor %}]
{% else %}
            server="logging-es"
{% endif %}
            serverport="{{ __rsyslog_output.server_port | d(9200) | int }}"
            template="{{ __rsyslog_output.template | d("es_template") }}"
            searchIndex="{{ __rsyslog_output.searchIndex | d("index_template") }}"
            dynSearchIndex="{{ __rsyslog_output.dynSearchIndex | d(true) | ternary('on', 'off') }}"
            searchType="{{ __rsyslog_output.searchType | d("com.redhat.viaq.common") }}"
            bulkmode="{{ __rsyslog_output.bulkmode | d(true) | ternary('on', 'off') }}"
            writeoperation="{{ __rsyslog_output.writeoperation | d("create") }}"
            bulkid="{{ __rsyslog_output.bulkid | d("id_template") }}"
            dynbulkid="{{ __rsyslog_output.dynbulkid | d(true) | ternary('on', 'off') }}"
            allowUnsignedCerts="{{ __rsyslog_output.allowUnsignedCerts | d(false) | ternary('on', 'off') }}"
{% if __rsyslog_output.retryfailures | d(true) %}
            retryfailures="on"
{%   if __rsyslog_output.retryruleset | d() | length > 0 %}
            retryruleset="{{ __rsyslog_output.retryruleset }}"
{%   else %}
            retryruleset="{{ __rsyslog_output.name }}"
{%   endif %}
{% else %}
            retryfailures="off"
{% endif %}
            usehttps="{{ __rsyslog_output.usehttps | d(true) | ternary('on', 'off') }}"
{% if (__rsyslog_output.tls is defined) | ternary(__rsyslog_output.tls, __rsyslog_output.use_cert | d(true)) %}
{%   if __rsyslog_output.ca_cert is defined %}
{%     set __cacert = __rsyslog_output.ca_cert %}
{%   elif __rsyslog_output.ca_cert_src is defined %}
{%     set __cacert = __rsyslog_default_pki_path + __rsyslog_default_pki_cert_dir + __rsyslog_output.ca_cert_src | basename %}
{%   else %}
{%     set __cacert = __rsyslog_default_pki_path + __rsyslog_default_pki_cert_dir + 'es-ca.crt' %}
{%   endif %}
{%   if __rsyslog_output.cert is defined %}
{%     set __mycert = __rsyslog_output.cert %}
{%   elif __rsyslog_output.cert_src is defined %}
{%     set __mycert = __rsyslog_default_pki_path + __rsyslog_default_pki_cert_dir + __rsyslog_output.cert_src | basename %}
{%   else %}
{%     set __mycert = __rsyslog_default_pki_path + __rsyslog_default_pki_cert_dir + 'es-cert.pem' %}
{%   endif %}
{%   if __rsyslog_output.private_key is defined %}
{%     set __myprivkey = __rsyslog_output.private_key %}
{%   elif __rsyslog_output.private_key_src is defined %}
{%     set __myprivkey = __rsyslog_default_pki_path + __rsyslog_default_pki_key_dir + __rsyslog_output.private_key_src | basename %}
{%   else %}
{%     set __myprivkey = __rsyslog_default_pki_path + __rsyslog_default_pki_key_dir + 'es-key.pem' %}
{%   endif %}
            tls.cacert="{{ __cacert }}"
            tls.mycert="{{ __mycert }}"
            tls.myprivkey="{{ __myprivkey }}"
{% endif %}
{% if logging_elasticsearch_password | length > 0 and __rsyslog_output.uid is defined and __rsyslog_output.uid | length > 0 %}
            uid="{{ __rsyslog_output.uid }}"
            pwd="{{ logging_elasticsearch_password }}"
{% endif %}
        )
    }
}
