Getting Data In

Inserting new events via the REST API using the Receivers endpoints thru Java SDK

misteryuku
Communicator

I'm doing Java Splunk REST API to insert new events via the REST API.

I used the Java's splunk service api to add headers and put in the path for the
receiver end point

Map<string, object=""> args = new HashMap<string, object="">();

args.put("Authorization", "Basic YWRtaW46cGFzcw==");

args.put("x-splunk-input-mode", "streaming");

String path = "https://localhost:8089/services/receivers/stream?data="+data+"&host="+host+"&index="+index+"&source="+source+"&sourcetype="+sourcetype;
authService.post(path,args);

A HTTP 404 error was thrown when i run the code. The receiver wasn't present. Probably due to the HttpHeaders.

0 Karma

misteryuku
Communicator

Yes!! Absolutely

0 Karma

MarioM
Motivator

Not sure sure if this is useful but if you look at index.java in the Java SDK, at the end it provides a way to upload data to a named index.

wcolgate_splunk
Splunk Employee
Splunk Employee

The Java SDK introduces a Receivers class in the SDK refresh due at beginning of June. It shows how to submit events very easily.

0 Karma

Ayn
Legend

Is it really the authService object you should be sending this request via?

0 Karma

misteryuku
Communicator

I changed and i tried this :
RequestMessage reqMsg = new RequestMessage();
reqMsg.setMethod("POST"); reqMsg.getHeader().put("Authorization" , authService.getToken());
reqMsg.getHeader().put("x-splunk-input-mode", "streaming");
String path = "https://localhost:8089/services/receivers/stream?data="+data+"?host="+host+"&index="+index+"&source=...;
authService.send(path,reqMsg);

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...