Here are three cURL command line examples for interacting with a Splunk instance: sending event data, sending metrics data, and querying a Splunk index.

1. Send Event Data to a Splunk Index

You can send raw event data to a Splunk HTTP Event Collector (HEC) using a POST request.

curl -k https://<SPLUNK_SERVER>:8088/services/collector/event \
     -H "Authorization: Splunk <HEC_TOKEN>" \
     -d '{"event": "User logged in", "sourcetype": "manual_event", "index": "<INDEX_NAME>"}'

2. Send Metrics Data to a Splunk Index

To send metrics data (e.g., CPU usage, memory consumption) to a Splunk metrics index, use a similar cURL command but include metrics-specific fields.

curl -k https://<SPLUNK_SERVER>:8088/services/collector \
     -H "Authorization: Splunk <HEC_TOKEN>" \
     -d '{"time": 1609459200, "event": "metric", "fields": {"_value": 70}, "sourcetype": "_json", "index": "<INDEX_NAME>", "metric_name": "cpu_usage"}'

3. Query a Splunk Index

To query a Splunk index using cURL, use the /services/search/jobs endpoint to start a search and then retrieve the results.

Step 1: Create a Search Job

curl -k https://<SPLUNK_SERVER>:8089/services/search/jobs \
     -u <USERNAME>:<PASSWORD> \
     -d search="search index=<INDEX_NAME> sourcetype=<SOURCETYPE> | head 10"

This will return a sid (search ID) that you will use in the next step.

Step 2: Retrieve the Search Results

curl -k https://<SPLUNK_SERVER>:8089/services/search/jobs/<SEARCH_ID>/results \
     -u <USERNAME>:<PASSWORD>

Summary: