.. SPDX-License-Identifier: Apache-2.0

.. _param-omclickhouse-template:
.. _omclickhouse.parameter.input.template:

template
========

.. index::
   single: omclickhouse; template
   single: template

.. summary-start

Selects the message template that renders the INSERT statement sent to
ClickHouse.

.. summary-end

This parameter applies to :doc:`/configuration/modules/omclickhouse`.

:Name: template
:Scope: input
:Type: word
:Default: `` StdClickHouseFmt``
:Required?: no
:Introduced: not specified

Description
-----------
This is the message format that will be sent to ClickHouse. With the default
``format="values"``, the rendered string must be an INSERT statement.
For ``format="values"``, custom INSERT templates must enable
``option.sql="on"`` in RainerScript.
ClickHouse accepts backslash escape sequences inside string literals, so
``option.stdsql="on"`` is not safe for this module. These are template-level
options, not ``omclickhouse`` action parameters. Only string and list
templates apply SQL escaping to rendered fields; plugin and subtree templates
are rejected for this action even if they declare ``option.sql="on"``.

With ``format="jsoneachrow"``, the template renders one JSON object per
event. Use a list template with ``option.jsonf="on"`` and
``format="jsonf"`` on each property, or a string template that escapes each
property with ``format="json"`` or ``:::json``. A template with any property that is not
JSON-escaped is rejected at configuration time, because a quote or line
break in message content would otherwise end the row and start a new one.
Subtree templates are accepted; plugin-generated templates are rejected.
``option.stdsql``, ``option.sql``, and
``option.json`` are rejected. The module puts the INSERT
in the request URL. Defaults to:

.. note::

   The leading space in `` StdClickHouseFmt`` is intentional. Rsyslog
   registers its built-in templates with a leading space in the internal
   configuration state, and the module looks up the default by that exact
   name. When overriding the parameter yourself, use the natural form
   ``StdClickHouseFmt`` (without the space) as shown below.

.. code-block:: none

   "\"INSERT INTO rsyslog.SystemEvents (severity, facility, "
   "timestamp, hostname, tag, message) VALUES ("
   "%syslogseverity%, %syslogfacility%, "
   "'%timereported:::date-unixtimestamp%', '%hostname%', "
   "'%syslogtag%', '%msg%')\""

Input usage
-----------
.. _omclickhouse.parameter.input.template-usage:

.. code-block:: rsyslog

   module(load="omclickhouse")
   template(name="CustomClickHouseFmt" type="string" option.sql="on"
            string="INSERT INTO rsyslog.SystemEvents (severity, facility, timestamp, hostname, tag, message) VALUES (%syslogseverity%, %syslogfacility%, '%timereported:::date-unixtimestamp%', '%hostname%', '%syslogtag%', '%msg%')")
   action(type="omclickhouse" template="CustomClickHouseFmt")

See also
--------
See also :doc:`/configuration/modules/omclickhouse`.
