Skip to content

How to handle submit request result?  #598

Open
@gabi939

Description

@gabi939

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions