Splunk Search

Java SDK send data directly to Splunk (web)

tomspring5000
New Member

Hi,
I'm attempting to implement a direct connection to Splunk in my Java application so I can send data straight to Splunk without having to go through a forwarder. I've written some psuedocode, I just wanted to check if its correct:

import com.splunk.*;

//Connect to Splunk Service
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("admin");
loginArgs.setPassword("password");
loginArgs.setHost("localhost");
loginArgs.setPort(8089);
Service service = Service.connect(loginArgs);

Index myIndex = service.getIndexes().get("index_name");
Args eventArgs = new Args();
eventArgs.put("CaseName", caseName);
eventArgs.put("Result", result);
eventArgs.put("Runtime", runtime);
eventArgs.put("Environment", env);
eventArgs.put("postDate", date);

myIndex.submit(eventArgs);

Thanks,
Tom

0 Karma
Get Updates on the Splunk Community!

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...