<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is there a way to set a timeout value to a splunk connection using python SDK ? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427926#M7641</link>
    <description>&lt;P&gt;Hey, thank you very much. For the ones who have the same problem, here's the solution :&lt;/P&gt;

&lt;P&gt;I created a hanlder, then put the handler in parameter of the connect method.&lt;/P&gt;

&lt;P&gt;It would have been easier to have a "timeout" parameter in the connect method, but well.&lt;/P&gt;

&lt;P&gt;connectionHanlder = binding.handler(timeout = self.SPLUNK_TIMEOUT)&lt;BR /&gt;
        try:&lt;BR /&gt;
            self.service = client.connect(&lt;BR /&gt;
                host=self.SPLUNKSERVER,&lt;BR /&gt;
                port=self.SPLUNKPORT,&lt;BR /&gt;
                username=self.SPLUNKUSERNAME,&lt;BR /&gt;
                password=self.SPLUNKPASSWORD,&lt;BR /&gt;
                handler = connectionHanlder&lt;BR /&gt;
            )&lt;BR /&gt;
        except Exception as e:&lt;BR /&gt;
            logging.info("Error connecting to the splunk platform : " + str(e))&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jun 2019 15:21:31 GMT</pubDate>
    <dc:creator>timoti</dc:creator>
    <dc:date>2019-06-18T15:21:31Z</dc:date>
    <item>
      <title>Is there a way to set a timeout value to a Splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427920#M7635</link>
      <description>&lt;P&gt;Hi, I have some problem to set a timeout value to Splunk connection with python SDK.&lt;/P&gt;
&lt;P&gt;I'm using this : &lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;self.service = client.connect(
host=self.SPLUNKSERVER,
port=self.SPLUNKPORT,
username=self.SPLUNKUSERNAME,
password=self.SPLUNKPASSWORD)
except Exception as e:
logging.info("Error connecting to the splunk platform : " + str(e))&lt;/LI-CODE&gt;
&lt;P&gt;But the default timeout value is 75 seconds, which is too long. Can't we set a timeout value in the parameters? Adding "timeout = 1" in the client.connect method's parameters doesn't have any effect.&lt;/P&gt;
&lt;P&gt;Example: My Splunk server is at 192.168.1.10. When I try to connect 192.168.1.10 when the Splunk server is off, it takes 75 seconds to timeout, or if I set the IP to 192.168.1.11 ( a machine where there is no server at all ), it takes also 75 seconds to timeout.&lt;/P&gt;
&lt;P&gt;The problem is that I have a UI where the user can type an IP address, and of course, i won't wait 75 seconds to inform the user that they typed a wrong IP address or that the server is not started.&lt;/P&gt;
&lt;P&gt;I've searched on the Splunk documentation without results. Waiting for your help, thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 23:31:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427920#M7635</guid>
      <dc:creator>timoti</dc:creator>
      <dc:date>2020-06-17T23:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427921#M7636</link>
      <description>&lt;P&gt;Hi @timoti,&lt;/P&gt;

&lt;P&gt;Should be here :&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/DocumentationStatic/PythonSDK/1.0/binding.html"&gt;https://docs.splunk.com/DocumentationStatic/PythonSDK/1.0/binding.html&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunklib.binding.handler(key_file=None, cert_file=None, timeout=None)

-key_file (string) – A path to a PEM (Privacy Enhanced Mail) formatted file containing your private key (optional).
-cert_file (string) – A path to a PEM (Privacy Enhanced Mail) formatted file containing a certificate chain file (optional).
-timeout (integer or “None”) – The request time-out period, in seconds (optional).
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that's what you're looking for.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 12:21:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427921#M7636</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-06-18T12:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427922#M7637</link>
      <description>&lt;P&gt;Thank's for your response, for the others who are searching for the solution, I did this :&lt;/P&gt;

&lt;P&gt;connectionHanlder = binding.handler(timeout = 1)&lt;BR /&gt;
        try:&lt;BR /&gt;
            self.service = client.connect(&lt;BR /&gt;
                host=self.SPLUNKSERVER,&lt;BR /&gt;
                port=self.SPLUNKPORT,&lt;BR /&gt;
                username=self.SPLUNKUSERNAME,&lt;BR /&gt;
                password=self.SPLUNKPASSWORD,&lt;BR /&gt;
                handler = connectionHanlder&lt;BR /&gt;
            )&lt;BR /&gt;
        except Exception as e:&lt;BR /&gt;
            logging.info("Error connecting to the splunk platform : " + str(e))&lt;/P&gt;

