Developing an 'Access Point Tracker' using Omada Open API
Access points (APs) are used everywhere at my workplace, and they are all configured by an application called 'Omada'. It's powerful in what it does, letting us tamper with each AP and make necessary changes to how they work as well as how they allow other devices to connect to them. Although Omada does show us if any APs are down, we don't have a clear view of where they are down. To solve this, I developed a solution that would show every AP, represented by circles, in their respective tags that are assigned to them, represented by a container outlining all the APs and showing the tag name and the number of APs inside those tags.
Firstly, I need to be able to retrieve all the information on the devices enlisted on Omada and then separate them to only get the APs on the network. I chose to use the Python programming language for this task and created two separate Python files; one for creating the HTML code to show the information I will be grabbing, and another for making sure that the token for accessing the Omada API is updated and will not cause errors when I attempt to connect and perform functions with the API.
To be able to access the API I need to have 'API Headers', which will contain the access token and other pieces of information like the content type of what I am trying to retrieve, and will let other parts of the script easily interact with the API without needing to create another header each time I call it. I also store the timestamp of when the access token and 'refresh token' was last made, in UNIX epoch time, so that when the 'UpdateToken' function is next called to make sure that the tokens are up-to-date it can either re-authorise or use the refresh token to refresh the access token again and update the API headers in the script. According to Omada Open API:
'Currently, the access token is valid for 2 hours, and the refresh token is valid for 14 days. If the access token expire, you can use the refresh token interface to obtain a new access token.'
And so, the program has been made sure to use the refresh token when this access token has expired after 2 hours (7200 seconds), and to re-authorise the access token if the refresh token has expired after 14 days (1,209,600 seconds), setting new timestamps for when these refreshes and re-authorisations have occurred.
This script also has a function that retrieves all of the APs in Omada, which stores it in a global variable for other scripts to then use after importing this script.
We have all the information we need now to create the website, so in another script the 'UpdateWebPage' function will firstly make sure that all the tokens and devices are up-to-date by calling the functions in the first script we made, and then it will go through the tag names that are available in Omada and appends them to a new list for later. For the HTML, I simply used 'open()' with the write 'OpenTextMode'. It works well and allows for instantaneous file writing. Then I loop through each tag, from the list earlier, and check for devices that match the tag name. If they matched and had a 'status' of 1, the device is online and can be given the 'online' class. If it had any other kind of status, then something was clearly wrong with the AP and it is given the 'offline' class. These classes will determine whether the circles representing them will be green or red to show if they're online or offline. After this, the tag name containers are then created. Something that I added to show if an entire tag is offline is checked for if the number of APs online in the current tag is greater than 1, which it will just create a normal div for the tag. Otherwise, it will give the 'offline' class as well, which will make the entire container red. Then, the name of the tag is added to the container, and a counter is added at the end to show exactly how many APs exist in the tag and how many are currently online. This is very useful for the IT team since it will let us troubleshoot any network issues much more efficiently.
For loop checking each tag and adding the divs for the tags and APs (devices). |
The header is then created, which will show when the program was last ran as well as number of all the APs; another useful visual for the IT team.
Still screenshot of the completed 'Access Point Tracker' with values inputted. Tag names have been censored for the privacy of the workplace's internal network. An example of a tag with all APs being offline is also shown. |