diff --git a/backend/src/integrations/netbird.ts b/backend/src/integrations/netbird.ts new file mode 100644 index 0000000..13c4152 --- /dev/null +++ b/backend/src/integrations/netbird.ts @@ -0,0 +1,44 @@ +import type { IntegrationAdapter, Resource } from './types.js' + +interface NetbirdPeer { + name: string + hostname?: string + connected: boolean + ip?: string + os?: string +} + +function baseUrlFor(config: Record) { + return (config.baseUrl?.replace(/\/$/, '')) || 'https://api.netbird.io' +} + +export const netbird: IntegrationAdapter = { + async testConnection(config, secrets) { + const apiKey = secrets.apiKey + if (!apiKey) return { ok: false, message: 'Missing API key' } + try { + const res = await fetch(`${baseUrlFor(config)}/api/peers`, { + headers: { Authorization: `Token ${apiKey}` }, + }) + if (!res.ok) return { ok: false, message: `HTTP ${res.status}` } + return { ok: true, message: 'Connected' } + } catch (err) { + return { ok: false, message: err instanceof Error ? err.message : 'Connection failed' } + } + }, + + async listResources(config, secrets): Promise { + const apiKey = secrets.apiKey + if (!apiKey) return [] + const res = await fetch(`${baseUrlFor(config)}/api/peers`, { + headers: { Authorization: `Token ${apiKey}` }, + }) + if (!res.ok) return [] + const peers = (await res.json()) as NetbirdPeer[] + return peers.map((p) => ({ + name: p.name || p.hostname || p.ip || 'unknown peer', + status: p.connected ? 'healthy' : 'critical', + detail: p.connected ? `Online — ${p.ip ?? ''}`.trim() : 'Offline', + })) + }, +} diff --git a/backend/src/integrations/registry.ts b/backend/src/integrations/registry.ts index 82af46d..739baa5 100644 --- a/backend/src/integrations/registry.ts +++ b/backend/src/integrations/registry.ts @@ -2,6 +2,7 @@ import type { IntegrationAdapter, IntegrationType } from './types.js' import { uptimeKuma } from './uptimeKuma.js' import { docker } from './docker.js' import { proxmox } from './proxmox.js' +import { netbird } from './netbird.js' const notImplemented: IntegrationAdapter = { async testConnection() { @@ -13,7 +14,7 @@ export const adapterRegistry: Record = { uptime_kuma: uptimeKuma, docker, proxmox, - netbird: notImplemented, + netbird, cloudflare: notImplemented, aws: notImplemented, weather: notImplemented,