Chapter 4. Forward to Splunk
You can forward logs to Splunk HTTP Event Collector (HEC).
4.1. Forward logs to Splunk HTTP Event Collector Copy linkLink copied to clipboard!
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
Create a secret using your Base64 encoded Splunk HEC token.
$ oc -n openshift-logging create secret generic splunk-secret --from-literal hecToken=<HEC_Token>Create or edit the
ClusterLogForwarderCustom 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-receiverserviceAccount.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_typeandlog_sourcevalues 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_fieldsfields 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
payloadKeyfield is not set, which means the collector forwards the complete log record as the payload. Use thepayloadKeyfield 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
gzipornone. The default value isnone. 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 Copy linkLink copied to clipboard!
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
@timestampfield 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
hostnamefield (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
_jsonfor structured logs orgeneric_single_linefor 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 field | Splunk HEC field | Notes |
|---|---|---|
| Complete log record |
| Entire log record preserved as structured JSON |
|
|
| Converted to epoch seconds with millisecond precision |
|
|
| Kubernetes node name (not configurable) |
| Log type-dependent |
| See default metadata mappings (infrastructure, application, audit) |
| Payload structure |
|
Automatically determined: |
| User-configured |
| 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 Copy linkLink copied to clipboard!
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 field | Infrastructure (journal) | Infrastructure/Application (container) | Audit logs | Notes |
|---|---|---|---|---|
|
|
|
|
| Identifies where the log originated |
|
|
|
|
| Determined automatically based on payload structure |
|
|
|
|
| Not configurable - always uses node hostname |
|
| Not configured | Not configured | Not configured | You must configure index routing in the ClusterLogForwarder |
|
| 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 Copy linkLink copied to clipboard!
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.
| Metadata field | Infrastructure (journal) | Infrastructure/Application (container) | Audit logs | Notes |
|---|---|---|---|---|
|
| Not configured by default. | |||
|
| SYSLOG_IDENTIFIER |
| .log_source | |
|
| Not configured by default. | |||
|
|
|
|
| Determined automatically based on the type of the final event payload. |
|
|
|
|
| Not configurable. |
|
| Not configured by default. |