-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservers_get_server_info.py
75 lines (63 loc) · 2.69 KB
/
servers_get_server_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
import requests
import sys
import json
def get_server_info(cert, key, l_key, id):
session = requests.Session()
session.cert = (cert, key)
# API request
api_url = 'https://web.skyvr.videoexpertsgroup.com:9000/api/v6/servers/' + id + '/'
headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'LKey %s' % str(l_key),
}
try:
response = session.get(url=api_url, headers=headers, verify=False)
except requests.exceptions.RequestException as e:
print (e)
sys.exit(1)
session.close()
return response.status_code, response.text
# Parsing program call arguments
parser = argparse.ArgumentParser()
parser.add_argument('-cert', '--path_to_cert', help = 'Path to .crt file', required=True)
parser.add_argument('-key', '--path_to_key', help = 'Path to .key file', required=True)
parser.add_argument('-vxg_cloud_key', '--vxg_cloud_key', help = 'Cloud relay key applied in server settings', required=True)
parser.add_argument('-id', '--server_id', help = 'Server ID number', required=True)
# Block responsible for checking the entered parameters. In case of an error, the status and description of use are returned
try:
param = parser.parse_args()
except IOError as msg:
parser.error(str(msg))
# Function call to send an HTTP request
code, data = get_server_info(param.path_to_cert, param.path_to_key, param.vxg_cloud_key, param.server_id)
# Convertion to json
try:
data_json = json.loads(data)
except Exception:
pass
# Output of the status.
print ('Request completed. HTTP status code: ' + str(code)+'\n')
# Output of the HTTP request (acess token, id)
try:
if data_json['online']:
print('API Endpoint: ' + data_json['api_endpoint']+'\n')
print('Endpoint: ' + data_json['endpoint']+'\n')
print('Expired: ' + data_json['expires']+'\n')
print('Server ID: ' + str(data_json['id'])+'\n')
print('l_key: ' + data_json['l_key']+'\n')
print('Server name: ' + data_json['name']+'\n')
print('Online: ' + str(data_json['online'])+'\n')
print('Token: ' + data_json['token']+'\n')
print('Server UUID: ' + data_json['uuid']+'\n')
print('Server version: ' + data_json['version']+'\n')
else:
print('Server ID: ' + str(data_json['id'])+'\n')
print('l_key: ' + data_json['l_key']+'\n')
print('Server name: ' + data_json['name']+'\n')
print('Online: ' + str(data_json['online'])+'\n')
print('Server UUID: ' + data_json['uuid']+'\n')
print('Server version: ' + data_json['version']+'\n')
except Exception:
print (data)