Cloning Scheduled Tests with Modified Source, Destination, and Schedule Using the NetBeez API

Looking to create a new scheduled test based on an existing one, but with some adjustments to the source, destination, or schedule? The NetBeez API makes it easy to achieve this!

In this guide, we’ll walk you through the steps involved in retrieving an existing test definition, modifying the necessary attributes, and creating a new test using the API.

Prerequisites:

  • Access to the NetBeez BeezKeeper API.
  • A tool for making API requests (e.g., Postman, curl, or a programming language like Python).
  • Understanding of basic API concepts and JSON data structures.

Steps:

  1. Retrieve the Existing Test Definition:

    • Send a GET request to the following API endpoint, replacing {{HOSTNAME}} with your NetBeez hostname and :id with the ID of the existing test:

      https://{{HOSTNAME}}/scheduled_nb_test_templates/:id
      
    • The response will contain the test definition in JSON format.

      {
          "data": {
              "id": "140",
              "type": "scheduled_nb_test_template",
              "attributes": {
                  "label": "TCP-V3-Iperf",
                  "target": "0.0.0.0",
                  "target_id_agent": 6, // Original target
                  "test_type_id": 5,
                  "cron_schedule": "0 * * * *",  // Original schedule
                  "configuration: {
                      "iperf_port": 5001,
                      "iperf_time": 10,
                      "iperf_type": 1,
                      "iperf_version": 3,
                      // ... other attributes
                  }
              },
              "relationships": {
                  "agents": {
                      "data": [
                          {
                              "id": "1",   // Original source agent
                              "type": "agent"
                          }
                       ]
                  }
              }
          }
      }
      

      Pay close attention to the following attributes:

      • target_is_agent: If this is a non-zero value, it indicates an agent-to-agent test. The target attribute will be “0.0.0.0” in this case.
      • agent_ids: An array containing the IDs of agents running the test.
      • cron_schedule: The cron expression defining the test schedule.
  2. Modify the Attributes:

    • To change the source/destination agent, modify the target_is_agent attribute with the ID of the new target agent.
    • To adjust the schedule, change the cron_schedule attribute with the desired cron expression.
    • You can also modify other attributes as needed, such as the test type or configuration options. Generally you would want to keep the same configuration attributes.
  3. Create the New Test:

    • Send a POST request to the following endpoint, including the modified test definition in the request body:

      https://{{HOSTNAME}}/scheduled_nb_test_templates
      
    • Ensure you include a valid API token in the request header for authorization.

Example:

Here’s an example of the request body for creating a new test based on the provided sample data, with a modified target agent and schedule:

{
    "scheduled_nb_test_template": {
        "test_type_id": 5,
        "agent_ids": [
            6  // New source agent ID
        ],
        "target_is_agent": 134,  // New target agent ID
        "cron_schedule": "0 9,15,21 * * 1,2,3,4,5",  // Modified schedule
        // ... other test configuration options
    }
}

Remember:

  • The agent_ids array should only contain one agent ID when using target_is_agent.
  • The target attribute can be omitted when using target_is_agent.
  • Refer to the NetBeez API documentation at https://api.netbeez.net.

By following these steps and leveraging the NetBeez API, you can efficiently create new scheduled tests based on existing ones, ensuring flexibility and customization in your network monitoring setup.