Getting Data In

Requests.Post CSV File contents into Splunk using HEC

vkannampuzha
Explorer

Hi all,

I'm having issues with using the requests library in python to send the contents of a csv file to Splunk. I've managed to do it for json files and can even convert the csv contents to a json format and post it on splunk successfully. I'm wondering if there was a way to do a requests.post and and send the csv file whilst keeping the csv format rather than changing to a json format.

Here is the code I am using to post json content to splunk:

with open('file.csv') as f:
    reader = csv.DictReader(f)
    file_contents = list(reader)

headers = {
            'Authorization': 'Splunk 'token number''  
        }

data = {'sourcetype': '_json', 'event': file_contents}  

try:
    response = requests.post('http://localhost:8088/services/collector',
                             headers=headers, data=json.dumps(data),
                             verify=False)  
except Exception as e:
    print(str(e))

Thanks!

0 Karma
1 Solution

vkannampuzha
Explorer

After a bit of research, it turns out I can't actually send through data that has a csv format. According to the splunk documentation, I can only send through json or raw data.

View solution in original post

0 Karma

vkannampuzha
Explorer

After a bit of research, it turns out I can't actually send through data that has a csv format. According to the splunk documentation, I can only send through json or raw data.

0 Karma
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...