Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle submit request result? #598

Open
gabi939 opened this issue Jan 15, 2025 · 0 comments
Open

How to handle submit request result? #598

gabi939 opened this issue Jan 15, 2025 · 0 comments

Comments

@gabi939
Copy link

gabi939 commented Jan 15, 2025

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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant