Skip to main content

Custom Command Tests

Run custom Bash and Python scripts on NetBeez Network Agents to collect, chart, and alert on user-defined metrics via Scheduled or Ad-Hoc Tests.

Written by Panickos Neophytou

Custom Command tests let you execute custom Bash or Python scripts on NetBeez Network Agents (hardware, virtual, cloud, container, and Linux software agents) to collect, chart, and alert on specialized numeric metrics. Custom Command tests are available both as recurring Scheduled Tests and as instant Ad-Hoc Tests. (Custom Command is not supported on Windows or macOS Remote Workers.)

In this article:

Script and Output Schema Requirements

Every Custom Command test pairs an executable script with an Output Schema that tells NetBeez which output keys to store and plot:

  • Required Shebang (Line 1): The script must start with either #!/usr/bin/env bash or #!/usr/bin/env python (including #!/usr/bin/env python3).

  • Script Size & Non-Interactive Execution: Scripts can contain up to 20,000 characters and must run non-interactively within the configured Timeout (seconds) (1–120 seconds, default 30 seconds).

  • Standard Output Format (key=value): Print one metric per line to stdout in metric_name=numeric_value format (integers or floating-point numbers). Any output lines that do not match a declared Metric name or do not contain a numeric value are ignored.

  • Output Schema Mapping: Define at least one Metric and Unit pair (up to 64 characters each). Click Add Output Schema Entry to capture multiple metrics from a single script, or click Remove to delete extra rows.

  • Custom Error Reporting (ERROR:): To surface a custom failure reason on the dashboard, print a line prefixed with ERROR: (for example, echo "ERROR: Service endpoint unreachable"). NetBeez records the error on the run and displays it in the Results error banner, per-agent Breakdown table, and Ad-Hoc result card.

Creating a Scheduled Custom Command Test

Scheduled Custom Command wizard Configure Test step displaying the script editor, Output Schema Metric and Unit fields, Timeout, and Interface options
  1. Go to Scheduled Tests in the primary left sidebar and click Add Template.

  2. Select Custom Command on the Choose Test Type step.

  3. Details: Enter a Name and optional Description, then click Configure Test.

  4. Configure Test:

    • Paste your script (beginning with #!/usr/bin/env bash or #!/usr/bin/env python) into Custom Command.

    • Enter each Metric key and display Unit under Output Schema (click Add Output Schema Entry for additional metrics).

    • Set Timeout (seconds) (1–120, default 30) and choose the Interface (Wi-Fi or Wired) for Wi-Fi Network Agents.

  5. Source Agents: Select one or more Network Agents and/or Agent Groups.

  6. Schedule: Set the cron frequency and select the Run Mode: Parallel (default), Serial, or Random with a Run Window.

  7. Alerts: Optionally attach Scheduled Test Error alert profiles (which fire when X out of the last Y runs return an execution error; Custom Command skips Monitoring Conditions), then click Create Scheduled Test.

Custom Command Scheduled Test detail view showing custom metric bars in Results and per-agent Breakdown metrics

Running an Ad-Hoc Custom Command Test

Before scheduling a script across an entire Agent Group, you can validate its output on a single Network Agent from Ad-Hoc Tests (/ad_hoc, visible to Read Write and Administrator users):

  1. Open Ad-Hoc Tests and click Custom Command in the Test Type bar.

  2. Select an online, non-busy Network Agent in Source Agent (and choose Wi-Fi or Wired if applicable).

  3. Paste your Custom Command script, set Timeout (seconds), and add matching Metric and Unit rows under Output Schema.

  4. Click Run Custom Command Test. Extracted metrics (with units) and any ERROR: messages render directly in the result card.

Example Bash and Python Scripts

Bash Example: Measuring Page Load Time with curl

Set Output Schema to Metric:load_time and Unit:seconds:

#!/usr/bin/env bash
load_time=$(curl -o /dev/null -s -w "%{time_total}\n" https://www.netbeez.net)
if [ $? -ne 0 ]; then
  echo "ERROR: curl request failed"
  exit 1
fi
echo "load_time=$load_time"

Python Example: Emitting Multiple Metrics

Add two Output Schema entries—tcp_handshake (ms) and payload_bytes (bytes):

#!/usr/bin/env python3
import socket
import timestart = time.monotonic()
with socket.create_connection(("example.com", 443), timeout=5) as sock:
    elapsed_ms = round((time.monotonic() - start) * 1000, 2)print(f"tcp_handshake={elapsed_ms}")
print("payload_bytes=512")

Tip: Always verify that required packages or CLI utilities exist on target Network Agents before deploying scripts across multiple agents, and browse the NetBeez Community for reusable script examples.

Did this answer your question?