UNPKG

seraph-agent

Version:

An extremely lightweight, SRE autonomous AI agent for seamless integration with common observability tasks.

52 lines (51 loc) 1.98 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AlerterClient = void 0; const node_fetch_1 = __importDefault(require("node-fetch")); class AlerterClient { config; alertManagerUrl; constructor(config) { this.config = config; this.alertManagerUrl = this.config.alertManager?.url || ''; } async sendAlert(context) { if (!this.alertManagerUrl) { console.error('[AlerterClient] Alertmanager URL is not configured. Cannot send alert.'); return; } console.log('[AlerterClient] Sending alert with context:', JSON.stringify(context, null, 2)); const alert = { labels: { alertname: 'SeraphAnomalyDetected', source: context.source || 'unknown', type: context.type || 'unknown', }, annotations: { summary: `Anomaly detected in ${context.source}`, description: context.details || 'No details provided.', log: context.log || 'No log provided.', }, }; try { const response = await (0, node_fetch_1.default)(this.alertManagerUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify([alert]), }); if (!response.ok) { throw new Error(`Alertmanager returned an error: ${response.statusText} - ${await response.text()}`); } console.log('[AlerterClient] Successfully sent alert to Alertmanager.'); } catch (error) { console.error('[AlerterClient] Failed to send alert:', error.message); } } } exports.AlerterClient = AlerterClient;