I am not able to connect to splunk web console using python sdk getting timedout error , I am suspecting port is not allowing, Could you please help
my code
--------------------------
import sys
import getpass
sys.path.append('splunk-sdk-python-1.6.16')
import splunklib.client as client
def setServer(hostname, splunkuser, splunkpassword):
HOST = hostname
PORT = 8089
USERNAME = splunkuser
PASSWORD = splunkpassword
service = client.connect(host=HOST,port=PORT,username=USERNAME,password=PASSWORD)
#for app in service.apps:
# print (app.name)
# Get the collection of users
#users = service.users
# print(users)
if __name__ == "__main__":
hostname = input("Enter Splunk Hostname/IP: ")
splunkUser = input("Enter Splunk Admin Username: ")
splunkPassword = getpass.getpass("Enter Splunk Admin Password: ")
setServer(hostname, splunkUser, splunkPassword)
-----------------------------------------------------------------
output
-----------------------
#python3 test66.py
Enter Splunk Hostname/IP: prd-p-pivip.splunkcloud.com
Enter Splunk Admin Username: sc_admin
Enter Splunk Admin Password:
Traceback (most recent call last):
File "/Users/sasikanth.bontha/test66.py", line 23, in <module>
setServer(hostname, splunkUser, splunkPassword)
File "/Users/sasikanth.bontha/test66.py", line 11, in setServer
service = client.connect(host=HOST,port=PORT,username=USERNAME,password=PASSWORD)
File "/usr/local/lib/python3.9/site-packages/splunklib/client.py", line 331, in connect
s.login()
File "/usr/local/lib/python3.9/site-packages/splunklib/binding.py", line 883, in login
response = self.http.post(
File "/usr/local/lib/python3.9/site-packages/splunklib/binding.py", line 1242, in post
return self.request(url, message)
File "/usr/local/lib/python3.9/site-packages/splunklib/binding.py", line 1259, in request
response = self.handler(url, message, **kwargs)
File "/usr/local/lib/python3.9/site-packages/splunklib/binding.py", line 1399, in request
connection.request(method, path, body, head)
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1257, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1303, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1252, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1012, in _send_output
self.send(msg)
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 952, in send
self.connect()
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1419, in connect
super().connect()
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 923, in connect
self.sock = self._create_connection(
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 843, in create_connection
raise err
File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 831, in create_connection
sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out
It's looks TimeoutError. Can you please check whether the Splunk Instance is reachable or not. Just ping OR use curl for same.
Not able to ping also
# ping prd-p-pivip.splunkcloud.com
PING ec2-54-158-75-102.compute-1.amazonaws.com (54.158.75.102): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
Request timeout for icmp_seq 7
Request timeout for icmp_seq 8
Request timeout for icmp_seq 9
Request timeout for icmp_seq 10
Means your VM is not connected to internet, You can verify it by doing ping to https://google.com also. If it is just contact your admin to provide Internet connectivity 🙂
i am able to ping google.com 🙂
#ping google.com
PING google.com (142.250.76.174): 56 data bytes
64 bytes from 142.250.76.174: icmp_seq=0 ttl=118 time=27.841 ms
64 bytes from 142.250.76.174: icmp_seq=1 ttl=118 time=26.473 ms
64 bytes from 142.250.76.174: icmp_seq=2 ttl=118 time=29.327 ms
64 bytes from 142.250.76.174: icmp_seq=3 ttl=118 time=29.047 ms
64 bytes from 142.250.76.174: icmp_seq=4 ttl=118 time=30.789 ms
^C
--- google.com ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 26.473/28.695/30.789/1.454 ms
I just notice one thing. Can please check your access of Splunk cloud instance management port for API? May be 8089 port is not open.
Just check below link for more info.
KV
Hi @kamlesh_vaghela ,
Could you please check port 8089 from your end and open
prd-p-pivip.splunkcloud.com |
Note :I am using free trail splunk cloud
No I'm not able to access it. The reason being, when you ask Splunk Support to enable 8089 port, they will ask you to allowed IP list from 8089 port being called. 🙂
yes @skr
To access your Splunk Cloud deployment using the Splunk REST API and SDKs, submit a case requesting access using the Splunk Support Portal. Splunk Support opens port 8089 for REST access. You can specify a range of IP addresses to control who can access the REST API.
Thank you so much for your help and support @kamlesh_vaghela
Unfortunately no one having any access to this 😒.. i am learning alone.
Well you are learning then I suggest to install Splunk Enterprise in your local machine and get same experience of REST :). This is what I did and doing 🙂 . Click on Free Splunk on right top and enjoy learning.
Happy Splunking
🙂