Skip to content

Add timeout param #615

@retzero

Description

@retzero

Hello.
Below is example code. It works fine but timed out after 2 minutes in the firewall blocked host machine.
So I'd want to set shorter timeout value, eg, 30 seconds.
How can I set this value in your SDK?

service = client.connect(
    scheme='http',
    host=os.getenv('SPLUNK_HOST'),
    port=int(os.getenv('SPLUNK_PORT')),
    splunkToken=os.getenv('SPLUNK_TOKEN'))

result = []
kwargs_oneshot = {"earliest_time": "-2d@d",
                  "latest_time": "-0d@d",
                  "output_mode": 'json',
                  "count": 0}
searchquery_oneshot = '''search index="my_test_index" earliest=-2d@d
           | table column_1 column_2 column_3'''

oneshotsearch_results = service.jobs.oneshot(searchquery_oneshot, **kwargs_oneshot)

Log snippet;

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 10, in splunk_search
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 510, in jobs
    return Jobs(self)
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 3051, in __init__
    if not service.disable_v2_api:
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 714, in disable_v2_api
    if self.splunk_instance.lower() == 'cloud':
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 705, in splunk_instance
    splunk_info = self.info
  File "/usr/local/lib/python3.10/site-packages/splunklib/client.py", line 479, in info
    response = self.get("/services/server/info")
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 318, in wrapper
    return request_fun(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 76, in new_f
    val = f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 737, in get
    response = self.http.get(path, all_headers, **query)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 1272, in get
    return self.request(url, {'method': "GET", 'headers': headers})
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 1334, in request
    response = self.handler(url, message, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/splunklib/binding.py", line 1488, in request
    connection.request(method, path, body, head)
  File "/usr/local/lib/python3.10/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.10/http/client.py", line 976, in send
    self.connect()
  File "/usr/local/lib/python3.10/http/client.py", line 942, in connect
    self.sock = self._create_connection(
  File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection
    raise err
  File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions