> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-fbfa8bee.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Connect Splunk dashboards to ClickHouse

# Connecting Splunk to ClickHouse

export const ClickHouseSupportedBadge = () => {
  return <div className="ClickHouseSupportedBadge">
            <div className="ClickHouseSupportedIcon">
                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M1.30762 1.39073C1.30762 1.3103 1.37465 1.22986 1.46849 1.22986H2.64824C2.72868 1.22986 2.80912 1.29689 2.80912 1.39073V14.4886C2.80912 14.5691 2.74209 14.6495 2.64824 14.6495H1.46849C1.38805 14.6495 1.30762 14.5825 1.30762 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M4.2832 1.39073C4.2832 1.3103 4.35023 1.22986 4.44408 1.22986H5.62383C5.70427 1.22986 5.7847 1.29689 5.7847 1.39073V14.4886C5.7847 14.5691 5.71767 14.6495 5.62383 14.6495H4.44408C4.36364 14.6495 4.2832 14.5825 4.2832 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M7.25977 1.39073C7.25977 1.3103 7.3268 1.22986 7.42064 1.22986H8.60039C8.68083 1.22986 8.76127 1.29689 8.76127 1.39073V14.4886C8.76127 14.5691 8.69423 14.6495 8.60039 14.6495H7.42064C7.3402 14.6495 7.25977 14.5825 7.25977 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M10.2354 1.39073C10.2354 1.3103 10.3024 1.22986 10.3962 1.22986H11.576C11.6564 1.22986 11.7369 1.29689 11.7369 1.39073V14.4886C11.7369 14.5691 11.6698 14.6495 11.576 14.6495H10.3962C10.3158 14.6495 10.2354 14.5825 10.2354 14.4886V1.39073Z" fill="currentColor" />
                    <path d="M13.2256 6.6057C13.2256 6.52526 13.2926 6.44482 13.3865 6.44482H14.5662C14.6466 6.44482 14.7271 6.51186 14.7271 6.6057V9.27354C14.7271 9.35398 14.6601 9.43442 14.5662 9.43442H13.3865C13.306 9.43442 13.2256 9.36739 13.2256 9.27354V6.6057Z" fill="currentColor" />
                </svg>
            </div>
            ClickHouse Supported
        </div>;
};

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

<Tip>
  Looking to store ClickHouse audit logs to Splunk? Follow the ["Storing ClickHouse Cloud Audit logs into Splunk"](/integrations/connectors/data-integrations/integrations/splunk) guide.
</Tip>

Splunk is a popular technology for security and observability. It is also a powerful search and dashboarding engine. There are hundreds of Splunk apps available to address different use cases.

For ClickHouse specifically, we're leveraging the [Splunk DB Connect App](https://splunkbase.splunk.com/app/2686) which has a simple integration to the highly performant ClickHouse JDBC driver to query tables in ClickHouse directly.

