# omhttp: HTTP Output Module

Module Name: | omhttp
Module Type: | contributed - not maintained by rsyslog core team
Current Maintainer: | Nelson Yen
Original Author: | Christian Tramnitz

## Purpose

This module provides the ability to send messages over an HTTP REST interface.

This module supports sending messages in individual requests (the default), and batching multiple messages into a single request. Support for retrying failed requests is available in both modes. GZIP compression is configurable with the compress parameter. TLS encryption is configurable with the useHttps parameter and associated tls parameters.

In the default mode, every message is sent in its own HTTP request and it is a drop-in replacement for any other output module. In batch mode, the module implements several batch formatting options that are configurable via the batch.format parameter. Some additional attention to message formatting and retry strategy is required in this mode.

See the Examples section for some configuration examples.

## Notable Features

- Statistic Counter

- Message Batching, supports several formats.

    - Newline concatenation, like the Elasticsearch bulk format.

    - JSON Array as a generic batching strategy.

    - Kafka REST Proxy format, to support sending data through the Confluent Kafka REST API to a Kafka cluster.

## Configuration Parameters

Note

Parameter names are case-insensitive; camelCase is recommended for readability.

### Input Parameters

Parameter | Summary
--- | ---
server | Defines the list of HTTP server hostnames or IP addresses that omhttp connects to.
serverport | Specifies the TCP port that omhttp uses when connecting to the configured HTTP server.
healthchecktimeout | Sets the number of milliseconds omhttp waits before a health check request times out.
httpcontenttype | Overrides the HTTP `Content-Type` header that omhttp sends with each request.
httpheaderkey | Defines the single custom HTTP header name to send with each omhttp request.
httpheadervalue | Provides the value for the single custom HTTP header defined by httpheaderkey.
httpheaders | Configures an array of additional HTTP headers that omhttp sends with each request.
httpretrycodes | Lists HTTP status codes that omhttp treats as retriable errors.
httpignorablecodes | Lists HTTP status codes that omhttp never retries.
proxyhost | Sets the hostname of the HTTP proxy that omhttp should use.
proxyport | Sets the port number of the HTTP proxy used by omhttp.
uid | Provides the username for HTTP basic authentication.
pwd | Provides the password for HTTP basic authentication.
restpath | Sets the REST path portion of the request URL used by omhttp.
dynrestpath | Enables using a template name in restpath so each message can select a REST path dynamically.
restpathtimeout | Specifies how long omhttp waits for a dynamic REST path template to resolve.
checkpath | Defines the health-check endpoint that omhttp polls to decide when to resume after suspension.
batch | Enables batching so omhttp queues messages and submits them in a single HTTP request.
batch.format | Chooses how omhttp combines multiple messages when batching is enabled.
batch.maxsize | Limits how many messages omhttp includes in a batch.
batch.maxbytes | Limits the serialized size of each batched HTTP payload.
template | Selects the rsyslog template used to render each message before omhttp submits it.
retry | Enables omhttp’s internal retry logic that requeues failed requests for another attempt.
retry.ruleset | Names the ruleset where omhttp requeues failed messages when retry is enabled.
retry.addmetadata | Adds HTTP response metadata to `$!omhttp!response` for messages handled by the retry logic.
ratelimit.interval | Controls the duration, in seconds, of the rate-limiting window for the retry ruleset.
ratelimit.burst | Sets how many messages the retry ruleset may emit within each rate-limiting window.
errorfile | Specifies a file where omhttp records HTTP requests that return error responses.
compress | Enables GZIP compression of each HTTP payload sent by omhttp.
compress.level | Sets the zlib compression level used when compress is enabled.
useHttps | Switches omhttp to use HTTPS instead of HTTP when sending requests.
tls.cacert | Points omhttp to the CA bundle used to verify HTTPS servers.
tls.mycert | Supplies the client certificate file used for HTTPS mutual authentication.
tls.myprivkey | Provides the private key file that pairs with tls.mycert.
allowunsignedcerts | Controls whether omhttp skips server certificate validation when using HTTPS.
skipverifyhost | Controls whether omhttp verifies the HTTPS server hostname.
reloadonhup | Reinitializes libcurl handles on `HUP` signals so certificates can be refreshed without restarting rsyslog.
statsname | Assigns a dedicated statistics counter origin name for this omhttp action.

