splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

How to handle submit request result?

Open gabi939 opened this issue 1 year ago • 1 comments

Hey,

I want to use the submit operation given by the sdk as in the following example.

I have tried to find documentation on how to handle different responses from splunk for the submit action but I cant find any, how can I validate if the submit operation was successful or if it failed?


import splunklib.client as client
import json

# Connect to Splunk
service = client.connect(
    host="your_splunk_host",
    port=8089,
    username="your_username",
    password="your_password"
)

# Prepare your JSON data
json_data = {
    "event": {
        "name": "John Doe",
        "age": 30,
        "city": "New York"
    },
    "sourcetype": "my_json_data",
    "index": "main"
}

# Convert JSON to string
event_data = json.dumps(json_data)

# Send data to Splunk using HEC
index = service.indexes["main"]
index.submit(event_data, sourcetype="my_json_data")

print("JSON data uploaded successfully")


gabi939 avatar Jan 15 '25 11:01 gabi939

Dismissing as stale. Please tell us if the issue persists!

Ickerday avatar Sep 09 '25 09:09 Ickerday