Connected Clients Statistics
PyCentral Workflow
This is a Python script that allows users to gather connected client statistics based on a site name and when a connected client was last connected. Users can gather connected client statistics from multiple sites over multiple last connected time filters. One or more output csv files are created to display: Client Username, Client IP Address, Client MAC Address, Association Time, and Associated AP Name. The code for this script can be found here on Github.
Workflow Overview
Description
This script that uses the Pycentral library to achieve the following steps on a Central account:
- Get connected clients for a site and collect relevant statistics
- Create a csv file of data from within last connected time window based on the site
Prerequisites
- Connected Clients need to be online and connected
Installation Steps
In order to run the script, please complete the steps below:
-
Clone this repository and cd into the workflow directory:
git clone https://github.com/aruba/central-python-workflows cd central-python-workflows/connected_clients
-
Install virtual environment (refer https://docs.python.org/3/library/venv.html). Make sure python version 3 is installed in system.
python -m venv env
-
Activate the virtual environment In Mac/Linux:
source env/bin/activate
In Windows:
env/Scripts/activate.bat
-
Install the packages required for the script:
python -m pip install -r requirements.txt
-
Provide the Central API Gateway Base URL & Access Token in the central_token.json:
{ "central_info": { "base_url": "<api-gateway-domain-url>", "token": { "access_token": "<api-gateway-access-token>" } }, "ssl_verify": true }
Note
-
Provide a one or more site names into the string list array in the site_names.json:
{ "site_names": [ "<site name>", "<site name>" ] }
-
The default timeframes preset within this script are 3 hours, 24 hours, 1 week, and 1 month. The "timeframe" list variable within the connected_clients.py file is responsible for using all of those preset variables. If you would only like the see connected clients that connected last within just one week, you can make one_week_ago the only item within the "timeframe" list variable. Otherwise if no changes are made, the connected_clients.py script will output the 4 default timeframes.
# timeframe = [one_day_ago, one_week_ago] # timeframe = [one_week_ago] # timeframe = [one_month_ago] timeframe = [three_hours_ago, one_day_ago, one_week_ago, one_month_ago]
-
Once central_token.json & site_names.json are updated with the relevant information, you can execute the script with the following command:
python connected_clients.py
Note
- This script takes the following optional parameters to override default filenames for the script
- central_auth - Path of Central Token File
- You can run the following command to use the optional parameters:
python connected_clients.py --central_auth <central_token_file>
- This script takes the following optional parameters to override default filenames for the script
-
If the script runs successfully, your terminal output should look like this:
-
Depending on the site name and time frame inputs, one or more output csv files will be created with the output of the script results
- Columns will consist of: 'Client Username', 'Client IP Address', 'Client MAC Address', 'Association Time', 'AP Name', 'Site Name'
Generated:,2024-08-01 16:45:00.730098 Report By:,Site Site Name:,Roseville Admin Building Reporting Period:,"30 days, 0:00:00" "" Client Username,Client IP Address,Client MAC Address,Association Time,AP Name,Site Name --,192.168.0.198,dc:a6:32:a2:aa:7a,2024-08-01 15:28:30,Automation-Central-01,Roseville Admin Building
Central APIs used for this workflow
Updated 4 months ago