splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

kvcollection.data.query_by_id broken for custom _key

Open SyraD opened this issue 8 years ago • 6 comments

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)

SyraD avatar Nov 26 '18 04:11 SyraD

Thanks for the issue report @SyraD ! We'll investigate

tdhellmann avatar Nov 30 '18 18:11 tdhellmann

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')

dan1 avatar Mar 22 '19 16:03 dan1

@SyraD do you happen to gave the string for the custom _key that encounters the 404? Thanks :)

dan1 avatar Mar 22 '19 16:03 dan1

I'm can't test/look this week, but the key was an IP address.

SyraD avatar Mar 23 '19 20:03 SyraD

@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")

ljiang1 avatar Apr 09 '19 18:04 ljiang1

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)

SyraD avatar May 07 '19 12:05 SyraD