Getting Data In

Why am I unable to post logs using Java SDK?

srinitest123
Engager

I have attached below my code snippet. I am using a free developer access machine. https://prd-p-lgqtg5v8fkdb.cloud.splunk.com

I am unable to login using my credentials.

public class Splunk {
    public static void main(String args[]) throws IOException {
        HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);

        Map<String, Object> connectionArgs = new HashMap<String, Object>();
        connectionArgs.put("host", "input-prd-p-lgqtg5v8fkdb.cloud.splunk.com");
        connectionArgs.put("username", "test123");
        connectionArgs.put("password", "test123");
        connectionArgs.put("port", 8089);
        connectionArgs.put("scheme", "https");

        Service splunkService = Service.connect(connectionArgs); 
    }
}

Tried using a lot of ways. The curl works fine.

0 Karma

aaraneta_splunk
Splunk Employee
Splunk Employee

Hi @srinitest123 - I saw that you up voted msivill's answer. If it helped answer your question, please don't forget to resolve this post by clicking "Accept" below the answer. Thanks!

0 Karma

msivill_splunk
Splunk Employee
Splunk Employee

I've successfully used the HTTP event collector ( http://dev.splunk.com/view/event-collector/SP-CAAAE6M ) mechanism to send data to the cloud. It works using a token rather than username/password (also different port). As the HTTP event collector (HEC) is based on REST you can create a java client (with your preferred HTTP java library) that passes data to Splunk Cloud.

Example curl -

curl -X POST -d @**FILENAME** -H "Content-Type: application/json" -k https://input-**SERVER**.cloud.splunk.com:8088/services/collector/event -H "Authorization: Splunk **HEC_TOKEN**"
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...