#### statsbysenders

type | default | mandatory | `obsolete legacy` directive
--- | --- | --- | ---
binary | off | no | none

This parameter configures omhttp to generate statistics on a per-destination-server basis, rather than per action instance. The destination servers are specified in the server parameter. if this is enabled, the name of the stats will be: “<instance name>(<server name>)”. if this is disabled, the name of the stats will be: “<instance name>(ALL)”.

#### profile

type | default | mandatory | `obsolete legacy` directive
--- | --- | --- | ---
word | none | no | none

The profile allow user to use a defined profile supported by this module. The list of the current supported profile is :

1. loki : allow Rsyslog to send data to the loki endpoint “loki/api/v1/push”

2. hec:splunk:event : allow Rsyslog to send data to the Splunk HEC endpoint “event”. This profile use a custom template to format logs into json :

    {"event":"%rawmsg:::json%"}

3. hec:splunk:raw : allow Rsyslog to send data to the Splunk HEC endpoint “raw”. This profile use a custom template to format logs :

    %rawmsg:::drop-last-lf%\n

Other name set up here is ignored.

#### token

type | default | mandatory | `obsolete legacy` directive
--- | --- | --- | ---
word | none | no | none

The token is necessary when you use the profile “hec:splunk:event” or “hec:splunk:raw”. The token to set up is given by when you create a Splunk HEC. This value is ignored if you use other profile.

## Statistic Counter

This plugin maintains global statistics for omhttp that accumulates all action instances. The statistic origin is named “omhttp” with following counters:

- messages.submitted - Number of messages submitted to omhttp. Messages resubmitted via a retry ruleset will be counted twice.

- messages.success - Number of messages successfully sent.

- messages.fail - Number of messages that omhttp failed to deliver for any reason.

- messages.retry - Number of messages that omhttp resubmitted for retry via the retry ruleset.

- request.success - Number of successful HTTP requests. A successful request can return any HTTP status code.

- request.fail - Number of failed HTTP requests. A failed request is something like an invalid SSL handshake, or the server is not reachable. Requests returning 4XX or 5XX HTTP status codes are not failures.

- request.status.success - Number of requests returning 1XX or 2XX HTTP status codes.

- request.status.fail - Number of requests returning 3XX, 4XX, or 5XX HTTP status codes. If a requests fails (i.e. server not reachable) this counter will not be incremented.

Additionally, the following statistics can also be configured for a specific action instances. See statsname for more details.

- requests.count - Number of requests

- requests.status.0xx - Number of failed requests. 0xx errors indicate request never reached destination.

- requests.status.1xx - Number of HTTP requests returning 1xx status codes

- requests.status.2xx - Number of HTTP requests returning 2xx status codes

- requests.status.3xx - Number of HTTP requests returning 3xx status codes

- requests.status.4xx - Number of HTTP requests returning 4xx status codes

- requests.status.5xx - Number of HTTP requests returning 5xx status codes

- requests.bytes - Total number of bytes sent - derived from CURLINFO_REQUEST_SIZE.

- requests.time_ms - Total accumulated request time in milliseconds - derived from CURLINFO_TOTAL_TIME.

## Message Batching

See the batch.format section for some light examples of available batching formats.

### Implementation

Here’s the pseudocode of the batching algorithm used by omhttp. This section of code would run once per transaction.

    Q = Queue()

    def submit(Q):                      # function to submit
        batch = serialize(Q)            # serialize according to configured batch.format
        result = post(batch)            # HTTP post serialized batch to server
        checkFailureAndRetry(Q, result) # check if post failed and pushed failed messages to configured retry.ruleset
        Q.empty()                       # reset for next batch

    while isActive(transaction):            # rsyslog manages the transaction
        message = receiveMessage()          # rsyslog sends us messages
        if wouldTriggerSubmit(Q, message):  # if this message puts us over maxbytes or maxsize
            submit(Q)                       # submit the current batch
        Q.push(message)                     # queue this message on the current batch

    submit(Q)   # transaction is over, submit what is currently in the queue

