Monitoring SDN connector status using an API
You can monitor SDN connector status using a REST API that Fortinet SDN Connector for Cisco ACI and Nuage Networks provides.
Request:
/api/status
Response:
Format: json
Key |
Type |
Possible values |
Description |
---|---|---|---|
in_sync |
Boolean |
|
Whether endpoints are synchronized with upstream SDN controller. |
rpc_listener |
String |
|
Send and receive notifications to and from FortiOS and FortiManager.
|
sdn_controller |
String |
|
Controller that the SDN connector connects to in order to get endpoint updates.
|
sdn_controller_host |
String |
|
IP address or FQDN of the SDN controller that the SDN connector is connecting to. |
type |
String |
|
Current SDN controller type. |
time |
Integer |
Epoch time in seconds |
Current epoch time stamp. |
usage |
Dictionary |
|
|
usage.cpu |
Float |
|
SDN connector CPU usage. |
usage.mem |
Float |
|
SDN connector memory usage. |
version |
String |
|
Version number in major.minor.patch format. |
The following is an example of the output:
{ "in_sync": true, "rpc_listener": "connected", "sdn_controller": "connected", "sdn_controller_host": "x.x.x.x", "time": 1584398898, "type": "aci", "usage": { "cpu": 7.6, "mem": 69.7 }, "version": "1.1.3" }
The following shows sample code for monitoring the SDN connector using this API:
#!/usr/bin/env python import re import requests class SdnConnectorClient(object): def __init__(self, host, password, user="admin@sdn-connector.local"): self.host = host self.base_url = "https://" + host self.user = user self.password = password self.csrf = None self.cookies = None def login(self): login_page = requests.get(self.base_url + '/login', verify=False) session = login_page.cookies regex = re.compile(".+csrf_token=\\'(\S+)\\'.+") self.csrf = regex.search(login_page.text).group(1) form = {"email": self.user, "password": self.password, "csrf_token": self.csrf, "submit": "Login", "next": "/"} res = requests.post(self.base_url + '/login', data=form, verify=False, cookies=session, headers={'referer': self.base_url}) self.cookies = res.cookies def get_status(self): res = self.get('/api/status') return res[1] def get(self, path): res = requests.get(self.base_url + path, cookies=self.cookies, verify=False) return res.status_code, res.text def post(self, path, data): res = requests.post(self.base_url + path, cookies=self.cookies, data=data, verify=False) return res.status_code, res.text if __name__ == "__main__": sdn_client = SdnConnectorClient('localhost', 'xxxxxx') sdn_client.login() print sdn_client.get_status()