-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
50 lines (42 loc) · 1.51 KB
/
example.ts
File metadata and controls
50 lines (42 loc) · 1.51 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
/**
* Example usage of the OpenStatus Node.js SDK.
*
* Run with: deno task dev
*/
import { type HTTPMonitor, openstatus } from "./src/mod.ts";
async function main(): Promise<void> {
console.log("OpenStatus SDK Example\n");
// 1. Health check (no authentication required)
console.log("1. Checking API health...");
const health = await openstatus.health.v1.HealthService.check({});
console.log(` Status: ${health.status}\n`);
// 2. List monitors (requires authentication)
const apiKey = process.env.OPENSTATUS_API_KEY;
if (!apiKey) {
console.log("2. Skipping monitor operations (OPENSTATUS_API_KEY not set)");
console.log(
" Set OPENSTATUS_API_KEY environment variable to test monitor operations.",
);
return;
}
const headers = { "x-openstatus-key": `${apiKey}` };
console.log("2. Listing monitors...");
const { httpMonitors, tcpMonitors, dnsMonitors, totalSize } = await openstatus
.monitor.v1.MonitorService.listMonitors({}, { headers });
console.log(` Found ${totalSize} monitors:`);
console.log(` - HTTP: ${httpMonitors.length}`);
console.log(` - TCP: ${tcpMonitors.length}`);
console.log(` - DNS: ${dnsMonitors.length}`);
// 3. Display HTTP monitors
if (httpMonitors.length > 0) {
console.log("\n3. HTTP Monitors:");
httpMonitors.forEach((monitor: HTTPMonitor) => {
console.log(
` - ${monitor.name}: ${monitor.url} (${
monitor.active ? "active" : "paused"
})`,
);
});
}
}
main().catch(console.error);