vrf-ping's web UI and the Zabbix template talk to vrf-ping through this API. The
same rules hold in fogping and pingping, so a client written for one reads the
others the same way. Targets themselves are not edited through the API: they
come from targets/*.list (see the README).
The same API in machine-readable form: openapi.yaml (OpenAPI 3.1).
A test (TestOpenAPIMatchesRoutes) fails when it and the registered routes differ.
These are enforced by tests (api_test.go): code that breaks one does not pass CI.
-
Version. This is API version 1. Every
/api/response carries the headerAPI-Version: 1. Within version 1, changes are only additive: new endpoints, new optional request fields, new response fields. Removing or renaming a field, or changing what it means, needs a new prefix/api/v2/, and/api/keeps answering as before. -
Methods. Every endpoint names its methods. Reads are
GET, createsPOST, replacementsPUT, deletionsDELETE, actionsPOST. Any other method gets405with anAllowheader. -
JSON in, JSON out. A request with a body sends
Content-Type: application/json(anything else gets415). Every response, errors included, isapplication/json; charset=utf-8. -
One error shape. Every error is
{"error": "<message for a person>", "code": "<code for a program>"}. Programs branch oncode(or the status); people readerror. The codes:Status code400 bad_request401 unauthorized403 forbidden404 not_found405 method_not_allowed409 conflict413 too_large415 unsupported_media_type429 rate_limited(withRetry-After)500 internal503 unavailableAn unknown path under
/api/is a404in the same shape. -
Names. JSON keys are
snake_case, in requests and responses. Times are Unix seconds; a duration or size says its unit in its name (interval_sec,window_sec); a percentage ends in_pct. The one exception is the compact sample format of/api/series(below), which predates these rules and is kept for compatibility. -
Authentication. The web UI signs in with
POST /api/loginand then sends thevrfping_sessioncookie. Machine clients use a bearer token (Authorization: Bearer …) where an endpoint says so. The/api/statstoken is read-only by design: it can read statistics and nothing else, and there are no write tokens. Every write needs a signed-in session. A missing or bad credential is401. The one write,PUT /api/routing-options, needs a login to be configured and a same-origin browser request (403otherwise). -
Documented. Every endpoint is listed below. A test compares this table with the routes the code registers, both ways.
| Method | Path | Auth | What it does |
|---|---|---|---|
| POST | /api/login | none | Sign in. Body {"user": "…", "pass": "…"}; sets the session cookie. Repeated failures from one address get 429. |
| POST | /api/logout | none | Sign out: the session ends on the server too. Safe to call without one. |
| GET | /api/version | none | {"version"}. |
| GET | /api/health | session | Whether the target lists are applied in full: lines skipped at startup and the latest refused reload. |
| GET | /api/routing-options | session | ?target=NAME: the target's active and saved VRF and source address, and whether a reload is pending. |
| PUT | /api/routing-options | session, login configured, same-origin | Save a target's VRF and source address. Body {"name", "vrf", "source_address"}; applied by the next reload. |
| GET | /api/targets | session | Every target with its last-hour and last-day summary, routing and latest probe error. |
| GET | /api/series | session | Rounds for one target: ?target=NAME and either ?minutes=N or ?from=&to= (Unix seconds). |
| GET | /api/stats | bearer token | Per-target summary of the last 5 minutes, for Zabbix. Exists only with --zabbix. |
"session" means: a signed-in session when vrf-ping was started with a login,
anyone otherwise. Data requests (/api/targets, /api/series) are limited to a
few at a time; beyond that they wait, and after 30 seconds get 503.
[{"t": 1700000000, "s": 20, "r": 19, "ms": [12.1, 12.4], "b": true, "z": 3.8},
{"t": 1700000060, "s": 0, "r": 0, "ms": null, "error": "bind to VRF blue: no such device"}]One entry per round, oldest first: t time (Unix seconds), s packets sent,
r received, ms every reply's round-trip time in milliseconds, b true when
the round was flagged as a loss burst, z the robust z-score behind that flag,
error set when the round could not probe at all (then s and r are 0; it is
not packet loss). Rounds older than the full-sample window are downsampled in
place and keep the same shape.