The ideal use case for this integration is when you're using ClickHouse for large data sources such as NetFlow, Avro or Protobuf binary data, DNS, VPC flow logs, and other OTEL logs that can be shared with your team on Splunk to search and create dashboards. By using this approach, the data isn't ingested into the Splunk index layer and is simply queried directly from ClickHouse similarly to other visualization integrations such as [Metabase](https://www.metabase.com/) or [Superset](https://superset.apache.org/).

<h2 id="goal">
  Goal​
</h2>

In this guide, we will use the ClickHouse JDBC driver to connect ClickHouse to Splunk. We will install a local version of Splunk Enterprise but we're not indexing any data. Instead, we're using the search functions through the DB Connect query engine.

With this guide, you will be able to create a dashboard connected to ClickHouse similar to this:

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-1.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=cf043796679473ddc60b4c6761da8e12" size="lg" border alt="Splunk dashboard showing NYC taxi data visualizations" width="1600" height="879" data-path="images/integrations/splunk/splunk-1.png" />

<Note>
  This guide uses the [New York City Taxi dataset](/get-started/sample-datasets/nyc-taxi). There are many other datasets that you can use from [our docs](http://localhost:3000/docs/getting-started/example-datasets).
</Note>

<h2 id="prerequisites">
  Prerequisites
</h2>

Before you get started you will need:

* Splunk Enterprise to use search head functions
* [Java Runtime Environment (JRE)](https://docs.splunk.com/Documentation/DBX/3.16.0/DeployDBX/Prerequisites) requirements installed on your OS or container
* [Splunk DB Connect](https://splunkbase.splunk.com/app/2686)
* Admin or SSH access to your Splunk Enterprise OS Instance
* ClickHouse connection details (see [here](/integrations/connectors/data-visualization/metabase-and-clickhouse#1-gather-your-connection-details) if you're using ClickHouse Cloud)

<h2 id="install-and-configure-db-connect-on-splunk-enterprise">
  Install and configure DB Connect on Splunk Enterprise
</h2>

You must first install the Java Runtime Environment on your Splunk Enterprise instance. If you're using Docker, you can use the command `microdnf install java-11-openjdk`.

Note down the `java_home` path: `java -XshowSettings:properties -version`.

Ensure that the DB Connect App is installed on Splunk Enterprise. You can find it in the Apps section of the Splunk Web UI:

* Log in to Splunk Web and go to Apps > Find More Apps
* Use the search box to find DB Connect
* Click the green "Install" button next to Splunk DB Connect
* Click "Restart Splunk"

If you're having issues installing the DB Connect App, please see [this link](https://splunkbase.splunk.com/app/2686) for additional instructions.

Once you've verified that the DB Connect App is installed, add the java\_home path  to the DB Connect App in Configuration -> Settings, and click save then reset.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-2.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=a410aebac7ae10316d65da6978a20b7d" size="md" border alt="Splunk DB Connect settings page showing Java Home configuration" width="1600" height="548" data-path="images/integrations/splunk/splunk-2.png" />

<h2 id="configure-jdbc-for-clickhouse">
  Configure JDBC for ClickHouse
</h2>

Download the [ClickHouse JDBC driver JAR file](https://github.com/ClickHouse/clickhouse-java/releases/) and copy it to the DB Connect Drivers folder at:

```bash theme={null}
$SPLUNK_HOME/etc/apps/splunk_app_db_connect/drivers
```

To ensure that all required dependencies are available to the DB Connect App, download one of:

```text theme={null}
- clickhouse-jdbc-<VERSION>-shaded-all.jar (if VERSION < 0.9.0)
- clickhouse-jdbc-<VERSION>-all-dependencies.jar (if VERSION >= 0.9.0)
```

You must then edit the connection types configuration at `$SPLUNK_HOME/etc/apps/splunk_app_db_connect/local/db_connection_types.conf` to add the ClickHouse JDBC Driver class details. Add the following stanza to `db_connection_types.conf`:

```text theme={null}
[ClickHouse]
displayName = ClickHouse
serviceClass = com.splunk.dbx2.DefaultDBX2JDBC
jdbcUrlFormat = jdbc:ch://<host>:<port>/<database>
jdbcUrlSSLFormat = jdbc:ch://<host>:<port>/<database>?ssl=true
jdbcDriverClass = com.clickhouse.jdbc.ClickHouseDriver
ui_default_catalog = $database$
```

Restart Splunk using `$SPLUNK_HOME/bin/splunk restart`.

Navigate back to the DB Connect App and go to Configuration > Settings > Drivers. You should see a green tick next to ClickHouse:

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-3.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=9a8c87d2912b16866e1d90fa1a590928" size="lg" border alt="Splunk DB Connect drivers page showing ClickHouse driver successfully installed" width="1600" height="581" data-path="images/integrations/splunk/splunk-3.png" />

<h2 id="connect-splunk-search-to-clickhouse">
  Connect Splunk search to ClickHouse
</h2>

Navigate to DB Connect App Configuration -> Databases -> Identities: Create a Identity for your ClickHouse.

Create a new Connection to ClickHouse from Configuration -> Databases -> Connections and select "New Connection".

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-4.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=137bdc35ade41a616ee76a5ea4d5ae14" size="sm" border alt="Splunk DB Connect new connection button" width="764" height="1168" data-path="images/integrations/splunk/splunk-4.png" />

<br />

Add ClickHouse host details and ensure "Enable SSL" is ticked:

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-5.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=e81b8e8ce196e4f15193de14fdf04645" size="md" border alt="Splunk connection configuration page for ClickHouse" width="1254" height="990" data-path="images/integrations/splunk/splunk-5.png" />

After saving the connection, you will have successfully connected to ClickHouse to Splunk!

<Note>
  If you receive an error, make sure that you have added the IP address of your Splunk instance to the ClickHouse Cloud IP Access List. See [the docs](/products/cloud/guides/security/connectivity/setting-ip-filters) for more info.
</Note>

<h2 id="run-a-sql-query">
  Run a SQL query
</h2>

We will now run a SQL query to test that everything works.

Select your connection details in the SQL Explorer from the DataLab section of the DB Connect App. We're using the  `trips` table for this demo:

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-6.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=bd2059ea0bd59ecc878c5fc222359895" size="md" border alt="Splunk SQL Explorer selecting connection to ClickHouse" width="1600" height="866" data-path="images/integrations/splunk/splunk-6.png" />

Execute a SQL query on the `trips` table that returns the count of all the records in the table:

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-7.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=042f016c0ca7d29e4e323242f6e5ef4b" size="md" border alt="Splunk SQL query execution showing count of records in trips table" width="1344" height="684" data-path="images/integrations/splunk/splunk-7.png" />

If your query is successful, you should see the results.

<h2 id="create-a-dashboard">
  Create a dashboard
</h2>

Let's create a dashboard that leverages a combination of SQL plus the powerful Splunk Processing Language (SPL).

Before proceeding, you must first [Deactivate DPL Safeguards](https://docs.splunk.com/Documentation/Splunk/9.2.1/Security/SPLsafeguards?ref=hk#Deactivate_SPL_safeguards).

Run the following query that shows us the top 10 neighborhoods that have the most frequent pickups:

```sql theme={null}
dbxquery query="SELECT pickup_ntaname, count(*) AS count
FROM default.trips GROUP BY pickup_ntaname
ORDER BY count DESC LIMIT 10;" connection="chc"
```

Select the visualization tab to view the column chart created:

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-8.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=96c1088a2d468440608966436b75c79c" size="lg" border alt="Splunk column chart visualization showing top 10 pickup neighborhoods" width="1600" height="789" data-path="images/integrations/splunk/splunk-8.png" />

We will now create a dashboard by clicking Save As > Save to a Dashboard.

Let's add another query that shows the average fare based on the number of passengers.

```sql theme={null}
dbxquery query="SELECT passenger_count,avg(total_amount)
FROM default.trips GROUP BY passenger_count;" connection="chc"
```

This time, let's create a bar chart visualization and save it to the previous dashboard.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-9.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=e6d58efe62f076c9d38d1eb1685cf3d8" size="lg" border alt="Splunk bar chart showing average fare by passenger count" width="1600" height="708" data-path="images/integrations/splunk/splunk-9.png" />

Finally, let's add one more query that shows the correlation between the number of passengers and the distance of the trip:

```sql theme={null}
dbxquery query="SELECT passenger_count, toYear(pickup_datetime) AS year,
round(trip_distance) AS distance, count(* FROM default.trips)
GROUP BY passenger_count, year, distance
ORDER BY year, count(*) DESC; " connection="chc"
```

Our final dashboard should look like this:

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/amY-JDMREAaO7mx6/images/integrations/splunk/splunk-10.png?fit=max&auto=format&n=amY-JDMREAaO7mx6&q=85&s=c7566ed866d15a2a2017b1befb44fa2e" size="lg" border alt="Final Splunk dashboard with multiple visualizations of NYC taxi data" width="1600" height="734" data-path="images/integrations/splunk/splunk-10.png" />

<h2 id="time-series-data">
  Time series data
</h2>

Splunk has hundreds of built-in functions that dashboards can use for visualization and presentation of time series data. This example will combine SQL + SPL to create a query that can work with time series data in Splunk

```sql theme={null}
dbxquery query="SELECT time, orig_h, duration
FROM "demo"."conn" WHERE time >= now() - interval 1 HOURS" connection="chc"
| eval time = strptime(time, "%Y-%m-%d %H:%M:%S.%3Q")
| eval _time=time
| timechart avg(duration) as duration by orig_h
| eval duration=round(duration/60)
| sort - duration:
```

<h2 id="learn-more">
  Learn more
</h2>

If you'd like to find more information about Splunk DB Connect and how to build dashboards, please visit the [Splunk documentation](https://docs.splunk.com/Documentation).
