Dashboards & Visualizations

How do I know the login status

junwhuan
New Member

Hello all,

I'm currently using java sdk to login splunk. How do I know the login status? Is there any session expiration time? If the login status is expired, I then can re-login it. Otherwise I don't want to login Splunk each time I do the searches.

Tags (2)
0 Karma

junwhuan
New Member

It doesn't work. The token will be fetched locally. Even I log out.

0 Karma

dfoster_splunk
Splunk Employee
Splunk Employee

Sessions expire after a certain amount of time - 60 minutes by default.

The only way to determine whether the session is still valid is to make a request and see whether it succeeds.

The Service.getToken() method that was mentioned by others will give you the current session token that is being used but it won't tell you whether it is valid or not. The Service object doesn't actually know whether it is still valid until a new request is made. Even after a timeout occurs the existing token isn't changed (or blanked out) until Server.login() is called again.

0 Karma

dfoster_splunk
Splunk Employee
Splunk Employee

If you need to make an explicit check, something like the following should work:

service.getServiceInfo().getServerName(); // throws SplunkException if session invalid

However note that the session may time out by the time you send the next request. Therefore such an explicit check cannot reliably tell you whether a subsequent request will succeed.

A more robust solution is to harden any code that talks to Splunk to handle session timeouts, relogin if necessary, and reperform the request.

0 Karma

junwhuan
New Member

Could you please give me an example of this?

The only way to determine whether the session is still valid is to make a request and see whether it succeeds.

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Nothing much on documentation, but by description of the method, worth a try (gut feeling it might work)

0 Karma

junwhuan
New Member

I didn't try it. But I will try it now. Do they have documentation for the token?

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Could you try using service.getToken method. I believe if session is expired, it should return null (or throw exception). Haven't verified it.

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...