splunk / splunk-sdk-python

Splunk Software Development Kit for Python
http://dev.splunk.com
Apache License 2.0
698 stars 370 forks source link

KVStoreCollection using wrong argument in "update_index" #497

Closed seiimonn closed 1 year ago

seiimonn commented 2 years ago

Describe the bug When updating the index of a collection the following error is given:

splunklib.binding.HTTPError: HTTP 400 Bad Request -- Argument "index.ho1" is not supported by this handler.

To Reproduce Steps to reproduce the behavior:

>>> import splunklib.client as client
>>> c = client.connect()
>>> c.kvstore.create("example_collection")
>>> c.kvstore["example_collection"].update_index("get_fast",{"important_field": 1})

Expected behavior Update of accelerated fields for collection.

Logs or Screenshots

>>> c.kvstore["example_collection"].update_index("get_fast",{"important_field": 1})
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.11) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/backend/src/lib/splunklib/client.py", line 3622, in update_index
    return self.post(**kwargs)
  File "/app/backend/src/lib/splunklib/client.py", line 1047, in post
    return super(Entity, self).post(path_segment, owner=owner, app=app, sharing=sharing, **query)
  File "/app/backend/src/lib/splunklib/client.py", line 852, in post
    return self.service.post(path, owner=owner, app=app, sharing=sharing, **query)
  File "/app/backend/src/lib/splunklib/binding.py", line 289, in wrapper
    return request_fun(self, *args, **kwargs)
  File "/app/backend/src/lib/splunklib/binding.py", line 70, in new_f
    val = f(*args, **kwargs)
  File "/app/backend/src/lib/splunklib/binding.py", line 769, in post
    response = self.http.post(path, all_headers, **query)
  File "/app/backend/src/lib/splunklib/binding.py", line 1262, in post
    return self.request(url, message)
  File "/app/backend/src/lib/splunklib/binding.py", line 1282, in request
    raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 400 Bad Request -- Argument "index.get_fast" is not supported by this handler.

Splunk (please complete the following information):

SDK (please complete the following information):

Additional context I guess that the issue is based on index vs accelerations. An acceleration in a collection is an index on the underlying MongoDB. Patching the line https://github.com/splunk/splunk-sdk-python/blob/master/splunklib/client.py#L3724 to kwargs['accelerated_fields.' + name] = value if isinstance(value, six.string_types) else json.dumps(value) fixes the issue.

ashah-splunk commented 1 year ago

Hi @seiimonn we are looking into the issue and will get back to you soon.

akaila-splunk commented 1 year ago

Hi @seiimonn , support for accelerated_fields is added in SDK and it will be available in the next release.

ashah-splunk commented 1 year ago

@seiimonn request you to pull the latest SDK release v1.7.3 with the added support and let us know in case of any issue. Thanks!