Splunk Dev

Having trouble uploading log files with python-sdk - no errors, but don't see logs on indexes?

haktor5
Explorer

I am working on a python script to upload logs to an index on the local Splunk server. I use splunk-sdk for python for this.

Connection and some splunk-sdk example runs fine but I am having trouble when uploading logs.

When i run the upload.py script with the file to be uploaded command runs with no error but I don't see the logs on any index. So far I tried:

1. using the example script on github python-sdk page
2. implementing upload() method with indexes class described here: https://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.5/client.html#splunklib.client.Index.uploa...
3. Implementing oneshot() method with inputs class

None of the above worked.

What am i doing wrong? Is there any way to have some feedback on why the file wasn't uploaded?

http://dev.splunk.com/view/python-sdk/SP-CAAAEE6#createinput
http://dev.splunk.com/view/python-sdk/SP-CAAAEE6
http://dev.splunk.com/view/python-sdk/SP-CAAAEFK#upload

Labels (2)
0 Karma

vkannampuzha
Explorer

Not sure why it doesn't work. I use python to upload data from a file to an index on my local Splunk. This is what I did

1. I installed splunk-sdk for python. Installed simply using the pip install command so:

pip install splunk-sdk

2. On python, you need to first connect to your local Splunk server

"""Connect to splunk local"""

import splunklib.client as client
import splunklib.results as results
from splunklib.binding import AuthenticationError

HOST=localhost
PORT = '8089'
USERNAME = 'username'
PASSWORD = 'password'

try:
    service = client.connect(host=HOST, port=PORT, username=USERNAME, password=PASSWORD)
except exception as e:
    print(str(e))

3. Upload your file to your index

myindex = service.indexes[ENTER INDEX NAME]  # Retrieve the index for the data

try:
    myindex.upload(ENTER THE ABSOLUTE PATH TO YOUR FILE)  # Upload file 
    to the index specified
except Exception as e:
    print(str(e))
0 Karma

starcher
Influencer

You would be much better off sending the logs in via HTTP Event Collector (HEC) if you are already operating in python. Read the file, blow in the events.

http://dev.splunk.com/view/event-collector/SP-CAAAE6M

0 Karma

haktor5
Explorer

Thank you for the answer but my events are in a file and that's why I'm trying to use a method for file upload.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...