kvcollection.data.query_by_id broken for custom _key
Followed splunk-sdk-python/examples/kvstore.py.
query_by_id returns splunklib.binding.HTTPError: HTTP 404 Not Found -- Could not find object.
id = "mah_super_custom_key"
print("Should return item1: %s" % json.dumps(collection.data.query_by_id(id), indent=1))
However, a standard query returns the entry.
id = "mah_super_custom_key"
query = json.dumps({"_key": id})
collection.data.query(query=query)
Thanks for the issue report @SyraD ! We'll investigate
I was not able to reproduce this using the latest version of the SDK, version 1.6.6 and Splunk Enterprise 7.2.1
self.col.insert(json.dumps({'_key': 'mykey', 'dntest': 'dntestvalue'})) Out[11]: {u'_key': u'mykey'} self.col.query_by_id('mykey') Out[12]: {u'_key': u'mykey', u'_user': u'nobody', u'dntest': u'dntestvalue'} self.col.insert(json.dumps({'_key': 'my_key', 'dntest': 'dntestvalue'})) Out[13]: {u'_key': u'my_key'} self.col.query_by_id('my_key') Out[14]: {u'_key': u'my_key', u'_user': u'nobody', u'dntest': u'dntestvalue'} self.col.insert(json.dumps({'_key': 'mah_super_custom_key', 'dntest': 'dntestvalue'})) Out[15]: {u'_key': u'mah_super_custom_key'} self.col.query_by_id('mah_super_custom_key')
@SyraD do you happen to gave the string for the custom _key that encounters the 404? Thanks :)
I'm can't test/look this week, but the key was an IP address.
@SyraD Are you able to run the following curl command to see if the key actually exists?
curl -k -u admin:yourpassword
https://your_splunkserver_ip:8089/servicesNS/nobody/Your_app_name/storage/collections/data/Your_dataset_name
404 usually means that you query the data set with an non-existing key
Also the 404 could happen if use wrong namespace, the correct namespace should be "nobody". Specifically in sdk, need to to the setup like below:
opts.kwargs["owner"] = "nobody"
opts.kwargs["app"] = "search"
service = connect(**opts.kwargs)
collection_name = "newcol"
collection1 = service.kvstore[collection_name]
x =collection1.data.query_by_id("5cabadf6b7912f45dd4d58d2")
Maybe user error... could not replicate:
kv_client.create('test')
test_col = service.kvstore['test']
k = "host:name.10_testytesty%55"
test = {"_key": k, "val":"test"}
test_row = json.dumps(test)
test_col.data.insert(test_row)
print("Should return item1: %s" % json.dumps(test_col.data.query_by_id(k), indent=1))
query = json.dumps({"_key": k})
out = test_col.data.query(query=query)
print("Returns %s" % out)