Possible illegal argument name to client.py
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"}
@4n6parser the issue you're seeing is expected, Python variables or parameters cannot contain hyphens. Your workaround is the correct approach.