Splunk Dev

Unble to connect to splunk server via java sdk

chitranjan155
New Member

Hi,

PFB the code i am using to connect to splunk using java sdk.

         HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );
     ServiceArgs serviceArgs = new ServiceArgs();
     serviceArgs.setHost("mycompanysplunkServer.net");  // complete url https://mycompanysplunkServer.net
     serviceArgs.setPort(8089);
     serviceArgs.setUsername("myusername");
     serviceArgs.setPassword("mypassword");

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

     System.out.println(service.getToken().toString());
     for (Application app : service.getApplications().values()) {
         System.out.println(app.getName());
     }

I am able to connect to local splunk using localhost as host. However when i am using mycompanysplunkServer.net to connect to splunk server i am getting connection timeout error.
Below is error stack.

Exception in thread "main" java.lang.RuntimeException: Operation timed out (Connection timed out)
at com.splunk.HttpService.send(HttpService.java:451)
at com.splunk.Service.send(Service.java:1295)
at com.splunk.HttpService.post(HttpService.java:348)
at com.splunk.Service.login(Service.java:1124)
at com.splunk.Service.login(Service.java:1103)
at com.splunk.Service.connect(Service.java:189)
at com.test.slpunkUiDemo.SplunkConnectApp.main(SplunkConnectApp.java:20)
Caused by: java.net.ConnectException: Operation timed out (Connection timed out)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConne...
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1162)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1056)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.jav...
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1340)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1315)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:264)
at com.splunk.HttpService.send(HttpService.java:445)
... 6 more

Labels (1)
0 Karma

fredthefrog
Explorer

Try this instead:
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setHost("mycompanysplunkServer.net"); // complete url https://mycompanysplunkServer.net
serviceArgs.setPort(8089);
serviceArgs.setUsername("myusername");
serviceArgs.setPassword("mypassword");
serviceArgs.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...