Repository navigation
Expand file tree
/
Copy pathopenapi.yaml
More file actions
476 lines (474 loc) · 16.4 KB
/
Copy pathopenapi.yaml
File metadata and controls
476 lines (474 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
openapi: 3.1.0
info:
title: vrf-ping HTTP API
version: "1"
summary: The API the vrf-ping web UI and the Zabbix template use.
description: |
Machine-readable form of [API.md](API.md); the rules there apply.
Every `/api/` response carries `API-Version: 1`. Every error is
`{"error", "code"}` (schema `Error`). A wrong method on a known path is
`405` with an `Allow` header; an unknown path under `/api/` is `404`.
"session" below means the `vrfping_session` cookie from `POST /api/login`
when vrf-ping was started with login users; without them, anyone may call
those endpoints. Session endpoints share five request slots; a request
that waits 30 seconds for one gets `503` with `Retry-After: 5`.
`GET /api/stats` is the only endpoint that takes a bearer token, and that
token is read-only.
`openapi_test.go` (`TestOpenAPIMatchesRoutes`) fails when this file and the
routes the code registers differ.
license:
name: Apache-2.0
identifier: Apache-2.0
servers:
- url: /
description: The vrf-ping instance serving this API.
tags:
- name: pages
description: HTML pages and static files, outside `/api/`.
- name: auth
description: Sign in and out.
- name: info
description: Version and configuration health.
- name: routing
description: Per-target VRF and source address.
- name: data
description: Targets and measurements.
security:
- session: []
paths:
/:
get:
tags: [pages]
operationId: getIndex
summary: The web UI.
security: []
responses:
"200":
description: The dashboard page.
content:
text/html: {}
"302":
description: Not signed in; redirects to `/login`.
headers:
Location:
schema: { type: string, const: /login }
"405":
description: Wrong method (plain text; not under `/api/`).
/login:
get:
tags: [pages]
operationId: getLoginPage
summary: The sign-in page.
security: []
responses:
"200":
description: The sign-in page.
content:
text/html: {}
"405":
description: Wrong method (plain text; not under `/api/`).
/static/{path}:
get:
tags: [pages]
operationId: getStatic
summary: Embedded static files (the route is the prefix `/static/`).
security: []
parameters:
- name: path
in: path
required: true
description: File path below `/static/`; may contain `/`.
schema: { type: string }
responses:
"200":
description: The file.
content:
"*/*": {}
"404":
description: No such file (plain text, not under `/api/`).
"405":
description: Wrong method (plain text; not under `/api/`).
/api/login:
post:
tags: [auth]
operationId: login
summary: Sign in and get the session cookie.
security: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
user: { type: string }
pass: { type: string }
responses:
"200":
description: Signed in.
headers:
Set-Cookie:
description: "`vrfping_session`; HttpOnly, SameSite=Lax, 2 hours from issue."
schema: { type: string }
content:
application/json:
schema: { $ref: "#/components/schemas/Ok" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"413": { $ref: "#/components/responses/TooLarge" }
"415": { $ref: "#/components/responses/UnsupportedMediaType" }
"429": { $ref: "#/components/responses/RateLimited" }
/api/logout:
post:
tags: [auth]
operationId: logout
summary: Sign out; the session also ends on the server. Safe without one.
security: []
responses:
"200":
description: Signed out; the cookie is cleared.
content:
application/json:
schema: { $ref: "#/components/schemas/Ok" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
/api/version:
get:
tags: [info]
operationId: getVersion
summary: Build version.
security: []
responses:
"200":
description: Version.
content:
application/json:
schema:
type: object
required: [version]
properties:
version: { type: string }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
/api/health:
get:
tags: [info]
operationId: getHealth
summary: Whether the target lists are applied in full.
responses:
"200":
description: Lines skipped at startup and the latest refused reload.
headers:
Cache-Control:
schema: { type: string, const: no-store }
content:
application/json:
schema: { $ref: "#/components/schemas/HealthReport" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"503": { $ref: "#/components/responses/Busy" }
/api/routing-options:
get:
tags: [routing]
operationId: getRoutingOptions
summary: A target's active and saved VRF and source address.
parameters:
- name: target
in: query
required: true
description: Target name.
schema: { type: string }
responses:
"200":
description: Routing as running, as saved, and whether a reload is pending.
headers:
Cache-Control:
schema: { type: string, const: no-store }
content:
application/json:
schema:
type: object
required: [editable, target, saved_target, pending_reload]
properties:
editable: { type: boolean, description: True when login users are configured. }
target: { $ref: "#/components/schemas/Target" }
saved_target: { $ref: "#/components/schemas/Target" }
pending_reload: { type: boolean }
"401": { $ref: "#/components/responses/Unauthorized" }
"404": { $ref: "#/components/responses/NotFound" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"500": { $ref: "#/components/responses/Internal" }
"503": { $ref: "#/components/responses/Busy" }
put:
tags: [routing]
operationId: putRoutingOptions
summary: Save a target's VRF and source address; applied by the next reload.
description: >
Needs login users to be configured, a browser `Origin` equal to this
host (and `Sec-Fetch-Site: same-origin` when sent), and a JSON body.
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [name, vrf, source_address]
properties:
name: { type: string, minLength: 1 }
vrf: { type: string, description: Empty for the default table. }
source_address: { type: string, description: Empty for automatic. }
responses:
"200":
description: Saved.
headers:
Cache-Control:
schema: { type: string, const: no-store }
content:
application/json:
schema:
type: object
required: [saved, pending_reload, target]
properties:
saved: { type: boolean, const: true }
pending_reload: { type: boolean, const: true }
target: { $ref: "#/components/schemas/Target" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"404": { $ref: "#/components/responses/NotFound" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"413": { $ref: "#/components/responses/TooLarge" }
"415": { $ref: "#/components/responses/UnsupportedMediaType" }
"500": { $ref: "#/components/responses/Internal" }
"503": { $ref: "#/components/responses/Busy" }
/api/targets:
get:
tags: [data]
operationId: listTargets
summary: Every target with its last-hour and last-day summary, routing and latest probe error.
responses:
"200":
description: Targets; `null` when none has history yet.
content:
application/json:
schema:
type: [array, "null"]
items: { $ref: "#/components/schemas/TargetItem" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"503": { $ref: "#/components/responses/Busy" }
/api/series:
get:
tags: [data]
operationId: getSeries
summary: Every stored round for one target in a window.
parameters:
- name: target
in: query
required: true
schema: { type: string }
- name: minutes
in: query
description: Recent window; default 360, at most 300 days. Used when `from` or `to` is missing.
schema: { type: integer }
- name: from
in: query
description: Unix seconds.
schema: { type: integer, format: int64 }
- name: to
in: query
description: Unix seconds.
schema: { type: integer, format: int64 }
responses:
"200":
description: Rounds, oldest first; `null` when there are none.
content:
application/json:
schema:
type: [array, "null"]
items: { $ref: "#/components/schemas/Round" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"503": { $ref: "#/components/responses/Busy" }
/api/stats:
get:
tags: [data]
operationId: getStats
summary: Per-target summary of the last 5 minutes, for Zabbix.
description: Registered only when vrf-ping runs with `--zabbix` and a token.
security:
- bearer: []
responses:
"200":
description: Summary.
headers:
Cache-Control:
schema: { type: string, const: no-store }
content:
application/json:
schema: { $ref: "#/components/schemas/StatsReport" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"429": { $ref: "#/components/responses/RateLimited" }
components:
securitySchemes:
session:
type: apiKey
in: cookie
name: vrfping_session
bearer:
type: http
scheme: bearer
description: The read-only Zabbix token; accepted by `GET /api/stats` only.
responses:
BadRequest:
description: Bad input.
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
Unauthorized:
description: Missing or bad credential.
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
Forbidden:
description: No login users configured, or not a same-origin browser request.
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
NotFound:
description: No such target.
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
MethodNotAllowed:
description: Wrong method for this path.
headers:
Allow:
schema: { type: string }
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
TooLarge:
description: Request body too large.
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
UnsupportedMediaType:
description: Content-Type is not `application/json`.
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
RateLimited:
description: Too many failed attempts from this address.
headers:
Retry-After:
description: Seconds to wait.
schema: { type: integer }
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
Internal:
description: Server error.
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
Busy:
description: All request slots stayed busy for 30 seconds.
headers:
Retry-After:
schema: { type: integer, const: 5 }
content:
application/json:
schema: { $ref: "#/components/schemas/Error" }
schemas:
Error:
type: object
required: [error, code]
properties:
error: { type: string, description: For a person. }
code:
type: string
description: For a program; fixed per status.
enum: [bad_request, unauthorized, forbidden, not_found, method_not_allowed, conflict,
too_large, unsupported_media_type, rate_limited, unavailable, internal]
Ok:
type: object
required: [ok]
properties:
ok: { type: boolean, const: true }
HealthReport:
type: object
required: [ok]
properties:
ok: { type: boolean }
skipped_at_startup: { type: array, items: { type: string } }
reload_error: { type: string }
reload_error_since: { type: integer, format: int64, description: Unix seconds. }
Target:
type: object
required: [name, type, host, port, pace, interval_sec]
properties:
vrf: { type: string }
source_address: { type: string }
name: { type: string }
type: { type: string, description: "`icmp`, `tcp` or `http`." }
host: { type: string }
port: { type: integer }
pace: { type: string }
interval_sec: { type: integer }
options: { type: object }
Stats:
type: object
required: [rounds, p50, p90, p99, loss_pct, bursts]
properties:
rounds: { type: integer }
p50: { type: number }
p90: { type: number }
p99: { type: number }
loss_pct: { type: number }
bursts: { type: integer }
TargetItem:
type: object
required: [name, type, host, interval_sec, pace, down, vrf, source_address, last_1h, last_24h]
properties:
name: { type: string }
type: { type: string }
host: { type: string, description: "`host:port` for tcp." }
interval_sec: { type: integer }
pace: { type: string }
down: { type: boolean }
vrf: { type: string }
source_address: { type: string }
error: { type: string, description: Why the latest round could not probe. }
last_1h: { $ref: "#/components/schemas/Stats" }
last_24h: { $ref: "#/components/schemas/Stats" }
Round:
type: object
required: [t, s, r, ms]
properties:
t: { type: integer, format: int64, description: Unix seconds. }
s: { type: integer, description: Packets sent. }
r: { type: integer, description: Replies received. }
ms: { type: [array, "null"], items: { type: number } }
b: { type: boolean, description: Flagged as a loss burst. }
z: { type: number, description: Robust z-score behind the flag. }
error: { type: string, description: Why the round could not probe at all. }
StatsTarget:
type: object
required: [id, name, rounds, bursts, probe_errors]
properties:
id: { type: integer, format: int64 }
name: { type: string }
rounds: { type: integer }
p50: { type: number }
p90: { type: number }
p99: { type: number }
loss_pct: { type: number }
bursts: { type: integer }
up: { type: integer, enum: [0, 1] }
probe_errors: { type: integer }
StatsReport:
type: object
required: [window_sec, targets]
properties:
window_sec: { type: integer }
targets: { type: array, items: { $ref: "#/components/schemas/StatsTarget" } }