Splunk Search

Why does index creation via Java SDK returns null value?

Silviya_brayano
New Member

Hi colleagues,
I am trying to create index using the Java SDK for Splunk and to reset the "FrozenTimePeriodInSecs" property afterwards.
The code snippet follows:

ServiceArgs loginArgs = new ServiceArgs();
        loginArgs.setUsername("admin");
        loginArgs.setPassword("admin");
        loginArgs.setHost("host");
        loginArgs.setPort(8089);

String indexName = "testIndex_" + System.currentTimeMillis(); 

HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);        
Service splunkService = Service.connect(login);
IndexCollection indexCollection = splunkService.getIndexes();
Index createdIndex = indexCollection.create(indexName);
createdIndex.setFrozenTimePeriodInSecs(retentionPeriod);
createdIndex.update();

I run into java.lang.NullPointerException because apparently the the IndexCollection.create(String indexName); returns a null value.
Any idea what am I doing wrong?

0 Karma

Silviya_brayano
New Member

Hi all,

I have found the root cause.
The problem is with the capital "I" in the testIndex_<timestamp>.
It turns out that despite my attempt to create an index with name testIndex_<timestamp> (capital "I") on the backend an index with name testindex_<timestamp> (lower case "i") is created.

The method IndexCollection.create(String indexName) sends internal GET request attempting to obtain the Index object, having the original name testIndex_<timestamp> with (capital "I") and since on the back end there is no such thing that method returns null value.

In my opinion that is a bug.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Index names are always lower case. Per the Managing Indexers and Clusters of Indexers docs: "User-defined index names must consist of only numbers, lowercase letters, underscores, and hyphens."

Splunk probably should block attempts to create an index with an invalid name or warn that it changed the name, but I see no bug here.

---
If this reply helps you, Karma would be appreciated.
0 Karma

Silviya_brayano
New Member

On line 10 I actually pass the loginArgs and not login.

0 Karma

tgandham1
New Member

EntityCollection<Index> indexes = splunkService.getIndexes();

splunkService.getIndexes();

the above line giving error ,pasted in below.

tgandham1_1-1648489784740.png

 

due this Create index returning null pointer error. 

 

 

 

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...