/** * AlertManager - Comprehensive alerting system with multi-channel notifications * Target: 1,450 lines, 89% token reduction * * Operations: * 1. create-alert - Create new alert rule * 2. update-alert - Modify existing alert rule * 3. delete-alert - Remove alert rule * 4. list-alerts - List all alert rules with status * 5. trigger - Manually trigger alert (for testing) * 6. get-history - Get alert firing history * 7. configure-channels - Setup notification channels * 8. silence - Temporarily silence alerts * * Token Reduction Techniques: * - Alert rule metadata caching (92% reduction, 6-hour TTL) * - History aggregation (88% reduction, return counts instead of full events) * - Channel configuration caching (95% reduction, 24-hour TTL) * - Silence state compression (90% reduction) */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface AlertManagerOptions { operation: 'create-alert' | 'update-alert' | 'delete-alert' | 'list-alerts' | 'trigger' | 'get-history' | 'configure-channels' | 'silence'; alertId?: string; alertName?: string; condition?: AlertCondition; severity?: 'info' | 'warning' | 'error' | 'critical'; channels?: Array<'email' | 'slack' | 'webhook' | 'sms' | 'pagerduty' | 'custom'>; dataSource?: DataSource; threshold?: { type: 'above' | 'below' | 'equals' | 'not-equals' | 'change' | 'anomaly'; value?: number; changePercent?: number; timeWindow?: number; }; channelConfig?: { email?: { to: string[]; subject?: string; template?: string; }; slack?: { webhook: string; channel?: string; mentionUsers?: string[]; }; webhook?: { url: string; method?: string; headers?: Record; }; sms?: { to: string[]; provider?: string; }; pagerduty?: { serviceKey: string; severity?: string; }; }; silenceId?: string; silenceDuration?: number; silenceReason?: string; timeRange?: { start: number; end: number; }; limit?: number; useCache?: boolean; cacheTTL?: number; } export interface AlertCondition { metric: string; aggregation?: 'avg' | 'sum' | 'min' | 'max' | 'count' | 'percentile'; percentile?: number; groupBy?: string[]; filters?: Array<{ field: string; operator: string; value: any; }>; } export interface DataSource { id: string; type: 'api' | 'database' | 'file' | 'mcp-tool' | 'custom'; connection: { url?: string; method?: string; headers?: Record; query?: string; tool?: string; }; transform?: string; cache?: { enabled: boolean; ttl: number; }; } export interface Alert { id: string; name: string; description?: string; condition: AlertCondition; severity: 'info' | 'warning' | 'error' | 'critical'; channels: string[]; dataSource: DataSource; threshold: { type: string; value?: number; changePercent?: number; timeWindow?: number; }; enabled: boolean; createdAt: number; updatedAt: number; lastTriggered?: number; triggerCount: number; status: 'active' | 'silenced' | 'disabled'; silencedUntil?: number; } export interface AlertEvent { id: string; alertId: string; alertName: string; severity: 'info' | 'warning' | 'error' | 'critical'; triggeredAt: number; value: number; threshold: number; message: string; metadata?: Record; channelsNotified: string[]; resolved?: boolean; resolvedAt?: number; } export interface NotificationChannel { id: string; name: string; type: 'email' | 'slack' | 'webhook' | 'sms' | 'pagerduty' | 'custom'; config: { email?: { to: string[]; subject?: string; template?: string; }; slack?: { webhook: string; channel?: string; mentionUsers?: string[]; }; webhook?: { url: string; method?: string; headers?: Record; }; sms?: { to: string[]; provider?: string; }; pagerduty?: { serviceKey: string; severity?: string; }; custom?: Record; }; enabled: boolean; createdAt: number; lastUsed?: number; successCount: number; failureCount: number; } export interface SilenceRule { id: string; alertId?: string; reason?: string; createdAt: number; expiresAt: number; createdBy?: string; active: boolean; } export interface AlertManagerResult { success: boolean; data?: { alert?: Alert; alerts?: Alert[]; history?: AlertEvent[]; channels?: NotificationChannel[]; triggered?: boolean; silence?: SilenceRule; }; metadata: { tokensUsed?: number; tokensSaved?: number; cacheHit: boolean; alertCount?: number; firingCount?: number; }; error?: string; } export declare class AlertManager { private cache; private tokenCounter; private metricsCollector; private alerts; private alertEvents; private notificationChannels; private silenceRules; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector); /** * Main entry point for alert management operations */ run(options: AlertManagerOptions): Promise; private createAlert; private updateAlert; private deleteAlert; private listAlerts; private triggerAlert; private getHistory; private configureChannels; private silenceAlerts; private generateAlertId; private generateEventId; private generateChannelId; private generateSilenceId; private findAlertIdByName; private isAlertSilenced; private compressAlertMetadata; private aggregateHistory; private estimateHistoryTokenSavings; private sendNotifications; private cleanupExpiredSilences; private persistAlerts; private persistEvents; private persistChannels; private persistSilences; private loadPersistedData; } export declare function getAlertManager(cache: CacheEngine, tokenCounter: TokenCounter, metricsCollector: MetricsCollector): AlertManager; export declare const ALERT_MANAGER_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { operation: { type: string; enum: string[]; description: string; }; alertId: { type: string; description: string; }; alertName: { type: string; description: string; }; condition: { type: string; description: string; properties: { metric: { type: string; }; aggregation: { type: string; enum: string[]; }; percentile: { type: string; }; groupBy: { type: string; items: { type: string; }; }; filters: { type: string; items: { type: string; properties: { field: { type: string; }; operator: { type: string; }; value: {}; }; }; }; }; required: string[]; }; severity: { type: string; enum: string[]; description: string; }; channels: { type: string; items: { type: string; enum: string[]; }; description: string; }; threshold: { type: string; description: string; properties: { type: { type: string; enum: string[]; }; value: { type: string; }; changePercent: { type: string; }; timeWindow: { type: string; }; }; }; channelConfig: { type: string; description: string; properties: { email: { type: string; properties: { to: { type: string; items: { type: string; }; }; subject: { type: string; }; template: { type: string; }; }; }; slack: { type: string; properties: { webhook: { type: string; }; channel: { type: string; }; mentionUsers: { type: string; items: { type: string; }; }; }; }; webhook: { type: string; properties: { url: { type: string; }; method: { type: string; }; headers: { type: string; }; }; }; }; }; silenceDuration: { type: string; description: string; }; silenceReason: { type: string; description: string; }; timeRange: { type: string; description: string; properties: { start: { type: string; }; end: { type: string; }; }; }; limit: { type: string; description: string; }; useCache: { type: string; description: string; default: boolean; }; cacheTTL: { type: string; description: string; }; dataSource: { type: string; description: string; properties: { id: { type: string; }; type: { type: string; enum: string[]; }; connection: { type: string; description: string; properties: { url: { type: string; }; method: { type: string; }; headers: { type: string; additionalProperties: { type: string; }; }; query: { type: string; }; tool: { type: string; description: string; }; }; }; transform: { type: string; description: string; }; cache: { type: string; description: string; properties: { enabled: { type: string; }; ttl: { type: string; description: string; }; }; required: string[]; }; }; required: string[]; }; silenceId: { type: string; description: string; }; }; required: string[]; }; }; //# sourceMappingURL=alert-manager.d.ts.map