&lt;P&gt;Would'nt it have been easier to set a "timeout = 1" parameter in the connect function ?&lt;/P&gt;

&lt;P&gt;Have a nice day.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 12:35:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427922#M7637</guid>
      <dc:creator>timoti</dc:creator>
      <dc:date>2019-06-18T12:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427923#M7638</link>
      <description>&lt;P&gt;Hello @timoti,&lt;/P&gt;

&lt;P&gt;I don't see any way to do it outside the python-sdk, If you are okay to do minor change in your python SDK it can be done.&lt;/P&gt;

&lt;P&gt;Search for below code in &lt;STRONG&gt;splunklib/binding.py&lt;/STRONG&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if timeout is not None:
    connection.sock.settimeout(timeout)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And replace with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;connection.sock.settimeout(10)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here "10" is 10 seconds timeout.&lt;/P&gt;

&lt;P&gt;I recommended you test this first in your test environment. Hope this helps!!!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:06:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427923#M7638</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-18T15:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427924#M7639</link>
      <description>&lt;P&gt;Hi, thank's all,  the solution was, as said below, to code an hanlder like that : &lt;BR /&gt;
connectionHanlder = binding.handler(timeout = self.SPLUNK_TIMEOUT)&lt;/P&gt;

&lt;P&gt;and then adding the hanlder to the connect method.&lt;/P&gt;

&lt;P&gt;I won't change the python SDK because my program is for production and i wont install pythonsdk with pip and then modify it at every installation.&lt;/P&gt;

&lt;P&gt;Thank's for the reply, cdt.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:15:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427924#M7639</guid>
      <dc:creator>timoti</dc:creator>
      <dc:date>2019-06-18T15:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427925#M7640</link>
      <description>&lt;P&gt;Hello, thank's you for your reply, but the solution with the handler worked well, and i wont change my python sdk at every installation ( the code is for production, i will probably forgot to make this change at every deployment )&lt;BR /&gt;
 Cdt.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:19:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427925#M7640</guid>
      <dc:creator>timoti</dc:creator>
      <dc:date>2019-06-18T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427926#M7641</link>
      <description>&lt;P&gt;Hey, thank you very much. For the ones who have the same problem, here's the solution :&lt;/P&gt;

&lt;P&gt;I created a hanlder, then put the handler in parameter of the connect method.&lt;/P&gt;

&lt;P&gt;It would have been easier to have a "timeout" parameter in the connect method, but well.&lt;/P&gt;

&lt;P&gt;connectionHanlder = binding.handler(timeout = self.SPLUNK_TIMEOUT)&lt;BR /&gt;
        try:&lt;BR /&gt;
            self.service = client.connect(&lt;BR /&gt;
                host=self.SPLUNKSERVER,&lt;BR /&gt;
                port=self.SPLUNKPORT,&lt;BR /&gt;
                username=self.SPLUNKUSERNAME,&lt;BR /&gt;
                password=self.SPLUNKPASSWORD,&lt;BR /&gt;
                handler = connectionHanlder&lt;BR /&gt;
            )&lt;BR /&gt;
        except Exception as e:&lt;BR /&gt;
            logging.info("Error connecting to the splunk platform : " + str(e))&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:21:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427926#M7641</guid>
      <dc:creator>timoti</dc:creator>
      <dc:date>2019-06-18T15:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427927#M7642</link>
      <description>&lt;P&gt;nicely done, glad I could help!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 15:27:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427927#M7642</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-06-18T15:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to set a timeout value to a splunk connection using python SDK ?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427928#M7643</link>
      <description>&lt;P&gt;Yeah I understand that, that's why I mentioned in the answer. Thanks!!!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 05:58:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-there-a-way-to-set-a-timeout-value-to-a-Splunk-connection/m-p/427928#M7643</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-19T05:58:44Z</dc:date>
    </item>
  </channel>
</rss>

