mcp-image 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -17
- package/dist/api/geminiClient.d.ts +2 -12
- package/dist/api/geminiClient.d.ts.map +1 -1
- package/dist/api/geminiClient.js +28 -56
- package/dist/api/geminiClient.js.map +1 -1
- package/dist/api/geminiTextClient.d.ts +42 -0
- package/dist/api/geminiTextClient.d.ts.map +1 -0
- package/dist/api/geminiTextClient.js +198 -0
- package/dist/api/geminiTextClient.js.map +1 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.d.ts +84 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.d.ts.map +1 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.js +100 -0
- package/dist/business/__tests__/mocks/mcpSamplingClient.mock.js.map +1 -0
- package/dist/business/bestPracticesEngine.d.ts +149 -0
- package/dist/business/bestPracticesEngine.d.ts.map +1 -0
- package/dist/business/bestPracticesEngine.js +781 -0
- package/dist/business/bestPracticesEngine.js.map +1 -0
- package/dist/business/complexityAssessment.d.ts +132 -0
- package/dist/business/complexityAssessment.d.ts.map +1 -0
- package/dist/business/complexityAssessment.js +488 -0
- package/dist/business/complexityAssessment.js.map +1 -0
- package/dist/business/fallbackStrategies.d.ts +177 -0
- package/dist/business/fallbackStrategies.d.ts.map +1 -0
- package/dist/business/fallbackStrategies.js +368 -0
- package/dist/business/fallbackStrategies.js.map +1 -0
- package/dist/business/imageGenerator.d.ts.map +1 -1
- package/dist/business/imageGenerator.js +26 -5
- package/dist/business/imageGenerator.js.map +1 -1
- package/dist/business/multiImage/aspectRatioController.d.ts +77 -0
- package/dist/business/multiImage/aspectRatioController.d.ts.map +1 -0
- package/dist/business/multiImage/aspectRatioController.js +580 -0
- package/dist/business/multiImage/aspectRatioController.js.map +1 -0
- package/dist/business/multiImage/multiImageCoordinator.d.ts +142 -0
- package/dist/business/multiImage/multiImageCoordinator.d.ts.map +1 -0
- package/dist/business/multiImage/multiImageCoordinator.js +801 -0
- package/dist/business/multiImage/multiImageCoordinator.js.map +1 -0
- package/dist/business/pomlTemplateEngine.d.ts +206 -0
- package/dist/business/pomlTemplateEngine.d.ts.map +1 -0
- package/dist/business/pomlTemplateEngine.js +737 -0
- package/dist/business/pomlTemplateEngine.js.map +1 -0
- package/dist/business/promptOrchestrator.d.ts +173 -0
- package/dist/business/promptOrchestrator.d.ts.map +1 -0
- package/dist/business/promptOrchestrator.js +490 -0
- package/dist/business/promptOrchestrator.js.map +1 -0
- package/dist/business/responseBuilder.d.ts +2 -2
- package/dist/business/responseBuilder.d.ts.map +1 -1
- package/dist/business/responseBuilder.js +6 -1
- package/dist/business/responseBuilder.js.map +1 -1
- package/dist/business/structuredPromptGenerator.d.ts +54 -0
- package/dist/business/structuredPromptGenerator.d.ts.map +1 -0
- package/dist/business/structuredPromptGenerator.js +208 -0
- package/dist/business/structuredPromptGenerator.js.map +1 -0
- package/dist/business/templateNormalizer.d.ts +81 -0
- package/dist/business/templateNormalizer.d.ts.map +1 -0
- package/dist/business/templateNormalizer.js +659 -0
- package/dist/business/templateNormalizer.js.map +1 -0
- package/dist/documentation/apiContractValidation.d.ts +62 -0
- package/dist/documentation/apiContractValidation.d.ts.map +1 -0
- package/dist/documentation/apiContractValidation.js +305 -0
- package/dist/documentation/apiContractValidation.js.map +1 -0
- package/dist/infrastructure/concurrency/concurrencyManager.d.ts +101 -0
- package/dist/infrastructure/concurrency/concurrencyManager.d.ts.map +1 -0
- package/dist/infrastructure/concurrency/concurrencyManager.js +345 -0
- package/dist/infrastructure/concurrency/concurrencyManager.js.map +1 -0
- package/dist/infrastructure/config/secureConfigManager.d.ts +319 -0
- package/dist/infrastructure/config/secureConfigManager.d.ts.map +1 -0
- package/dist/infrastructure/config/secureConfigManager.js +600 -0
- package/dist/infrastructure/config/secureConfigManager.js.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.d.ts +229 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.d.ts.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.js +61 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandler.js.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.d.ts +133 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.d.ts.map +1 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.js +569 -0
- package/dist/infrastructure/errorHandling/orchestrationErrorHandlerImpl.js.map +1 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.d.ts +19 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.d.ts.map +1 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.js +31 -0
- package/dist/infrastructure/mcp/MCPSamplingClient.js.map +1 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.d.ts +59 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.d.ts.map +1 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.js +271 -0
- package/dist/infrastructure/mcp/RealMCPSamplingClient.js.map +1 -0
- package/dist/infrastructure/metadata/generationMetadata.d.ts +72 -0
- package/dist/infrastructure/metadata/generationMetadata.d.ts.map +1 -0
- package/dist/infrastructure/metadata/generationMetadata.js +228 -0
- package/dist/infrastructure/metadata/generationMetadata.js.map +1 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.d.ts +106 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.js +456 -0
- package/dist/infrastructure/monitoring/OrchestrationMetrics.js.map +1 -0
- package/dist/infrastructure/monitoring/alertingSystem.d.ts +135 -0
- package/dist/infrastructure/monitoring/alertingSystem.d.ts.map +1 -0
- package/dist/infrastructure/monitoring/alertingSystem.js +549 -0
- package/dist/infrastructure/monitoring/alertingSystem.js.map +1 -0
- package/dist/infrastructure/optimization/performanceOptimizer.d.ts +89 -0
- package/dist/infrastructure/optimization/performanceOptimizer.d.ts.map +1 -0
- package/dist/infrastructure/optimization/performanceOptimizer.js +375 -0
- package/dist/infrastructure/optimization/performanceOptimizer.js.map +1 -0
- package/dist/infrastructure/security/AdvancedContentFilter.d.ts +99 -0
- package/dist/infrastructure/security/AdvancedContentFilter.d.ts.map +1 -0
- package/dist/infrastructure/security/AdvancedContentFilter.js +363 -0
- package/dist/infrastructure/security/AdvancedContentFilter.js.map +1 -0
- package/dist/infrastructure/security/MCPSecurityValidator.d.ts +62 -0
- package/dist/infrastructure/security/MCPSecurityValidator.d.ts.map +1 -0
- package/dist/infrastructure/security/MCPSecurityValidator.js +129 -0
- package/dist/infrastructure/security/MCPSecurityValidator.js.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.d.ts +304 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.d.ts.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.js +61 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddleware.js.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.d.ts +62 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.d.ts.map +1 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.js +591 -0
- package/dist/infrastructure/security/OrchestrationSecurityMiddlewareImpl.js.map +1 -0
- package/dist/infrastructure/security/SecureMCPClient.d.ts +154 -0
- package/dist/infrastructure/security/SecureMCPClient.d.ts.map +1 -0
- package/dist/infrastructure/security/SecureMCPClient.js +292 -0
- package/dist/infrastructure/security/SecureMCPClient.js.map +1 -0
- package/dist/infrastructure/security/SecurityIncidentManager.d.ts +142 -0
- package/dist/infrastructure/security/SecurityIncidentManager.d.ts.map +1 -0
- package/dist/infrastructure/security/SecurityIncidentManager.js +260 -0
- package/dist/infrastructure/security/SecurityIncidentManager.js.map +1 -0
- package/dist/infrastructure/security/apiKeyManager.d.ts +297 -0
- package/dist/infrastructure/security/apiKeyManager.d.ts.map +1 -0
- package/dist/infrastructure/security/apiKeyManager.js +254 -0
- package/dist/infrastructure/security/apiKeyManager.js.map +1 -0
- package/dist/infrastructure/security/dataSanitizer.d.ts +157 -0
- package/dist/infrastructure/security/dataSanitizer.d.ts.map +1 -0
- package/dist/infrastructure/security/dataSanitizer.js +525 -0
- package/dist/infrastructure/security/dataSanitizer.js.map +1 -0
- package/dist/infrastructure/validation/inputValidator.d.ts +54 -0
- package/dist/infrastructure/validation/inputValidator.d.ts.map +1 -0
- package/dist/infrastructure/validation/inputValidator.js +362 -0
- package/dist/infrastructure/validation/inputValidator.js.map +1 -0
- package/dist/integration/parameterOptimizer.d.ts +69 -0
- package/dist/integration/parameterOptimizer.d.ts.map +1 -0
- package/dist/integration/parameterOptimizer.js +317 -0
- package/dist/integration/parameterOptimizer.js.map +1 -0
- package/dist/integration/twoStageProcessor.d.ts +66 -0
- package/dist/integration/twoStageProcessor.d.ts.map +1 -0
- package/dist/integration/twoStageProcessor.js +348 -0
- package/dist/integration/twoStageProcessor.js.map +1 -0
- package/dist/server/handlers/structuredPromptHandler.d.ts +65 -0
- package/dist/server/handlers/structuredPromptHandler.d.ts.map +1 -0
- package/dist/server/handlers/structuredPromptHandler.js +314 -0
- package/dist/server/handlers/structuredPromptHandler.js.map +1 -0
- package/dist/server/mcpServer.d.ts +16 -35
- package/dist/server/mcpServer.d.ts.map +1 -1
- package/dist/server/mcpServer.js +111 -150
- package/dist/server/mcpServer.js.map +1 -1
- package/dist/server/mcpServerWithOrchestration.d.ts +98 -0
- package/dist/server/mcpServerWithOrchestration.d.ts.map +1 -0
- package/dist/server/mcpServerWithOrchestration.js +284 -0
- package/dist/server/mcpServerWithOrchestration.js.map +1 -0
- package/dist/types/mcpOrchestrationTypes.d.ts +135 -0
- package/dist/types/mcpOrchestrationTypes.d.ts.map +1 -0
- package/dist/types/mcpOrchestrationTypes.js +28 -0
- package/dist/types/mcpOrchestrationTypes.js.map +1 -0
- package/dist/types/multiImageTypes.d.ts +328 -0
- package/dist/types/multiImageTypes.d.ts.map +1 -0
- package/dist/types/multiImageTypes.js +27 -0
- package/dist/types/multiImageTypes.js.map +1 -0
- package/dist/types/performanceTypes.d.ts +300 -0
- package/dist/types/performanceTypes.d.ts.map +1 -0
- package/dist/types/performanceTypes.js +50 -0
- package/dist/types/performanceTypes.js.map +1 -0
- package/dist/types/twoStageTypes.d.ts +123 -0
- package/dist/types/twoStageTypes.d.ts.map +1 -0
- package/dist/types/twoStageTypes.js +7 -0
- package/dist/types/twoStageTypes.js.map +1 -0
- package/dist/utils/config.d.ts +1 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +1 -0
- package/dist/utils/config.js.map +1 -1
- package/package.json +11 -4
- package/vitest.config.mjs +0 -47
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configurable alerting system for performance monitoring
|
|
3
|
+
* Provides intelligent threshold management and alert notification capabilities
|
|
4
|
+
*/
|
|
5
|
+
import { type AlertEvent, type AlertRule, type CurrentMetrics } from '../../types/performanceTypes';
|
|
6
|
+
/**
|
|
7
|
+
* Alert notification handler interface
|
|
8
|
+
*/
|
|
9
|
+
interface AlertNotificationHandler {
|
|
10
|
+
sendAlert(event: AlertEvent): Promise<void>;
|
|
11
|
+
isHealthy(): boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* AlertingSystem class
|
|
15
|
+
* Comprehensive alerting system with configurable rules and intelligent threshold management
|
|
16
|
+
*/
|
|
17
|
+
export declare class AlertingSystem {
|
|
18
|
+
private alertRules;
|
|
19
|
+
private alertHistory;
|
|
20
|
+
private notificationHandlers;
|
|
21
|
+
private cooldownTracking;
|
|
22
|
+
private readonly maxHistorySize;
|
|
23
|
+
constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Initialize default alert rules for common monitoring scenarios
|
|
26
|
+
*/
|
|
27
|
+
private initializeDefaultRules;
|
|
28
|
+
/**
|
|
29
|
+
* Add or update an alert rule
|
|
30
|
+
*/
|
|
31
|
+
addAlertRule(rule: AlertRule): void;
|
|
32
|
+
/**
|
|
33
|
+
* Remove an alert rule
|
|
34
|
+
*/
|
|
35
|
+
removeAlertRule(ruleId: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Get alert rule by ID
|
|
38
|
+
*/
|
|
39
|
+
getAlertRule(ruleId: string): AlertRule | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Get all alert rules
|
|
42
|
+
*/
|
|
43
|
+
getAllAlertRules(): AlertRule[];
|
|
44
|
+
/**
|
|
45
|
+
* Enable or disable an alert rule
|
|
46
|
+
*/
|
|
47
|
+
setAlertRuleEnabled(ruleId: string, enabled: boolean): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Add notification handler
|
|
50
|
+
*/
|
|
51
|
+
addNotificationHandler(name: string, handler: AlertNotificationHandler): void;
|
|
52
|
+
/**
|
|
53
|
+
* Add webhook notification handler
|
|
54
|
+
*/
|
|
55
|
+
addWebhookHandler(name: string, webhookUrl: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Check alerts against current metrics
|
|
58
|
+
*/
|
|
59
|
+
checkAlerts(metrics: CurrentMetrics): Promise<AlertEvent[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Evaluate a specific alert rule against metrics
|
|
62
|
+
*/
|
|
63
|
+
private evaluateAlertRule;
|
|
64
|
+
/**
|
|
65
|
+
* Evaluate performance degradation alerts
|
|
66
|
+
*/
|
|
67
|
+
private evaluatePerformanceAlert;
|
|
68
|
+
/**
|
|
69
|
+
* Evaluate cost threshold alerts
|
|
70
|
+
*/
|
|
71
|
+
private evaluateCostAlert;
|
|
72
|
+
/**
|
|
73
|
+
* Evaluate error rate alerts
|
|
74
|
+
*/
|
|
75
|
+
private evaluateErrorRateAlert;
|
|
76
|
+
/**
|
|
77
|
+
* Evaluate resource exhaustion alerts
|
|
78
|
+
*/
|
|
79
|
+
private evaluateResourceAlert;
|
|
80
|
+
/**
|
|
81
|
+
* Evaluate a specific condition
|
|
82
|
+
*/
|
|
83
|
+
private evaluateCondition;
|
|
84
|
+
/**
|
|
85
|
+
* Create alert event from rule and evaluation
|
|
86
|
+
*/
|
|
87
|
+
private createAlertEvent;
|
|
88
|
+
/**
|
|
89
|
+
* Calculate alert severity based on how much the threshold is exceeded
|
|
90
|
+
*/
|
|
91
|
+
private calculateSeverity;
|
|
92
|
+
/**
|
|
93
|
+
* Process triggered alert by sending notifications
|
|
94
|
+
*/
|
|
95
|
+
private processAlert;
|
|
96
|
+
/**
|
|
97
|
+
* Get alert history
|
|
98
|
+
*/
|
|
99
|
+
getAlertHistory(limit?: number): AlertEvent[];
|
|
100
|
+
/**
|
|
101
|
+
* Get active alerts (unresolved)
|
|
102
|
+
*/
|
|
103
|
+
getActiveAlerts(): AlertEvent[];
|
|
104
|
+
/**
|
|
105
|
+
* Resolve an alert
|
|
106
|
+
*/
|
|
107
|
+
resolveAlert(alertId: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Get alert statistics
|
|
110
|
+
*/
|
|
111
|
+
getAlertStatistics(): {
|
|
112
|
+
totalAlerts: number;
|
|
113
|
+
activeAlerts: number;
|
|
114
|
+
alertsByRule: Record<string, number>;
|
|
115
|
+
alertsBySeverity: Record<string, number>;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Update alert rule threshold dynamically
|
|
119
|
+
*/
|
|
120
|
+
updateAlertThreshold(ruleId: string, newThreshold: number): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Maintain alert history size limit
|
|
123
|
+
*/
|
|
124
|
+
private maintainHistoryLimit;
|
|
125
|
+
/**
|
|
126
|
+
* Get health status of all notification handlers
|
|
127
|
+
*/
|
|
128
|
+
getNotificationHandlerStatus(): Record<string, boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Clean up resources
|
|
131
|
+
*/
|
|
132
|
+
destroy(): void;
|
|
133
|
+
}
|
|
134
|
+
export {};
|
|
135
|
+
//# sourceMappingURL=alertingSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alertingSystem.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/monitoring/alertingSystem.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAA;AAErC;;GAEG;AACH,UAAU,wBAAwB;IAChC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3C,SAAS,IAAI,OAAO,CAAA;CACrB;AAyED;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAoC;IACtD,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAO;;IAUtC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAkG9B;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAInC;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIxC;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAInD;;OAEG;IACH,gBAAgB,IAAI,SAAS,EAAE;IAI/B;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAS9D;;OAEG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAI7E;;OAEG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAIzD;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IA6BjE;;OAEG;YACW,iBAAiB;IAkB/B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA4BhC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAmBzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAsB9B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAwB7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAiBzB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA8BxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA4BzB;;OAEG;YACW,YAAY;IA6B1B;;OAEG;IACH,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE;IAK7C;;OAEG;IACH,eAAe,IAAI,UAAU,EAAE;IAI/B;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAUtC;;OAEG;IACH,kBAAkB,IAAI;QACpB,WAAW,EAAE,MAAM,CAAA;QACnB,YAAY,EAAE,MAAM,CAAA;QACpB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACpC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACzC;IAiBD;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO;IAanE;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAM5B;;OAEG;IACH,4BAA4B,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUvD;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
|
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configurable alerting system for performance monitoring
|
|
4
|
+
* Provides intelligent threshold management and alert notification capabilities
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.AlertingSystem = void 0;
|
|
8
|
+
const performanceTypes_1 = require("../../types/performanceTypes");
|
|
9
|
+
/**
|
|
10
|
+
* Log-based alert handler
|
|
11
|
+
*/
|
|
12
|
+
class LogAlertHandler {
|
|
13
|
+
async sendAlert(event) {
|
|
14
|
+
const logLevel = this.getLogLevel(event.severity);
|
|
15
|
+
console[logLevel](`[ALERT ${event.severity.toUpperCase()}] ${event.message}`, {
|
|
16
|
+
ruleId: event.ruleId,
|
|
17
|
+
timestamp: new Date(event.timestamp).toISOString(),
|
|
18
|
+
context: event.context,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
isHealthy() {
|
|
22
|
+
return true; // Log handler is always considered healthy
|
|
23
|
+
}
|
|
24
|
+
getLogLevel(severity) {
|
|
25
|
+
switch (severity) {
|
|
26
|
+
case 'critical':
|
|
27
|
+
case 'high':
|
|
28
|
+
return 'error';
|
|
29
|
+
case 'medium':
|
|
30
|
+
return 'warn';
|
|
31
|
+
default:
|
|
32
|
+
return 'info';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Webhook-based alert handler
|
|
38
|
+
*/
|
|
39
|
+
class WebhookAlertHandler {
|
|
40
|
+
constructor(webhookUrl) {
|
|
41
|
+
this.isActive = true;
|
|
42
|
+
this.webhookUrl = webhookUrl;
|
|
43
|
+
}
|
|
44
|
+
async sendAlert(event) {
|
|
45
|
+
if (!this.isActive) {
|
|
46
|
+
throw new Error('Webhook handler is not healthy');
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
// In a real implementation, this would make an HTTP request
|
|
50
|
+
console.log(`Sending webhook alert to ${this.webhookUrl}:`, {
|
|
51
|
+
alert: event,
|
|
52
|
+
payload: {
|
|
53
|
+
text: `Alert: ${event.message}`,
|
|
54
|
+
severity: event.severity,
|
|
55
|
+
timestamp: event.timestamp,
|
|
56
|
+
context: event.context,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
// Simulate webhook call success
|
|
60
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
this.isActive = false;
|
|
64
|
+
throw new Error(`Webhook alert failed: ${error}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
isHealthy() {
|
|
68
|
+
return this.isActive;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* AlertingSystem class
|
|
73
|
+
* Comprehensive alerting system with configurable rules and intelligent threshold management
|
|
74
|
+
*/
|
|
75
|
+
class AlertingSystem {
|
|
76
|
+
constructor() {
|
|
77
|
+
this.alertRules = new Map();
|
|
78
|
+
this.alertHistory = [];
|
|
79
|
+
this.notificationHandlers = new Map();
|
|
80
|
+
this.cooldownTracking = new Map();
|
|
81
|
+
this.maxHistorySize = 1000;
|
|
82
|
+
// Initialize default notification handlers
|
|
83
|
+
this.notificationHandlers.set('log', new LogAlertHandler());
|
|
84
|
+
// Initialize default alert rules
|
|
85
|
+
this.initializeDefaultRules();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Initialize default alert rules for common monitoring scenarios
|
|
89
|
+
*/
|
|
90
|
+
initializeDefaultRules() {
|
|
91
|
+
// Performance degradation alert
|
|
92
|
+
this.addAlertRule({
|
|
93
|
+
id: 'performance_degradation',
|
|
94
|
+
name: 'Performance Degradation Alert',
|
|
95
|
+
type: performanceTypes_1.AlertType.PERFORMANCE_DEGRADATION,
|
|
96
|
+
enabled: true,
|
|
97
|
+
conditions: [
|
|
98
|
+
{
|
|
99
|
+
metric: 'averageProcessingTime',
|
|
100
|
+
operator: 'gt',
|
|
101
|
+
value: 25000, // 25 seconds
|
|
102
|
+
timeWindow: 300000, // 5 minutes
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
actions: [
|
|
106
|
+
{
|
|
107
|
+
type: 'log',
|
|
108
|
+
config: { severity: 'high' },
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
threshold: 25000,
|
|
112
|
+
cooldownPeriod: 600000, // 10 minutes
|
|
113
|
+
});
|
|
114
|
+
// High error rate alert
|
|
115
|
+
this.addAlertRule({
|
|
116
|
+
id: 'high_error_rate',
|
|
117
|
+
name: 'High Error Rate Alert',
|
|
118
|
+
type: performanceTypes_1.AlertType.ERROR_RATE,
|
|
119
|
+
enabled: true,
|
|
120
|
+
conditions: [
|
|
121
|
+
{
|
|
122
|
+
metric: 'errorRate',
|
|
123
|
+
operator: 'gt',
|
|
124
|
+
value: 0.1, // 10% error rate
|
|
125
|
+
timeWindow: 300000, // 5 minutes
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
actions: [
|
|
129
|
+
{
|
|
130
|
+
type: 'log',
|
|
131
|
+
config: { severity: 'medium' },
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
threshold: 0.1,
|
|
135
|
+
cooldownPeriod: 300000, // 5 minutes
|
|
136
|
+
});
|
|
137
|
+
// Memory usage alert
|
|
138
|
+
this.addAlertRule({
|
|
139
|
+
id: 'memory_exhaustion',
|
|
140
|
+
name: 'Memory Exhaustion Alert',
|
|
141
|
+
type: performanceTypes_1.AlertType.RESOURCE_EXHAUSTION,
|
|
142
|
+
enabled: true,
|
|
143
|
+
conditions: [
|
|
144
|
+
{
|
|
145
|
+
metric: 'memoryUsage',
|
|
146
|
+
operator: 'gt',
|
|
147
|
+
value: 0.9, // 90% memory usage
|
|
148
|
+
timeWindow: 60000, // 1 minute
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
actions: [
|
|
152
|
+
{
|
|
153
|
+
type: 'log',
|
|
154
|
+
config: { severity: 'critical' },
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
threshold: 0.9,
|
|
158
|
+
cooldownPeriod: 300000, // 5 minutes
|
|
159
|
+
});
|
|
160
|
+
// Cost threshold alert
|
|
161
|
+
this.addAlertRule({
|
|
162
|
+
id: 'daily_cost_threshold',
|
|
163
|
+
name: 'Daily Cost Threshold Alert',
|
|
164
|
+
type: performanceTypes_1.AlertType.COST_THRESHOLD,
|
|
165
|
+
enabled: true,
|
|
166
|
+
conditions: [
|
|
167
|
+
{
|
|
168
|
+
metric: 'dailyCost',
|
|
169
|
+
operator: 'gt',
|
|
170
|
+
value: 50.0, // $50 daily limit
|
|
171
|
+
timeWindow: 86400000, // 24 hours
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
actions: [
|
|
175
|
+
{
|
|
176
|
+
type: 'log',
|
|
177
|
+
config: { severity: 'medium' },
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
threshold: 50.0,
|
|
181
|
+
cooldownPeriod: 3600000, // 1 hour
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Add or update an alert rule
|
|
186
|
+
*/
|
|
187
|
+
addAlertRule(rule) {
|
|
188
|
+
this.alertRules.set(rule.id, rule);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Remove an alert rule
|
|
192
|
+
*/
|
|
193
|
+
removeAlertRule(ruleId) {
|
|
194
|
+
return this.alertRules.delete(ruleId);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get alert rule by ID
|
|
198
|
+
*/
|
|
199
|
+
getAlertRule(ruleId) {
|
|
200
|
+
return this.alertRules.get(ruleId);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get all alert rules
|
|
204
|
+
*/
|
|
205
|
+
getAllAlertRules() {
|
|
206
|
+
return Array.from(this.alertRules.values());
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Enable or disable an alert rule
|
|
210
|
+
*/
|
|
211
|
+
setAlertRuleEnabled(ruleId, enabled) {
|
|
212
|
+
const rule = this.alertRules.get(ruleId);
|
|
213
|
+
if (rule) {
|
|
214
|
+
rule.enabled = enabled;
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Add notification handler
|
|
221
|
+
*/
|
|
222
|
+
addNotificationHandler(name, handler) {
|
|
223
|
+
this.notificationHandlers.set(name, handler);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Add webhook notification handler
|
|
227
|
+
*/
|
|
228
|
+
addWebhookHandler(name, webhookUrl) {
|
|
229
|
+
this.notificationHandlers.set(name, new WebhookAlertHandler(webhookUrl));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Check alerts against current metrics
|
|
233
|
+
*/
|
|
234
|
+
async checkAlerts(metrics) {
|
|
235
|
+
const triggeredAlerts = [];
|
|
236
|
+
for (const [ruleId, rule] of this.alertRules) {
|
|
237
|
+
if (!rule.enabled) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
// Check cooldown period
|
|
241
|
+
const lastTriggered = this.cooldownTracking.get(ruleId);
|
|
242
|
+
if (lastTriggered && Date.now() - lastTriggered < rule.cooldownPeriod) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const evaluation = await this.evaluateAlertRule(rule, metrics);
|
|
246
|
+
if (evaluation.triggered) {
|
|
247
|
+
const alert = this.createAlertEvent(rule, evaluation, metrics);
|
|
248
|
+
triggeredAlerts.push(alert);
|
|
249
|
+
await this.processAlert(alert);
|
|
250
|
+
// Update cooldown tracking
|
|
251
|
+
this.cooldownTracking.set(ruleId, Date.now());
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return triggeredAlerts;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Evaluate a specific alert rule against metrics
|
|
258
|
+
*/
|
|
259
|
+
async evaluateAlertRule(rule, metrics) {
|
|
260
|
+
switch (rule.type) {
|
|
261
|
+
case performanceTypes_1.AlertType.PERFORMANCE_DEGRADATION:
|
|
262
|
+
return this.evaluatePerformanceAlert(rule, metrics);
|
|
263
|
+
case performanceTypes_1.AlertType.COST_THRESHOLD:
|
|
264
|
+
return this.evaluateCostAlert(rule, metrics);
|
|
265
|
+
case performanceTypes_1.AlertType.ERROR_RATE:
|
|
266
|
+
return this.evaluateErrorRateAlert(rule, metrics);
|
|
267
|
+
case performanceTypes_1.AlertType.RESOURCE_EXHAUSTION:
|
|
268
|
+
return this.evaluateResourceAlert(rule, metrics);
|
|
269
|
+
default:
|
|
270
|
+
return { triggered: false };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Evaluate performance degradation alerts
|
|
275
|
+
*/
|
|
276
|
+
evaluatePerformanceAlert(rule, metrics) {
|
|
277
|
+
const allProcessingTimes = Object.values(metrics.processingTime).flat();
|
|
278
|
+
if (allProcessingTimes.length === 0) {
|
|
279
|
+
return { triggered: false };
|
|
280
|
+
}
|
|
281
|
+
const averageProcessingTime = allProcessingTimes.reduce((sum, time) => sum + time, 0) / allProcessingTimes.length;
|
|
282
|
+
for (const condition of rule.conditions) {
|
|
283
|
+
if (condition.metric === 'averageProcessingTime') {
|
|
284
|
+
const triggered = this.evaluateCondition(condition, averageProcessingTime);
|
|
285
|
+
if (triggered) {
|
|
286
|
+
return {
|
|
287
|
+
triggered: true,
|
|
288
|
+
reason: `Average processing time ${averageProcessingTime}ms exceeds threshold ${condition.value}ms`,
|
|
289
|
+
metric: condition.metric,
|
|
290
|
+
actualValue: averageProcessingTime,
|
|
291
|
+
threshold: condition.value,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return { triggered: false };
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Evaluate cost threshold alerts
|
|
300
|
+
*/
|
|
301
|
+
evaluateCostAlert(rule, metrics) {
|
|
302
|
+
for (const condition of rule.conditions) {
|
|
303
|
+
if (condition.metric === 'dailyCost' || condition.metric === 'totalCost') {
|
|
304
|
+
const triggered = this.evaluateCondition(condition, metrics.totalCost);
|
|
305
|
+
if (triggered) {
|
|
306
|
+
return {
|
|
307
|
+
triggered: true,
|
|
308
|
+
reason: `Total cost $${metrics.totalCost.toFixed(2)} exceeds threshold $${condition.value.toFixed(2)}`,
|
|
309
|
+
metric: condition.metric,
|
|
310
|
+
actualValue: metrics.totalCost,
|
|
311
|
+
threshold: condition.value,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return { triggered: false };
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Evaluate error rate alerts
|
|
320
|
+
*/
|
|
321
|
+
evaluateErrorRateAlert(rule, metrics) {
|
|
322
|
+
const totalRequests = metrics.errorCount + metrics.successCount;
|
|
323
|
+
const errorRate = totalRequests > 0 ? metrics.errorCount / totalRequests : 0;
|
|
324
|
+
for (const condition of rule.conditions) {
|
|
325
|
+
if (condition.metric === 'errorRate') {
|
|
326
|
+
const triggered = this.evaluateCondition(condition, errorRate);
|
|
327
|
+
if (triggered) {
|
|
328
|
+
return {
|
|
329
|
+
triggered: true,
|
|
330
|
+
reason: `Error rate ${(errorRate * 100).toFixed(2)}% exceeds threshold ${(condition.value * 100).toFixed(2)}%`,
|
|
331
|
+
metric: condition.metric,
|
|
332
|
+
actualValue: errorRate,
|
|
333
|
+
threshold: condition.value,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return { triggered: false };
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Evaluate resource exhaustion alerts
|
|
342
|
+
*/
|
|
343
|
+
evaluateResourceAlert(rule, metrics) {
|
|
344
|
+
for (const condition of rule.conditions) {
|
|
345
|
+
if (condition.metric === 'memoryUsage') {
|
|
346
|
+
const memoryUsageRatio = metrics.memoryUsage.heapTotal > 0
|
|
347
|
+
? metrics.memoryUsage.heapUsed / metrics.memoryUsage.heapTotal
|
|
348
|
+
: 0;
|
|
349
|
+
const triggered = this.evaluateCondition(condition, memoryUsageRatio);
|
|
350
|
+
if (triggered) {
|
|
351
|
+
return {
|
|
352
|
+
triggered: true,
|
|
353
|
+
reason: `Memory usage ${(memoryUsageRatio * 100).toFixed(2)}% exceeds threshold ${(condition.value * 100).toFixed(2)}%`,
|
|
354
|
+
metric: condition.metric,
|
|
355
|
+
actualValue: memoryUsageRatio,
|
|
356
|
+
threshold: condition.value,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return { triggered: false };
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Evaluate a specific condition
|
|
365
|
+
*/
|
|
366
|
+
evaluateCondition(condition, actualValue) {
|
|
367
|
+
switch (condition.operator) {
|
|
368
|
+
case 'gt':
|
|
369
|
+
return actualValue > condition.value;
|
|
370
|
+
case 'gte':
|
|
371
|
+
return actualValue >= condition.value;
|
|
372
|
+
case 'lt':
|
|
373
|
+
return actualValue < condition.value;
|
|
374
|
+
case 'lte':
|
|
375
|
+
return actualValue <= condition.value;
|
|
376
|
+
case 'eq':
|
|
377
|
+
return actualValue === condition.value;
|
|
378
|
+
default:
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Create alert event from rule and evaluation
|
|
384
|
+
*/
|
|
385
|
+
createAlertEvent(rule, evaluation, metrics) {
|
|
386
|
+
const severity = this.calculateSeverity(rule, evaluation);
|
|
387
|
+
return {
|
|
388
|
+
id: `alert_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
389
|
+
ruleId: rule.id,
|
|
390
|
+
timestamp: Date.now(),
|
|
391
|
+
severity,
|
|
392
|
+
message: evaluation.reason || `Alert triggered for rule: ${rule.name}`,
|
|
393
|
+
context: {
|
|
394
|
+
ruleName: rule.name,
|
|
395
|
+
ruleType: rule.type,
|
|
396
|
+
metric: evaluation.metric,
|
|
397
|
+
actualValue: evaluation.actualValue,
|
|
398
|
+
threshold: evaluation.threshold,
|
|
399
|
+
currentMetrics: {
|
|
400
|
+
activeRequests: metrics.activeRequests,
|
|
401
|
+
errorCount: metrics.errorCount,
|
|
402
|
+
successCount: metrics.successCount,
|
|
403
|
+
totalCost: metrics.totalCost,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
resolved: false,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Calculate alert severity based on how much the threshold is exceeded
|
|
411
|
+
*/
|
|
412
|
+
calculateSeverity(rule, evaluation) {
|
|
413
|
+
if (!evaluation.actualValue || !evaluation.threshold) {
|
|
414
|
+
return 'medium';
|
|
415
|
+
}
|
|
416
|
+
const ratio = evaluation.actualValue / evaluation.threshold;
|
|
417
|
+
// Special handling for resource exhaustion (memory usage)
|
|
418
|
+
if (rule.type === performanceTypes_1.AlertType.RESOURCE_EXHAUSTION && ratio > 1.05) {
|
|
419
|
+
return 'critical'; // Memory exhaustion is always critical if exceeded
|
|
420
|
+
}
|
|
421
|
+
// Standard severity calculation
|
|
422
|
+
if (ratio > 1.8) {
|
|
423
|
+
return 'critical';
|
|
424
|
+
}
|
|
425
|
+
if (ratio > 1.4) {
|
|
426
|
+
return 'high';
|
|
427
|
+
}
|
|
428
|
+
if (ratio > 1.1) {
|
|
429
|
+
return 'medium';
|
|
430
|
+
}
|
|
431
|
+
return 'low';
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Process triggered alert by sending notifications
|
|
435
|
+
*/
|
|
436
|
+
async processAlert(alert) {
|
|
437
|
+
// Add to history
|
|
438
|
+
this.alertHistory.push(alert);
|
|
439
|
+
this.maintainHistoryLimit();
|
|
440
|
+
// Get the rule to determine which actions to take
|
|
441
|
+
const rule = this.alertRules.get(alert.ruleId);
|
|
442
|
+
if (!rule) {
|
|
443
|
+
console.error(`Alert rule not found for alert: ${alert.ruleId}`);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
// Execute alert actions
|
|
447
|
+
const notifications = rule.actions.map(async (action) => {
|
|
448
|
+
try {
|
|
449
|
+
const handler = this.notificationHandlers.get(action.type);
|
|
450
|
+
if (handler?.isHealthy()) {
|
|
451
|
+
await handler.sendAlert(alert);
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
console.error(`Alert handler '${action.type}' not available or unhealthy`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
console.error(`Failed to send alert via ${action.type}:`, error);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
await Promise.allSettled(notifications);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Get alert history
|
|
465
|
+
*/
|
|
466
|
+
getAlertHistory(limit) {
|
|
467
|
+
const history = [...this.alertHistory].sort((a, b) => b.timestamp - a.timestamp);
|
|
468
|
+
return limit ? history.slice(0, limit) : history;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Get active alerts (unresolved)
|
|
472
|
+
*/
|
|
473
|
+
getActiveAlerts() {
|
|
474
|
+
return this.alertHistory.filter((alert) => !alert.resolved);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Resolve an alert
|
|
478
|
+
*/
|
|
479
|
+
resolveAlert(alertId) {
|
|
480
|
+
const alert = this.alertHistory.find((a) => a.id === alertId);
|
|
481
|
+
if (alert && !alert.resolved) {
|
|
482
|
+
alert.resolved = true;
|
|
483
|
+
alert.resolvedAt = Date.now();
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Get alert statistics
|
|
490
|
+
*/
|
|
491
|
+
getAlertStatistics() {
|
|
492
|
+
const alertsByRule = {};
|
|
493
|
+
const alertsBySeverity = {};
|
|
494
|
+
for (const alert of this.alertHistory) {
|
|
495
|
+
alertsByRule[alert.ruleId] = (alertsByRule[alert.ruleId] || 0) + 1;
|
|
496
|
+
alertsBySeverity[alert.severity] = (alertsBySeverity[alert.severity] || 0) + 1;
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
totalAlerts: this.alertHistory.length,
|
|
500
|
+
activeAlerts: this.getActiveAlerts().length,
|
|
501
|
+
alertsByRule,
|
|
502
|
+
alertsBySeverity,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Update alert rule threshold dynamically
|
|
507
|
+
*/
|
|
508
|
+
updateAlertThreshold(ruleId, newThreshold) {
|
|
509
|
+
const rule = this.alertRules.get(ruleId);
|
|
510
|
+
if (rule) {
|
|
511
|
+
rule.threshold = newThreshold;
|
|
512
|
+
// Update conditions that use this threshold
|
|
513
|
+
for (const condition of rule.conditions) {
|
|
514
|
+
condition.value = newThreshold;
|
|
515
|
+
}
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Maintain alert history size limit
|
|
522
|
+
*/
|
|
523
|
+
maintainHistoryLimit() {
|
|
524
|
+
if (this.alertHistory.length > this.maxHistorySize) {
|
|
525
|
+
this.alertHistory = this.alertHistory.slice(-this.maxHistorySize / 2);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Get health status of all notification handlers
|
|
530
|
+
*/
|
|
531
|
+
getNotificationHandlerStatus() {
|
|
532
|
+
const status = {};
|
|
533
|
+
for (const [name, handler] of this.notificationHandlers) {
|
|
534
|
+
status[name] = handler.isHealthy();
|
|
535
|
+
}
|
|
536
|
+
return status;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Clean up resources
|
|
540
|
+
*/
|
|
541
|
+
destroy() {
|
|
542
|
+
this.alertRules.clear();
|
|
543
|
+
this.alertHistory = [];
|
|
544
|
+
this.notificationHandlers.clear();
|
|
545
|
+
this.cooldownTracking.clear();
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
exports.AlertingSystem = AlertingSystem;
|
|
549
|
+
//# sourceMappingURL=alertingSystem.js.map
|