Author: Kishori Patil

Splunk can read different types of data. After reading the data, it allows search, tag, create reports and dashboards on these data. Mule applications can be configured to send logs to Splunk.

Content

There are 2 ways to send logs to Splunk:

1. HTTP Appender   2. Splunk HTTP Appender

This blog contains steps to send logs from on-premise applications to Splunk using Splunk Http appender.

1.Create a token in Splunk

2.Configure log4j2.xml file

3.Add dependencies in pom.xml

Create a token in Splunk:

HTTP Event Collector allows you to send data and application events to a Splunk deployment over the HTTP and HTTPS protocols. Using the token, you can send data to Splunk. You do not need to include Splunk credentials in your application.

  1. Goto Splunk UI and select setting >Data inputs. Create a new HTTP Event Collector using add new

2. Provide any name to your token and press next

3. Then select a Source type that is log4j as we are sending logs to Splunk using log4j

4. Then select all indexes and make Main as Default index

5. Summary of your token looks something like this:

6. New token is created, which we will use as authorization for Splunk

7. Now go to settings>Data inputs>HTTP Event Collector. You can see the new token created

8. Go to Global Settings and Enable all Tokens by clicking on Enabled. Also, add HTTP port as 8088, now your HTTP Event collector will listen on this port. To make HTTP Event collector listen and communicate over HTTPS rather than HTTP, click the Enable SSL checkbox

9. If you click on edit, you can change any configuration of that token. You can also add a description of that token, name for the source

Configure log4j2.xml file:

  1. Open src/main/resources/log4j2.xml add the following Splunk HTTP appender to appenders. For sending logs to Splunk from the MuleSoft application, you need to provide an URL of Splunk for us its “https://localhost:8088” and Authorization add Token, which we have created in Splunk.

<SplunkHttp name=”splunk” url=”https://localhost:8088/”

token=”7acf9ccb-02a1-482e-a895-ba4ce3934eae” index=”main”

disableCertificateValidation=”true”>

<PatternLayout

pattern=”%-5p %d [%t] [event: %X{correlationId}] %c: %m%n” />

</SplunkHttp> 

  1. Then add AppenderRef, which is nothing but your SplunkHttp name .<AsyncRoot> in the following image. Sends the INFO level logs to Splunk and Console. Depending on your requirement, you can decide which level logs you want to send to Splunk.

Add dependencies in pom.xml:

  1. Add the following dependencies in your pom.xml dependencies section for Splunk.

<dependency>

<groupId>com.splunk.logging</groupId>

<artifactId>splunk-library-javalogging</artifactId>

<version>1.7.1</version>

</dependency>

<dependency>

<groupId>org.apache.logging.log4j</groupId>

<artifactId>log4j-core</artifactId>

<version>2.10.0</version>

</dependency>

<dependency>

<groupId>org.apache.logging.log4j</groupId>

<artifactId>log4j-api</artifactId>

<version>2.10.0</version>

</dependency>

  1. Add following repository in the repositories tag of pom.xml

<repository>

<id>splunk-artifactory</id>

<name>Splunk Releases</name>

<url>https://splunk.jfrog.io/splunk/ext-releases-local</url>

</repository>

  1. Once all the above configurations are done, your application is ready to send logs to Splunk. Deploy your application and make a call to it. Whatever logs you can see in the console are also send to Splunk(logs are sent depending upon your config in log4j).you can decide based on your requirement which logs you want to print in the console and which you want to send to Splunk.

Searching logs in Splunk :

To see logs go to Splunk>Apps>Search & Reporting:

As you can see in the above image you can either type string to search in the search box or click on data summary.

In the Data Summary, there are 3 options available: hosts, Sources, SourceType. Depending upon your choice, you can select one. If we are selecting Sources, you can see it’s the same name that we have added to the source of the token we created. Clicking on this will show logs for this source.

You can create separate tokens for different applications so that you can monitor logs separately. 

Leave a Comment