Create New Iperf, Network Speed or VoIP Tests Using the API

Introduction

Managing scheduled tests via API offers significant advantages, especially for large-scale deployments with hundreds of agents. It streamlines configuration, ensures consistency, and facilitates automation.

Setting Up API Variables

Before running any test, you need to configure the Bearer token and base URL. Here’s how to set them up in Python.

import requests

BEARER_TOKEN = "API_TOKEN_HERE"
BASE_URL = "https://YOUR_BEEZKEEPER_HOSTNAME"

headers = {
    'Authorization': f'Bearer {BEARER_TOKEN}',
}

Creating an Iperf Test

To create an Iperf test, make a POST request to the /scheduled_nb_test_templates.json endpoint with the appropriate payload.

Python Snippet

iperf_payload_1_to_1 = {
	"scheduled_nb_test_template": {
		"test_type_id": 5,
		"agent_ids": [
			6
		],
		"bandwidth": null,
		"cron_schedule": "0 9,15,21 * * 1,2,3,4,5",
		"iperf_port": 5001,
		"iperf_time": 10,
		"iperf_type": 1,
		"iperf_version": 2,
		"label": "Test API POST",
		"multicast": false,
		"multicast_ip": false,
		"parallel_streams": 1,
		"reverse": false,
		"target_is_agent": 5,
		"tcp_window": 1,
		"ttl": 5,
		"warning_conditions": {}
	}
}

response = requests.post(
    f"{BASE_URL}/scheduled_nb_test_templates.json",
    headers=headers,
    json=iperf_payload_1_to_1
)

Notice that the target_is_agent is set to a non-zero number which indicates the agent id of the destination agent. Make sure that agent is able to receive connections on the iperf_port.

For a M-to-1 test use this payload:

iperf_payload_M_to_1 = {
	"scheduled_nb_test_template": {
		"test_type_id": 5,
		"agent_ids": [
			14,
			7,
			6,
			5,
			4,
			2,
			1
		],
		"bandwidth": null,
		"cron_schedule": "0 * * * *",
		"iperf_port": 5001,
		"iperf_time": 10,
		"iperf_type": 1,
		"iperf_version": 2,
		"label": "M-to-1 Iperf Test API",
		"multicast": false,
		"multicast_ip": false,
		"parallel_streams": 1,
		"reverse": false,
		"target": "myiperf.example.com",
		"tcp_window": 1,
		"ttl": 5,
		"warning_conditions": {}
	}
}

Creating a Network Speed Test

To create a Network Speed test, the process is similar, but with a different payload.

Python Snippet

network_speed_payload = {
{
	"scheduled_nb_test_template": {
		"test_type_id": 7,
			"agent_ids": [
				14,
				7,
				6,
				5,
				4,
				2,
				1
			],
			"cron_schedule": "0 8,14,20 * * 1,2,3,4,5",
			"target": "",
			"label": "Network Speed Test API",
			"secure": true,
			"speedtest_type": 2,
			"server": "",
			"mini_server": "",
			"warning_conditions": {}
		}
	}
}

response = requests.post(
    f"{BASE_URL}/scheduled_nb_test_templates.json",
    headers=headers,
    json=network_speed_payload
)

Creating a VoIP Test

For a VoIP test, again, change the payload to match the test type and its parameters.

Python Snippet

voip_payload = {
	"scheduled_nb_test_template": {
		"test_type_id": 8,
		"agent_ids": [
			5
		],
		"cron_schedule": "0 9,15,21 * * *",
		"target": "",
		"label": "VoIP Test API",
		"codec": "g711",
		"num_of_concurrent_calls": 1,
		"target_is_agent": 6,
		"voip_port": 12001,
		"voip_time": 30,
		"warning_conditions": {}
	}
}

response = requests.post(
    f"{BASE_URL}/scheduled_nb_test_templates.json",
    headers=headers,
    json=voip_payload
)

Summary and Further Reading

Using the API to manage your tests offers efficiency and scalability, especially when configuring tests over multiple agents. For more details, consult the API Documentation.


By understanding and implementing these examples, you can effectively manage your network tests through API calls.