-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavocent-oob.py
More file actions
77 lines (64 loc) · 2.58 KB
/
avocent-oob.py
File metadata and controls
77 lines (64 loc) · 2.58 KB
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
76
77
import requests, json
import urllib3 #Can be removed when valid certificate is added
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) #Can be removed when valid certificate is added
# Section: Authenticate to the API
# Set the base URL for the API call
base = 'https://FQDN:48048/api/v1'
# Define the final portion of the URL for authenticating and getting an auth token
sessionlogin = '/sessions/login'
# Build the final URL to send
final_url = base + sessionlogin
# Set the POST parameters
headers = {'Content-Type': 'application/json'}
credentials = {'username': 'root', 'password': 'linux'}
# Send the POST and the parameters
response = requests.post (final_url, data=json.dumps(credentials), headers=headers, verify=False)
# verify=False can be removed when valid certificate is added
response.encoding = 'json'
#print(response.text) #TEXT/HTML
#print(response.status_code)
### Insert error checking
#if response.status_code != 200:
# print('Call to API has failed. Response code is: ' + response.status_code)
# quit()
# Load the results as JSON
json_data = json.loads(response.text)
# Pull out the token code
token = json_data['token']
#print(token)
# Section: Create Header for JWT
header_token = {'Authorization': 'Bearer ' + token}
#print(header_token)
networksettings = '/network/settings'
final_url = base + networksettings
response = requests.get(final_url, headers=header_token, verify=False)
json_data = json.loads(response.text)
#print(json_data)
hostname = json_data['hostname']
# print(hostname)
# Section: Get the System IP
intf = '/network/devices/eth0'
final_url = base + intf
response = requests.get(final_url, headers=header_token, verify=False)
#print(response.text)
json_data = json.loads(response.text)
ip_address = (json_data['ipv4Static']['ipv4Address'])
# Section: Build the Help Section
resources = '/resources'
final_url = base + resources
response = requests.get(final_url, headers=header_token, verify=False)
# print(response.text)
# Section: Build the serialPorts list
serialinfo = '/serialPorts'
final_url = base + serialinfo
response = requests.get(final_url, headers=header_token, verify=False)
#print(response.text)
json_data = json.loads(response.text)
for result in json_data['serialPorts']:
serialport = result['port']
ssh_port = result['cas']['sshAliasPort']
serialstatus = result['status']
pinout = result['physical']['pinout']
speed = result['physical']['speed']
deviceName = result['cas']['name']
print(hostname,ip_address,serialport,ssh_port,deviceName,serialstatus,pinout,speed)