Connect with REST/HTTP/HTTPS APIs
Automation Gateway allows central automation code to reach the HTTP/S API services running on devices on remote networks.
For more details see:
https://ftp.opengear.com/download/documentation/api/lighthouse/og-rest-api-specification-v3-7.html
This is accomplished by modifying the request to add the X-Ip-Access-Auth HTTP header to your API request, and substituting the device's remote IP with Lighthouse's central IP. Requests containing the header are reverse proxied via Lighthouse then via an Operations Manager node that is local to the remote device.
The example Python (3.5+) code below illustrates this. Note that this code is primarily for illustrative purposes with no error handling or modularity, for clarity & brevity.
The device being accessed in this example is an HP ILO's Redfish REST API service.
#!/usr/bin/env python3
# Example code showing how to reach a remote device REST API via Opengear
# Lighthouse Automation Gateway -> Operations Manager node -> device
#
# This code is primarily for illustrative purposes with no error handling
# or modularity, for clarity & brevity
import requests
import json
import base64
# Authenticate to Lighthouse
lighthouse_address = '192.168.67.20'
lighthouse_account = 'root'
lighthouse_password = 'default'
data = { 'username': lighthouse_account, 'password': lighthouse_password }
r = requests.post('https://%s/api/v3.7/sessions/' %
lighthouse_address, data=json.dumps(data), verify=False)
lh_token = json.loads(r.text)['session']
print('Authenticated to Lighthouse, token %s' % lh_token)
lh_headers = { 'Authorization': 'Token ' + lh_token }
# Find the node that is local to the remote device's API service
device_address = '10.0.0.71' # Equivalent to the UI fields under CONFIGURE >
device_service = 'https' # AUTOMATION GATEWAY > Devices > Filter By
r = requests.get('https://%s/api/v3.7/nom/ag/devices?ip=%s&service=%s' %
(lighthouse_address, device_address, device_service),
headers=lh_headers, verify=False)
j = json.loads(r.text)
print(json.dumps(j, indent=4))
for _device in j['devices']:
for _host in _device['hosts']:
for _service in _host['services']:
if _service['nmap']['name'] != device_service:
continue
for _avail in _service['availability']:
node_id = _avail['id']
print('Service available via %s' % node_id)
break
# Generate Automation Gateway token
data = { 'session': lh_token, 'request_type': 'new',
'url': 'https://%s' % device_address, 'node': node_id }
r = requests.post('https://%s/api/v3.7/nom/ag/auth_tokens' %
lighthouse_address, data=json.dumps(data), headers=lh_headers, verify=False)
j = json.loads(r.text)
ag_token = j['token']
print('Automation Gateway token is %s' % ag_token)
ag_headers = { 'X-Ip-Access-Auth': ag_token }
# Now we can query the device API using the Lighthouse address, by including
# the access token in the request headers
# The remaining code is specific to the device being accessed. this example
# hits a Redfish-compliant REST API
device_username = 'baz'
device_password = 'foobarfoobar'
device_auth = base64.b64encode(('%s:%s' %
(device_username, device_password)).encode('utf-8')).decode('utf-8')
device_headers = { 'Authorization': 'Basic %s' %
device_auth, 'Content-Type': 'application/json' }
# Add the access token to whatever headers you'd usually use to talk to the
# device's native API -- this header will be stripped by Automation Gateway
_headers = { **ag_headers, **device_headers }
r = requests.get('https://%s/redfish/v1/systems/1/' %
lighthouse_address, headers=_headers, verify=False)
j = json.loads(r.text)
print(json.dumps(j, indent=4))