This may or may not be an issue, but wanted to throw it out there in case it was not by design. When trying to upload a local file to splunk, I want to be able to change the host, source, and sourcetype values. In the following code, I use "rename-source" to change the value.
import splunklib.client as client
service = client.connect(host=HOST, port=PORT, username=USERNAME, password=PASSWORD)
myindex = service.indexes["test_index"]
uploadme = "C:\Python37\Splunk\test.csv"
myindex.upload(uploadme, host="NewHostName", sourcetype="NewTypeName", rename-source="fixme");
This gives me the error "SyntaxError: keyword can't be an expression". If I remove the rename-source argument, the other arguments get passed fine. I believe the problem is the hyphen in the argument name. I got around the issue by changing the last line to.
This may or may not be an issue, but wanted to throw it out there in case it was not by design. When trying to upload a local file to splunk, I want to be able to change the host, source, and sourcetype values. In the following code, I use "rename-source" to change the value.
import splunklib.client as client service = client.connect(host=HOST, port=PORT, username=USERNAME, password=PASSWORD) myindex = service.indexes["test_index"] uploadme = "C:\Python37\Splunk\test.csv" myindex.upload(uploadme, host="NewHostName", sourcetype="NewTypeName", rename-source="fixme");
This gives me the error "SyntaxError: keyword can't be an expression". If I remove the rename-source argument, the other arguments get passed fine. I believe the problem is the hyphen in the argument name. I got around the issue by changing the last line to.
myindex.upload(uploadme, **{"host" : "NewHostName", "sourcetype" : "NewTypeName", "rename-source" : "fixme"}