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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...