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
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...