How to Download NetBeez Path Analysis Results Using Python Script

Are you looking to retrieve path analysis results from the NetBeez BeezKeeper API for further analysis or reporting? With the provided Python script, you can easily download all the path analysis results and store them in JSON files. In this guide, we’ll walk you through the steps to use the script effectively.

Before you begin, make sure you have the following:

  • Access to the NetBeez BeezKeeper API.
  • Python installed on your system.
  • The required Python libraries, including requests and json.

Step 1: Download All Run Timestamps

The first step is to download all the run timestamps page by page. This will help you identify the runs you want to retrieve detailed results for.

Step 2: Download Detailed Results

Once you have obtained the run timestamps, you can use them to download the detailed results for each run. The script will create JSON files for each result, making it easy to work with the data.

The script will automatically download the detailed results for the first hop of each run. You can customize it to suit your specific needs.

Here is the full script


import requests
import json
import os

def get_path_analysis_results(base_url, token, agent, template, initial_timestamp):
    offset = 1
    while True:
        url = f"{base_url}/nb_tests/path_analysis/results?filter[agents]={agent}&filter[nb_test_templates]={template}&filter[ts][operator]=>&filter[ts][value]={initial_timestamp}&page[limit]=25&page[offset]={offset}"
        headers = {'Authorization': f'Bearer {token}'}
        response = requests.get(url, headers=headers, verify=False)
        if response.status_code != 200:
            print(f"Error: {response.status_code}")

        data = response.json()
        hop1_results = [item for item in data['data'] if item['attributes']['hop_number'] == 1]

        for result in hop1_results:
            timestamp = result['attributes']['ts']
            detail_url = f"{base_url}/nb_tests/path_analysis/results/{timestamp}"
            detail_response = requests.get(detail_url, headers=headers, verify=False)
            if detail_response.status_code == 200:
                detail_data = detail_response.json()
                file_name = f"{agent}-{template}-{timestamp}.json"
                with open(file_name, 'w') as f:
                    json.dump(detail_data, f)

        if not data['meta']['page']['next']:

        offset += 1

if __name__ == "__main__":
    BASE_URL = ""
    BEARER_TOKEN = "4RuwVqzmTXJMeep6J7V762byg30nkK1yKoUGMHEhhdva_PfZEPpD1A"
    AGENT = "280"
    TEMPLATE = "99"
    INITIAL_TIMESTAMP = "1696992764773"


Script Usage Tips:

  • Modify the script to adjust the filtering criteria or data storage method if needed.
  • Ensure that you have proper authorization and access to the NetBeez BeezKeeper API.
  • Always handle sensitive API tokens securely.

With these two steps, you can efficiently download all the path analysis results from the NetBeez BeezKeeper API using the provided script. This data can be invaluable for troubleshooting network issues and gaining insights into network performance. In future posts we’ll provide some methods to analyze the data.

Feel free to adapt and enhance the script to match your specific requirements or integrate it into your existing workflows. If you have any questions or need further assistance, please don’t hesitate to ask. Happy path analysis downloading!