Chapter 4. Forward to Splunk


You can forward logs to Splunk HTTP Event Collector (HEC).

4.1. Forward logs to Splunk HTTP Event Collector

You can forward logs to the Splunk HTTP Event Collector (HEC).

Prerequisites

  • Ensure that you installed the Red Hat OpenShift Logging Operator
  • You have obtained a Base64 encoded Splunk HEC token.

Procedure

  1. Create a secret using your Base64 encoded Splunk HEC token.

    $ oc -n openshift-logging create secret generic splunk-secret --from-literal hecToken=<HEC_Token>
  2. Create or edit the ClusterLogForwarder Custom Resource (CR) using the template below:

    apiVersion: observability.openshift.io/v1
    kind: ClusterLogForwarder
    metadata:
      name: <log_forwarder_name>
      namespace: openshift-logging
    spec:
      serviceAccount:
        name: <service_account_name>
      outputs:
        - name: splunk-receiver
          type: splunk
          splunk:
            url: '<http://your.splunk.hec.url:8088>'
            authentication:
              token:
                secretName: splunk-secret
                key: hecToken
            index: '{.log_type||"undefined"}'
            source: '{.log_source||"undefined"}'
            indexedFields: ['.log_type', '.log_source']
            payloadKey: '.kubernetes'
            tuning:
                compression: gzip
      pipelines:
        - name: my-logs
          inputRefs:
            - application
            - infrastructure
          outputRefs:
            - splunk-receiver
    serviceAccount.name
    The name of your service account.
    outputs.name
    Specify a name for the output.
    type
    Specify the output type as splunk.
    key
    Specify the name of the secret that has your HEC token.
    url
    Specify the URL, including port, of your Splunk HEC.
    index
    Specify the name of the index to send events to. If you do not specify an index, the Splunk server uses its default index. This is an optional field.
    source
    Specify the source of events to send to this sink. You can configure dynamic per-event values. This field is optional. If you do not specify a value, the log_type and log_source values determine the value of the field. For example, see Default Splunk metadata key values.
    indexedFields
    Specify the fields to add to the Splunk index. This field is optional. The index stores the values directly alongside the raw event data, allowing for faster search performance on those fields. However, indexed_fields fields increase storage use. Use them only for high-value fields that give significant search benefits, for example, large datasets with frequent queries on specific fields. You can use complex and nested fields as indexed fields. These are automatically transformed to meet Splunk’s requirements.
    payloadKey
    Specify the record field to use as the payload. By default, the payloadKey field is not set, which means the collector forwards the complete log record as the payload. Use the payloadKey field carefully. Selecting a single field as the payload might drop other important information in the log, potentially leading to inconsistent or incomplete log events.
    compression
    Specify the compression configuration, which can be either gzip or none. The default value is none. This field is optional.
    inputRefs
    Specify the input names.
    receiver
    Specify the name of the output to use when forwarding logs with this pipeline.

4.2. Splunk HEC output format and field mappings

When you forward logs to Splunk HTTP Event Collector (HEC), the log collector transforms OpenShift log records into the HEC event format. Understanding this transformation helps you configure Splunk searches, dashboards, and alerts.

The log collector sends logs to Splunk HEC by using JSON-formatted POST requests. Each OpenShift log record becomes a single HEC event with the following structure:

time (optional)
Timestamp in epoch seconds with millisecond precision. The collector converts the log record’s @timestamp field to this format. If not specified, Splunk uses the time it receives the event.
host (required)
The source host name. The collector sets this to the log record’s hostname field (typically the OpenShift node name).
source (optional)
The log source identifier. The default value depends on the log type (see metadata mappings table).
sourcetype (optional)
Splunk data format type. The collector automatically sets this to _json for structured logs or generic_single_line for plain text logs.
index (optional)
The Splunk index where the event is stored. You can configure a static index name or dynamically route events to different indexes based on log metadata.
event (required)
The log record payload. The collector preserves the complete OpenShift log record as a JSON object.

The following table shows metadata mappings from OpenShift log records to Splunk HEC fields:

OpenShift fieldSplunk HEC fieldNotes

Complete log record

event

Entire log record preserved as structured JSON

@timestamp

time

Converted to epoch seconds with millisecond precision

