-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tsp
161 lines (138 loc) · 3.43 KB
/
main.tsp
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
// ===============================================================
// TypeSpec definitions for NanoMon API
// ===============================================================
import "@typespec/http";
import "@typespec/json-schema";
import "@typespec/openapi";
using TypeSpec.Http;
using TypeSpec.JsonSchema;
using TypeSpec.OpenAPI;
@jsonSchema
// Core definitions for the whole API
@doc("The REST API for operating and using NanoMon")
@service({
title: "NanoMon API Service",
})
@info({
version: "2024-10-17",
})
@useAuth(BearerAuth)
// List servers and endpoints
@server("http://localhost:8000", "Local dev server endpoint")
@route("/api")
namespace NanoMon;
// ====================================================
// API operations for Monitors
// ====================================================
@route("/monitors")
@tag("Monitors")
interface MonitorAPI {
/** List all monitors. Doesn't require authentication */
list(): Monitor[];
/** Get a monitor by ID. Doesn't require authentication */
get(@path id: string): Monitor | {
@statusCode code: 400;
@body _: Problem;
} | {
@statusCode code: 404;
@body _: Problem;
};
@doc("Create a new monitor")
create(@body monitor: Monitor): Monitor | {
@statusCode code: 400;
@body _: Problem;
};
@doc("Update a single monitor")
update(@path id: string, @body monitor: Monitor): Monitor | {
@statusCode code: 400;
@body _: Problem;
} | {
@statusCode code: 404;
@body _: Problem;
};
@doc("Delete a monitor")
@delete
delete(@path id: string): void | {
@statusCode code: 400;
@body _: Problem;
} | {
@statusCode code: 404;
@body _: Problem;
};
@doc("Delete all monitors")
@delete
deleteAll(): void;
@doc("List *Results* for a single monitor. Doesn't require authentication")
@route("/{id}/results")
@get
getResults(@path id: string, @query max?: int32): Result[] | {
@statusCode code: 400;
@body _: Problem;
};
@doc("Import configuration from a JSON file")
@route("/import")
@post
importMonitors(@body monitor: Monitor[]): void | {
@statusCode code: 400;
};
}
// ====================================================
// API operations for Results
// ====================================================
@route("/results")
@tag("Results")
interface ResultsAPI {
@doc("List *Results* for ALL monitors. Doesn't require authentication")
@get
getResults(@query max?: int32): Result[];
}
// ====================================================
// MODELS
// ====================================================
// This holds the configuration for a single monitor
model Monitor {
@key
@visibility("read")
@pattern("[A-Fa-f0-9]{24}")
id: string;
@visibility("read")
updated: utcDateTime;
/** Name of this monitor */
name: string;
type: MonitorType;
target: string;
interval: duration;
rule: string;
enabled: boolean;
properties: Record<string>;
}
// Possible monitor types as an enumerated set
enum MonitorType {
http,
ping,
tcp,
dns,
}
// This holds the result of a single monitor check
model Result {
date: utcDateTime;
value: float64;
message: string;
monitor_id: string;
monitor_name: string;
monitor_target: string;
@minValue(0)
@maxValue(2)
status: int32;
}
// A standard RCF 7807 'Problem Details' for HTTP APIs
@error
model Problem {
type: string;
title: string;
detail: string;
instance: string;
@minValue(100)
@maxValue(599)
status: integer;
}