Repository navigation
Expand file tree
/
Copy pathopenapi.yaml
More file actions
614 lines (612 loc) · 21.3 KB
/
Copy pathopenapi.yaml
File metadata and controls
614 lines (612 loc) · 21.3 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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
openapi: 3.1.0
info:
title: fogping HTTP API
version: "1"
summary: The API the fogping 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 `fogping_session` cookie from `POST /api/login`
when fogping was started with a login; without a login, anyone may call
those endpoints. `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 fogping instance serving this API (default port 8518).
tags:
- name: pages
description: HTML pages and static files, outside `/api/`.
- name: auth
description: Sign in and out.
- name: info
description: Build and probe-type information.
- name: targets
description: Read and change what is probed.
- name: data
description: 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: "`fogping_session`; HttpOnly, SameSite=Lax, 7 days."
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; instance settings too with a session.
security:
- {}
- session: []
responses:
"200":
description: >
`version` for everyone; with a session (or no login configured)
also `retention_days`, `hot_days` and `editable`.
content:
application/json:
schema:
type: object
required: [version]
properties:
version: { type: string }
retention_days: { type: integer }
hot_days: { type: integer }
editable: { type: boolean }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
/api/probe-types:
get:
tags: [info]
operationId: getProbeTypes
summary: The probe types this build can run, in display order.
responses:
"200":
description: Probe types.
content:
application/json:
schema:
type: array
items: { $ref: "#/components/schemas/ProbeType" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
/api/targets:
get:
tags: [targets]
operationId: listTargets
summary: Every target with its last-hour and last-day summary.
responses:
"200":
description: Targets.
content:
application/json:
schema:
type: array
items: { $ref: "#/components/schemas/TargetItem" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
post:
tags: [targets]
operationId: createTarget
summary: Create a target (needs `--edit`). Unknown fields are refused.
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/TargetInput" }
responses:
"200":
description: The created target.
content:
application/json:
schema: { $ref: "#/components/schemas/Target" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"409": { $ref: "#/components/responses/Conflict" }
"413": { $ref: "#/components/responses/TooLarge" }
"415": { $ref: "#/components/responses/UnsupportedMediaType" }
"500": { $ref: "#/components/responses/Internal" }
/api/targets/{id}:
parameters:
- $ref: "#/components/parameters/TargetID"
put:
tags: [targets]
operationId: replaceTarget
summary: Replace a target (needs `--edit`).
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/TargetInput" }
responses:
"200":
description: The replaced target.
content:
application/json:
schema: { $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" }
"409": { $ref: "#/components/responses/Conflict" }
"413": { $ref: "#/components/responses/TooLarge" }
"415": { $ref: "#/components/responses/UnsupportedMediaType" }
"500": { $ref: "#/components/responses/Internal" }
delete:
tags: [targets]
operationId: deleteTarget
summary: Delete a target (needs `--edit`); its history is kept.
responses:
"200":
description: The deleted target as it was.
content:
application/json:
schema: { $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" }
"500": { $ref: "#/components/responses/Internal" }
/api/targets/export:
get:
tags: [targets]
operationId: exportTargets
summary: The target list as a `netping-targets` file download.
responses:
"200":
description: See [targets-format.md](targets-format.md).
headers:
Content-Disposition:
schema: { type: string }
content:
application/json:
schema: { $ref: "#/components/schemas/TargetsFile" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"500": { $ref: "#/components/responses/Internal" }
/api/targets/import:
post:
tags: [targets]
operationId: importTargets
summary: Import a `netping-targets` file (needs `--edit`).
parameters:
- name: dry_run
in: query
description: "`1`, `true` or `yes`: report the plan without applying it."
schema: { type: string }
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/TargetsFile" }
responses:
"200":
description: What was (or would be) imported.
content:
application/json:
schema: { $ref: "#/components/schemas/ImportPlan" }
"400": { $ref: "#/components/responses/BadRequest" }
"401": { $ref: "#/components/responses/Unauthorized" }
"403": { $ref: "#/components/responses/Forbidden" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
"409": { $ref: "#/components/responses/Conflict" }
"413": { $ref: "#/components/responses/TooLarge" }
"415": { $ref: "#/components/responses/UnsupportedMediaType" }
"500": { $ref: "#/components/responses/Internal" }
/api/series:
get:
tags: [data]
operationId: getSeries
summary: Rounds for one target, raw up to a day and hourly beyond.
parameters:
- name: target
in: query
required: true
schema: { type: string }
- name: minutes
in: query
description: Recent window; default 360, at most 93 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: See "`/api/series` format" in API.md.
content:
application/json:
schema: { $ref: "#/components/schemas/Series" }
"401": { $ref: "#/components/responses/Unauthorized" }
"405": { $ref: "#/components/responses/MethodNotAllowed" }
/api/stats:
get:
tags: [data]
operationId: getStats
summary: Per-target summary of the last 5 minutes, for Zabbix.
description: Registered only when fogping 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: fogping_session
bearer:
type: http
scheme: bearer
description: The read-only Zabbix token; accepted by `GET /api/stats` only.
parameters:
TargetID:
name: id
in: path
required: true
schema: { type: integer, format: int64, minimum: 1 }
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: Read-only instance (no `--edit`) or a cross-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" }
Conflict:
description: The name is taken or belongs to a deleted target.
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" }
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 }
OptionSpec:
type: object
required: [key, label, kind]
properties:
key: { type: string }
label: { type: string }
help: { type: string }
kind: { type: string }
required: { type: boolean }
default: {}
min: { type: integer }
max: { type: integer }
max_len: { type: integer }
choices: { type: array, items: { type: string } }
ProbeType:
type: object
required: [type, label, uses_port, options]
properties:
type: { type: string }
label: { type: string }
uses_port: { type: boolean }
options: { type: array, items: { $ref: "#/components/schemas/OptionSpec" } }
TargetInput:
type: object
additionalProperties: false
properties:
id: { type: integer, format: int64, description: Ignored; the path id wins on PUT. }
name: { type: string }
type: { type: string, description: A probe type from `/api/probe-types`; `icmp` when empty. }
host: { type: string }
port: { type: integer }
pace: { type: string, enum: ["", fast, normal, slow] }
interval_sec: { type: integer }
options: { type: object, description: Keys per the type's spec (OPTIONS.md). }
Target:
type: object
required: [id, name, type, host, port, pace, interval_sec]
properties:
id: { type: integer, format: int64 }
name: { type: string }
type: { type: string }
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, probe_errors]
properties:
rounds: { type: integer }
p50: { type: number }
p90: { type: number }
p99: { type: number }
loss_pct: { type: number }
bursts: { type: integer }
probe_errors: { type: integer }
TargetItem:
type: object
required: [id, name, type, host, port, addr, interval_sec, interval_set, pace, down, last_1h, last_24h]
properties:
id: { type: integer, format: int64 }
name: { type: string }
type: { type: string }
host: { type: string }
port: { type: integer }
addr: { type: string }
interval_sec: { type: integer, description: Effective interval. }
interval_set: { type: integer, description: Explicit override; 0 means from pace. }
pace: { type: string }
options: { type: object }
down: { type: boolean }
probe_error: { type: string, description: Why the latest round could not be measured. }
last_1h: { $ref: "#/components/schemas/Stats" }
last_24h: { $ref: "#/components/schemas/Stats" }
TargetsFile:
type: object
description: A `netping-targets` file; full schema in [targets.schema.json](targets.schema.json).
required: [format, version, targets]
properties:
format: { type: string, const: netping-targets }
version: { type: integer }
name: { type: string }
description: { type: string }
targets: { type: array, items: { type: object } }
ImportPlan:
type: object
required: [total, add, skip, invalid, dry_run, imported]
properties:
name: { type: string }
description: { type: string }
total: { type: integer }
add:
type: array
items:
type: object
required: [row, type, host]
properties:
row: { type: integer }
name: { type: string }
type: { type: string }
host: { type: string }
port: { type: integer }
pace: { type: string }
interval: { type: integer }
options: { type: object }
restores_history: { type: boolean }
skip:
type: array
items:
type: object
required: [row, name, code, reason]
properties:
row: { type: integer }
name: { type: string }
code: { type: string, enum: [exists, duplicate] }
reason: { type: string }
invalid:
type: array
items:
type: object
required: [row, error]
properties:
row: { type: integer }
name: { type: string }
error: { type: string }
dry_run: { type: boolean }
imported: { type: integer }
Round:
type: object
required: [t, s, r, ms]
properties:
t: { type: integer, format: int64, description: Unix seconds. }
s: { type: integer, description: Packets sent; 0 when the round could not be measured. }
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. }
e: { type: string, description: Why the round could not be measured. }
Bucket:
type: object
required: [t, loss, n]
properties:
t: { type: integer, format: int64 }
q: { type: array, items: { type: number }, description: "min, p50, p90, p99, max in ms." }
loss: { type: number, description: Percent of packets lost. }
n: { type: integer }
bursts: { type: integer }
Series:
type: object
required: [tier]
properties:
tier: { type: string, enum: [raw, hourly] }
rounds: { type: array, items: { $ref: "#/components/schemas/Round" } }
buckets: { type: array, items: { $ref: "#/components/schemas/Bucket" } }
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" } }