All Apps and Add-ons

How can I connect and send data using the Service and Receiver classes to Splunk (locally)?

tmartindale78
New Member

running splunk enterprise locally

trying the folllowing code in my java app:

    ServiceArgs serviceArgs = new ServiceArgs();
    serviceArgs.setHost("localhost");
    serviceArgs.setPort(8089);
    serviceArgs.setUsername("admin");
    serviceArgs.setPassword("admin");
    serviceArgs.setScheme("http");

    Service service = Service.connect(connArgs);
    Receiver receiver = service.getReceiver();

    Args args1 = new Args();
    args1.put("sourcetype","mytestsourcetype");

   receiver.log("main",args1,"{hello splunk}");

when I run this I get:

   Exception in thread "main" java.lang.RuntimeException: Unexpected end of file from server
at com.splunk.HttpService.send(HttpService.java:427)
at com.splunk.Service.send(Service.java:1293)
at com.splunk.HttpService.post(HttpService.java:308)
at com.splunk.Service.login(Service.java:1122)
at com.splunk.Service.login(Service.java:1101)
at com.splunk.Service.connect(Service.java:187)


I know its most likely a newbie question but what settings do I need to set up in splunk
to make this work - is there an 'out of the box' configuration of host/user/pw/port
that should work, so I can send data to splunk? and how can i see this data in splunk?

do I need to set up an HTTP Event Collector in splunk to make this work,
or is there some other type of data input listener I need to set up?

thanks
Tags (1)
0 Karma

deepashri_123
Motivator

Hey tmartindale78,

You can refer the doc below:
http://docs.splunk.com/DocumentationStatic/JavaSDK/1.2/com/splunk/Service.html

Let me know if this helps!!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...