hostname

host

Kubernetes node name (not configurable)

Log type-dependent

source

See default metadata mappings (infrastructure, application, audit)

Payload structure

sourcetype

Automatically determined: _json or generic_single_line

User-configured

index

Static index name or dynamic routing based on log metadata

The following OpenShift log record:

{
  "kubernetes": {
    "namespace_name": "my-app",
    "pod_name": "web-1",
    "container_name": "nginx"
  },
  "message": "Error connecting to database",
  "level": "error",
  "@timestamp": "2024-01-15T10:30:00.000Z",
  "hostname": "ip-10-0-1-42.ec2.internal"
}

The log collector transforms this into a Splunk HEC event:

{
  "time": 1705316600.000,
  "host": "ip-10-0-1-42.ec2.internal",
  "source": "my-app_web-1_nginx",
  "sourcetype": "_json",
  "index": "openshift-application",
  "event": {
    "kubernetes": {
      "namespace_name": "my-app",
      "pod_name": "web-1",
      "container_name": "nginx"
    },
    "message": "Error connecting to database",
    "level": "error",
    "@timestamp": "2024-01-15T10:30:00.000Z",
    "hostname": "ip-10-0-1-42.ec2.internal"
  }
}

The following infrastructure log from systemd journal:

{
  "message": "Started container",
  "SYSLOG_IDENTIFIER": "kubelet",
  "hostname": "ip-10-0-1-42.ec2.internal",
  "@timestamp": "2024-01-15T10:30:00.000Z"
}

The log collector transforms this into a Splunk HEC event:

{
  "time": 1705316600.000,
  "host": "ip-10-0-1-42.ec2.internal",
  "source": "kubelet",
  "sourcetype": "_json",
  "index": "openshift-infrastructure",
  "event": {
    "message": "Started container",
    "SYSLOG_IDENTIFIER": "kubelet",
    "hostname": "ip-10-0-1-42.ec2.internal",
    "@timestamp": "2024-01-15T10:30:00.000Z"
  }
}

4.2.1. Default metadata mappings

Red Hat OpenShift Logging Operator sets default values for Splunk metadata fields based on log type and source. You can override these defaults in the spec.output.splunk.source field of the ClusterLogForwarder custom resource.

Metadata fieldInfrastructure (journal)Infrastructure/Application (container)Audit logsNotes

source

SYSLOG_IDENTIFIER

namespace_podname_containername

log_source value

Identifies where the log originated

sourcetype

_json or generic_single_line

_json or generic_single_line

_json or generic_single_line

Determined automatically based on payload structure

host

hostname field

hostname field

hostname field

Not configurable - always uses node hostname

index

Not configured

Not configured

Not configured

You must configure index routing in the ClusterLogForwarder

indexedFields

Not configured

Not configured

Not configured

Optional - extracts specific fields for indexed searching

For infrastructure logs from systemd journal, the source field defaults to the SYSLOG_IDENTIFIER value (for example, kubelet, crio, systemd).

For container logs, the source field defaults to the format namespace_podname_containername (for example, openshift-logging_collector-abc123_collector).

For audit logs, the source field defaults to the audit source type (for example, kubeAPI, openshiftAPI, auditd, ovn).

Splunk HEC requires a valid HEC token with permissions to write to the configured indexes. Provide the token by using a Secret referenced in the ClusterLogForwarder output configuration.

4.3. Default Splunk metadata key values

Red Hat OpenShift Logging Operator sets default values for some Splunk metadata keys if you do not configure them in the spec.output.splunk.source field of the ClusterLogForwarder Custom Resource (CR).

The following table describes the default value that the collector uses for Splunk metadata, depending on log_type and log_source attributes.

Table 4.1. Default metadata key values
Metadata fieldInfrastructure (journal)Infrastructure/Application (container)Audit logsNotes

index

   

Not configured by default.

source

SYSLOG_IDENTIFIER

ns_name_podName_containerName

.log_source

 

indexedFields

   

Not configured by default.

sourceType

_json or generic_single_line

_json or generic_single_line

_json or generic_single_line

Determined automatically based on the type of the final event payload.

host

.hostname

.hostname

.hostname

Not configurable.

payloadKey

   

Not configured by default.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top