### Walkthrough

This is a run through of a file tailing to omhttp scenario. Suppose we have a file called `/var/log/my.log` with this content..

    001 message
    002 message
    003 message
    004 message
    005 message
    006 message
    007 message
    ...

We are tailing this using imfile and defining a template to generate a JSON payload…

    input(type="imfile" File="/var/log/my.log" ruleset="rs_omhttp" ... )

    # Produces JSON formatted payload
    template(name="tpl_omhttp_json" type="list") {
        constant(value="{")   property(name="msg"           outname="message"   format="jsonfr")
        constant(value=",")   property(name="hostname"      outname="host"      format="jsonfr")
        constant(value=",")   property(name="timereported"  outname="timestamp" format="jsonfr" dateFormat="rfc3339")
        constant(value="}")
    }

Our omhttp ruleset is configured to batch using the jsonarray format with 5 messages per batch, and to use a retry ruleset.

    module(load="omhttp")

    ruleset(name="rs_omhttp") {
        action(
            type="omhttp"
            template="tpl_omhttp_json"
            batch="on"
            batch.format="jsonarray"
            batch.maxsize="5"
            retry="on"
            retry.ruleset="rs_omhttp_retry"
            ...
        )
    }

    call rs_omhttp

Each input message to this omhttp action is the output of `tpl_omhttp_json` with the following structure..

    {"message": "001 message", "host": "localhost", "timestamp": "2018-12-28T21:14:13.840470+00:00"}

After 5 messages have been queued, and a batch submit is triggered, omhttp serializes the messages as a JSON array and attempts to post the batch to the server. At this point the payload on the wire looks like this..

    [
        {"message": "001 message", "host": "localhost", "timestamp": "2018-12-28T21:14:13.000000+00:00"},
        {"message": "002 message", "host": "localhost", "timestamp": "2018-12-28T21:14:14.000000+00:00"},
        {"message": "003 message", "host": "localhost", "timestamp": "2018-12-28T21:14:15.000000+00:00"},
        {"message": "004 message", "host": "localhost", "timestamp": "2018-12-28T21:14:16.000000+00:00"},
        {"message": "005 message", "host": "localhost", "timestamp": "2018-12-28T21:14:17.000000+00:00"}
    ]

If the request fails, omhttp requeues each failed message onto the retry ruleset. However, recall that the inputs to the `rs_omhttp` ruleset are the rendered outputs of `tpl_json_omhttp`, and therefore we cannot use the same template (and therefore the same action instance) to produce the retry messages. At this point, the `msg` rsyslog property is `{"message": "001 message", "host": "localhost", "timestamp": "2018-12-28T21:14:13.000000+00:00"}` instead of the original `001 message`, and `tpl_json_omhttp` would render incorrect payloads.

Instead we define a simple template that echos its input..

    template(name="tpl_echo" type="string" string="%msg%")

And assign it to the retry template..

    ruleset(name="rs_omhttp_retry") {
        action(
            type="omhttp"
            template="tpl_echo"
            batch="on"
            batch.format="jsonarray"
            batch.maxsize="5"
            ...
        )
    }

And the destination is none the wiser! The newline, jsonarray, and kafkarest formats all behave in the same way with respect to their batching and retry behavior, and differ only in the format of the on-the-wire payload. The formats themselves are described in the batch.format section.

## Examples

### Example 1

The following example is a basic usage, first the module is loaded and then the action is used with a standard retry strategy.

    module(load="omhttp")
    template(name="tpl1" type="string" string="{\"type\":\"syslog\", \"host\":\"%HOSTNAME%\"}")
    action(
        type="omhttp"
        server="127.0.0.1"
        serverport="8080"
        restpath="events"
        template="tpl1"
        action.resumeRetryCount="3"
    )

