Getting Data In

Not able to push data to splunk using python SDK

rajanishsinght
New Member

I am using below code to push data to splunk using Python SDk,script is executed successfully but i am not seeing any data in splunk.

import splunklib.client as client
service = client.connect(host='localhost',port=8089,username='username',password='password')
myindex = service.indexes["main"]
mysocket = myindex.attach(sourcetype='rajanish',host='myhost')
file_data = ''
with open("foo.txt", "r") as lines:
for line in lines:
if line.isspace():
line = ' '
file_data += line
file_data += '\r\n'
mysocket.send(file_data)
mysocket.close()

Tags (1)
0 Karma

yaseenbe
New Member

hi rajanish,

did you get this issue fixed. can you help me with the python code. i am also trying to push data to splunk.

I am new to splunk, so kindly help me

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...