• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

send some message to Splunk using index from spring boot Application

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Team is there any guide or example where I will
send some message to Splunk using index  from  spring boot Application.


Thanks.
Kula
 
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Have you already consulted the official documentation?

https://dev.splunk.com/enterprise/docs/devtools/java/
 
sadhu paikaray
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,Stephan but I am not getting any proper example , they gave small info only , I am able to login to Splunk but some where I am facing issue to send log to Splunk.
 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us what you've written, and tell us what your "issue to send log to Splunk" is.
 
sadhu paikaray
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stephan ,

   Please have a look below details. Anything i am missing on this ?


Controller :
------------


@RestController
public class SplunkController {
private Logger log = LogManager.getLogger(SplunkController.class);

@GetMapping("/spluckTest")
public void splunkLogg() {

log.info("This is a test event in splunk from log4j2 " + new Date());

log.error("This is a test error in splunk from log4j2 " + new Date());

}

}





log4j2-spring.xml:
-------------
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
   <Appenders>
       <Console name="console" target="SYSTEM_OUT">
           <PatternLayout
                   pattern="%style{%d{ISO8601}} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{10}}{bright,yellow}: %msg%n%throwable" />
       </Console>
       <SplunkHttp
           name="splunkhttp"
           url="########"
           token="######"
           host="####"
           index="########"
           type="raw"
           source="http-log-event"
           sourcetype="_json"
           messageFormat="text"
           disableCertificateValidation="true"
           >
           <PatternLayout pattern="%m" />
       </SplunkHttp>

   </Appenders>

   <Loggers>
       <!-- LOG everything at INFO level -->
       <Root level="info">
           <AppenderRef ref="console" />
           <AppenderRef ref="splunkhttp" />
       </Root>
   </Loggers>
</Configuration>



POM.XML
---------


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>SplunkDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SplunkDemo</name>
<description>Demo project for Spring Boot</description>
<properties>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
       <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
       <java.version>14</java.version>
   </properties>
    <repositories>
       <repository>
           <id>splunk-artifactory</id>
           <name>Splunk Releases</name>
           <url>https://splunk.artifactoryonline.com/artifactory/ext-releases-local</url>;
       </repository>
   </repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter</artifactId>
                <exclusions>
               <exclusion>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-starter-logging</artifactId>
               </exclusion>
           </exclusions>
       </dependency>
        <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-log4j2</artifactId>
           </dependency>
<!-- <dependency> -->
<!--    <groupId>com.splunk.logging</groupId> -->
<!--    <artifactId>splunk-library-javalogging</artifactId> -->
<!--    <version>1.5.1</version> -->
<!-- </dependency> -->
   
<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-core</artifactId>
 <version>2.12.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what problem are you having with this code?
 
sadhu paikaray
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able send any message to Splunk.
 
Stephan van Hulst
Saloon Keeper
Posts: 13280
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you already used a network analyzer to check that you're actually sending messages to Splunk when you log? There's an important difference between your application not sending messages, and Splunk not accepting them.
 
reply
    Bookmark Topic Watch Topic
  • New Topic