### Example 2

The following example is a basic batch usage with no retry processing.

    module(load="omhttp")
    template(name="tpl1" type="string" string="{\"type\":\"syslog\", \"host\":\"%HOSTNAME%\"}")
    action(
        type="omhttp"
        server="127.0.0.1"
        serverport="8080"
        restpath="events"
        template="tpl1"
        batch="on"
        batch.format="jsonarray"
        batch.maxsize="10"
    )

### Example 3

The following example is a batch usage with a retry ruleset that retries forever

    module(load="omhttp")

    template(name="tpl_echo" type="string" string="%msg%")
    ruleset(name="rs_retry_forever") {
        action(
            type="omhttp"
            server="127.0.0.1"
            serverport="8080"
            restpath="events"
            template="tpl_echo"

            batch="on"
            batch.format="jsonarray"
            batch.maxsize="10"

            retry="on"
            retry.ruleset="rs_retry_forever"
        )
    }

    template(name="tpl1" type="string" string="{\"type\":\"syslog\", \"host\":\"%HOSTNAME%\"}")
    action(
        type="omhttp"
        server="127.0.0.1"
        serverport="8080"
        restpath="events"
        template="tpl1"

        batch="on"
        batch.format="jsonarray"
        batch.maxsize="10"

        retry="on"
        retry.ruleset="rs_retry_forever"
    )

### Example 4

The following example is a batch usage with a couple retry options

    module(load="omhttp")

    template(name="tpl_echo" type="string" string="%msg%")

    # This retry ruleset tries to send batches once then logs failures.
    # Error log could be tailed by rsyslog itself or processed by some
    # other program.
    ruleset(name="rs_retry_once_errorfile") {
        action(
            type="omhttp"
            server="127.0.0.1"
            serverport="8080"
            restpath="events"
            template="tpl_echo"

            batch="on"
            batch.format="jsonarray"
            batch.maxsize="10"

            retry="off"
            errorfile="/var/log/rsyslog/omhttp_errors.log"
        )
    }

    # This retry ruleset gives up trying to batch messages and instead always
    # uses a batch size of 1, relying on the suspend/resume mechanism to do
    # further retries if needed.
    ruleset(name="rs_retry_batchsize_1") {
        action(
            type="omhttp"
            server="127.0.0.1"
            serverport="8080"
            restpath="events"
            template="tpl_echo"

            batch="on"
            batch.format="jsonarray"
            batch.maxsize="1"
            action.resumeRetryCount="-1"
        )
    }

    template(name="tpl1" type="string" string="{\"type\":\"syslog\", \"host\":\"%HOSTNAME%\"}")
    action(
        type="omhttp"
        template="tpl1"

        ...

        retry="on"
        retry.ruleset="<some_retry_ruleset>"
    )

### Example 5

The following example is a batch action for pushing logs with checking, and queues to Loki.

    module(load="omhttp")

    template(name="loki" type="string" string="{\"stream\":{\"host\":\"%HOSTNAME%\",\"facility\":\"%syslogfacility-text%\",\"priority\":\"%syslogpriority-text%\",\"syslogtag\":\"%syslogtag%\"},\"values\": [[ \"%timegenerated:::date-unixtimestamp%000000000\", \"%msg%\" ]]}")

    action(
        name="loki"
        type="omhttp"
        useHttps="off"
        server="localhost"
        serverport="3100"
        checkpath="ready"

        restpath="loki/api/v1/push"
        template="loki"
        batch.format="lokirest"
        batch="on"
        batch.maxsize="10"

        queue.size="10000" queue.type="linkedList"
        queue.workerthreads="3"
        queue.workerthreadMinimumMessages="1000"
        queue.timeoutWorkerthreadShutdown="500"
        queue.timeoutEnqueue="10000"
    )

Support: rsyslog Assistant | GitHub Discussions | GitHub Issues: rsyslog source project

Contributing: Source & docs: rsyslog source project

© 2008–2025 Rainer Gerhards and others. Licensed under the Apache License 2.0.