Openstatus sdk www.openstatus.dev
at maintenance-api 50 lines 1.5 kB view raw
1/** 2 * Example usage of the OpenStatus Node.js SDK. 3 * 4 * Run with: deno task dev 5 */ 6import { type HTTPMonitor, openstatus } from "./src/mod.ts"; 7 8async function main(): Promise<void> { 9 console.log("OpenStatus SDK Example\n"); 10 11 // 1. Health check (no authentication required) 12 console.log("1. Checking API health..."); 13 const health = await openstatus.health.v1.HealthService.check({}); 14 console.log(` Status: ${health.status}\n`); 15 16 // 2. List monitors (requires authentication) 17 const apiKey = process.env.OPENSTATUS_API_KEY; 18 if (!apiKey) { 19 console.log("2. Skipping monitor operations (OPENSTATUS_API_KEY not set)"); 20 console.log( 21 " Set OPENSTATUS_API_KEY environment variable to test monitor operations.", 22 ); 23 return; 24 } 25 26 const headers = { "x-openstatus-key": `${apiKey}` }; 27 28 console.log("2. Listing monitors..."); 29 const { httpMonitors, tcpMonitors, dnsMonitors, totalSize } = await openstatus 30 .monitor.v1.MonitorService.listMonitors({}, { headers }); 31 32 console.log(` Found ${totalSize} monitors:`); 33 console.log(` - HTTP: ${httpMonitors.length}`); 34 console.log(` - TCP: ${tcpMonitors.length}`); 35 console.log(` - DNS: ${dnsMonitors.length}`); 36 37 // 3. Display HTTP monitors 38 if (httpMonitors.length > 0) { 39 console.log("\n3. HTTP Monitors:"); 40 httpMonitors.forEach((monitor: HTTPMonitor) => { 41 console.log( 42 ` - ${monitor.name}: ${monitor.url} (${ 43 monitor.active ? "active" : "paused" 44 })`, 45 ); 46 }); 47 } 48} 49 50main().catch(console.error);