Splunk Dev

Not able to connect splunk using java sdk

Nilesh067
Explorer

Hi team,  

i am getting below error while trying to login with splunk using java sdk.

Caused by: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
Suppressed: java.net.SocketException: Broken pipe (Write failed)

Nilesh067_0-1626075241549.png

 

Labels (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Nilesh067 

Can you please try this? It is working for me.

import com.splunk.*;

public class App {
    public static void main(String[] args) throws Exception {
        HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);

        // Create a map of arguments and add login parameters
        ServiceArgs loginArgs = new ServiceArgs();
        loginArgs.setUsername("admin");
        loginArgs.setPassword("admin123");
        loginArgs.setHost("localhost");
        loginArgs.setPort(8089);

        // Create a Service instance and log in with the argument map
        Service service = Service.connect(loginArgs);

        for (User user : service.getUsers().values())
            System.out.println(user.getName());

    }
}

 

Thanks
KV
▄︻̷̿┻̿═━一

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated. 

View solution in original post

krienstra
Engager

You can try and set a different SSL protocol, the default protocol in Java is not suitable for connection with Splunk:

HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);

 

Edit:

Example code - just add the line somewhere that Java will execute it first before Service connection:

HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername(user);
loginArgs.setPassword(password);
loginArgs.setHost(host);
loginArgs.setPort(port); 

 

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Nilesh067 

In your case it seems that the connection has been closed by the server end of the connection. This could be an issue with the request you are sending or an issue at their end.

Can you please share you sample code to reproduce the same issue?

KV

0 Karma

Nilesh067
Explorer

@kamlesh_vaghela 

ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("uname");
loginArgs.setPassword("xx");
loginArgs.setHost("myhost");
loginArgs.setPort(8089);

// Create a Service instance and log in with the argument map
Service service = Service.connect(serviceArgs);
for (User user : service.getUsers().values())
System.out.println(user.getName());
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@Nilesh067 

Can you please try this? It is working for me.

import com.splunk.*;

public class App {
    public static void main(String[] args) throws Exception {
        HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);

        // Create a map of arguments and add login parameters
        ServiceArgs loginArgs = new ServiceArgs();
        loginArgs.setUsername("admin");
        loginArgs.setPassword("admin123");
        loginArgs.setHost("localhost");
        loginArgs.setPort(8089);

        // Create a Service instance and log in with the argument map
        Service service = Service.connect(loginArgs);

        for (User user : service.getUsers().values())
            System.out.println(user.getName());

    }
}

 

Thanks
KV
▄︻̷̿┻̿═━一

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated. 

Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...