A small collection of example Python scripts to easily extract data from Cisco DNA Spaces. Initially the scripts will concentrate on location tracking to help with finding where people have travelled.
- Have a look at the Cisco DNA Spaces API over at DevNet. To get familar with the APIs available.
- Clone this repository into a directory to get the helper scripts:
git clone https://github.com/leigh-jewell/dnaspaces-helper.git
- Install Python 3.7+ with the appropriate distribution for your OS.
- Install Pipenv using pip which should have been installed with Python3:
pip install pipenv
Or if you are using Homebrew simply run:
brew install pipenv
- For your script to authenticate with Cisco DNA Spaces you need to create a token in your account. Instructions are shown on DevNet. Otherwise, simply follow these steps:
- Browse to Detect and Locate
- Click on the menu bar and select "Notifications"
- Click on "API Keys"
- Add token
- Make a copy of the token string
Create the virtual environment using Pipflie.lock. This will ensure the dependencies are installed
pipenv install --ignore-pipfile
The script will use the environment variable 'TOKEN' to authenticate to DNA Spaces. You will need to set this according to your OS.
OSX:
export TOKEN="abcdefghijkl"
Windows10:
set TOKEN "abcdefghijkl"
Use the Pipenv shell to ensure you access the virtual environment created:
pipenv shell
You can now run the scripts:
python dnaspaces_get_history.py
usage: dnaspaces_get_history.py [-h] [-st START_TIME] [-et END_TIME]
[-tz TIMEZONE] [-f FILENAME] [-nc]
optional arguments:
-h, --help show this help message and exit
-st START_TIME, --start_time START_TIME
Start time in ISO format [YYY-MM-DDThh:mm:ss.s+TZD] If
not provided will use -1 day as start time. End time
will be start time +1 day if not provided.
-et END_TIME, --end_time END_TIME
End time ISO format [YYY-MM-DDThh:mm:ss.s+TZD]
-tz TIMEZONE, --timezone TIMEZONE
Time zone database name e.g. Australia/Sydney
-f FILENAME, --filename FILENAME
Filename to write the client history data into.
-nc, --no_convert Stop the conversion of timestamp to localised date
time.
-ko, --keep_original Keep the original file with timestamps before conversion.
Get the past 1 day of data in the local timezone timestamps to local date and time:
python dnaspaces_get_history.py
Get a specific date range in the local timezone. As DNA Spaces can only do 1 day of data at a time. This call will break time ranges into separate 1 day requests. The date time is in ISO format.
python dnaspaces_get_history.py -st=2020-05-25 -et=2020-05-28
Get a specific date range in the local timezone and write to file output.csv
python dnaspaces_get_history.py -st=2020-05-25 -et=2020-05-28 -f="/tmp/output.csv"
Get a specific date range in the local timezone and write to file output.csv but don't convert the timestamps.
python dnaspaces_get_history.py -st=2020-05-25 -et=2020-05-28 -nc
Get a specific date range in the specified time zone.
python dnaspaces_get_history.py -st=2020-05-25 -et=2020-05-28 -tz=Australia/Sydney
- Requests - Requests is an elegant and simple HTTP library for Python, built for human beings.
- Leigh Jewell - Initial work - Github
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
- Thanks to Cisco DNA Spaces for such a great product.