Camel Components

Splunk HEC

Since Camel 3.3

Only producer is supported

The Splunk HEC component allows sending data to Splunk using the HTTP Event Collector.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-splunk-hec</artifactId>
    <version>${camel-version}</version>
</dependency>

URI format

splunk-hec:[splunkURL]?[options]

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Splunk HEC component supports the following options which are listed below.

Name Description Default Type

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

sslContextParameters (security)

The SSL configuration (such as the trust store) for the HTTPS connections of all the endpoints. An endpoint can override it with its own sslContextParameters.

SSLContextParameters

useGlobalSslContextParameters (security)

Enable usage of global SSL context parameters.

false

boolean

Endpoint Options

The Splunk HEC endpoint is configured using URI syntax:

splunk-hec:splunkURL

With the following path and query parameters:

Path Parameters

Name Description Default Type

splunkURL (producer)

Required The host name (or IPv4 address) and port of the Splunk HTTP Event Collector, as host:port, for example splunk.example.com:8088. The port is required and no path is allowed; the path is set with splunkEndpoint.

String

Query Parameters

Name Description Default Type

bodyOnly (producer)

Whether to send only the message body as the event, instead of an event with a body and a headers field. Takes precedence over headersOnly.

false

boolean

headersOnly (producer)

Whether to send only the message headers, as a JSON object, as the event, without the message body. Ignored when bodyOnly is true.

false

boolean

host (producer)

The host of the events, written as the host field of each event. Defaults to the host name of the machine that runs Camel (or unknown when it cannot be resolved). This is not the Splunk server to connect to, which is set in the splunkURL path.

String

index (producer)

The Splunk index to store the events in, written as the index field of each event. The HEC token must be allowed to write to this index, otherwise Splunk rejects the event.

camel

String

source (producer)

The source of the events, written as the source field of each event.

camel

String

sourceType (producer)

The sourcetype of the events, written as the sourcetype field of each event. Splunk uses the sourcetype to decide how to parse the event data.

camel

String

splunkEndpoint (producer)

The path of the HTTP Event Collector REST endpoint, appended to the splunkURL. It can hold query parameters, such as /services/collector/event?auto_extract_timestamp=true (Splunk 8.0 or later); wrap such a value in RAW() in the endpoint URI. The producer always sends a JSON event (with the event, time, index, source, sourcetype and host fields), so an endpoint such as /services/collector/raw indexes this JSON as raw text.

/services/collector/event

String

sslContextParameters (producer)

The SSL configuration (such as the trust store) for the HTTPS connection to Splunk. It overrides the sslContextParameters of the component. Without either, the default SSL context of the JVM is used. Ignored when skipTlsVerify is true.

SSLContextParameters

time (producer)

The event time, in seconds since the epoch (UNIX time), written as the time field of each event. The CamelSplunkHECIndexTime header overrides it. Without either, Splunk uses the time it receives the event.

Long

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

https (security)

Whether to connect to the HTTP Event Collector over HTTPS (true) or plain HTTP (false). Over plain HTTP the HEC token and the events are sent unencrypted.

true

boolean

skipTlsVerify (security)

Whether to skip the verification of the TLS certificate of the Splunk server: any server certificate is trusted, the host name is not verified, and the sslContextParameters are ignored. Use it only for testing, for example with a self-signed certificate.

false

boolean

token (security)

Required The HEC token that authenticates the requests, sent in the Authorization header after the word Splunk. It is the token of an HTTP Event Collector input in Splunk, a GUID such as 4b35e71f-6a0f-4bab-94ce-f591ff45eecd, and not the authentication token of a Splunk user.

String

Message Headers

The Splunk HEC component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelSplunkHECIndexTime (producer)

Constant: INDEX_TIME

The event time, in seconds since the epoch (UNIX time), written as the time field of the event. It overrides the time option. Splunk reads the value as seconds, so do not pass milliseconds.

Long

Message Body

The message body at each side of the Splunk HEC component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Producer input

text, bytes, stream, file, value, map, list, pojo or null

The event, written as JSON by Jackson with the headers beside it, or alone with bodyOnly. Bytes, a stream or a file are sent as text. With headersOnly the body is not sent.

  • With headersOnly=true: any

Producer output

unchanged

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

Message body

The body must be serializable to JSON, so it may be sent to Splunk.

A String or a java.util.Map object can be serialized easily.

A byte array, an InputStream, a Reader or a file (such as the body of the file consumer) is converted to text and sent as a JSON string. The payload is written as JSON before the request is sent, so a body that cannot be serialized fails the exchange without sending anything to Splunk.

Use Cases

The Splunk HEC endpoint may be used to stream data to Splunk for ingestion.

It is meant for high-volume ingestion of machine data.

Configuring the index time

By default, the index time for an event is when the event makes it to the Splunk server.

  • Java

  • XML

  • YAML

from("direct:start")
    .to("splunk-hec://localhost:8080?token=token");
<route>
  <from uri="direct:start"/>
  <to uri="splunk-hec://localhost:8080?token=token"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: splunk-hec://localhost:8080
            parameters:
              token: token

If you are ingesting a large enough dataset with a big enough lag, then the time the event hits the server and when that event actually happened could be skewed. If you want to override the index time, you can do so.

Java-only: overrides index time from Kafka header
from("kafka:logs")
        .setHeader("CamelSplunkHECIndexTime", simple("${headers[kafka.HEADERS].lastKey('TIME')}"))
        .to("splunk-hec://localhost:8080?token=token");
  • Java

  • XML

  • YAML

from("kafka:logs")
        .toD("splunk-hec://localhost:8080?token=token&time=${headers[kafka.HEADERS].lastKey('TIME')}");
<route>
  <from uri="kafka:logs"/>
  <toD uri="splunk-hec://localhost:8080?token=token&amp;time=${headers[kafka.HEADERS].lastKey('TIME')}"/>
</route>
- route:
    from:
      uri: kafka:logs
      steps:
        - toD:
            uri: "splunk-hec://localhost:8080?token=token&time=${headers[kafka.HEADERS].lastKey('TIME')}"