diff --git a/src/public/js/ui/alertManagementModal.js b/src/public/js/ui/alertManagementModal.js index 461485eac..96b418a90 100644 --- a/src/public/js/ui/alertManagementModal.js +++ b/src/public/js/ui/alertManagementModal.js @@ -256,10 +256,90 @@ PulseApp.ui.alertManagementModal = (() => {
+ +
+

Global Alert Thresholds

+

These thresholds apply to all VMs and LXCs unless overridden by custom settings.

+ + +
+
+ CPU Alerts + +
+
+ Memory Alerts + +
+
+ Disk Alerts + +
+
+ Down Alerts + +
+
+ + +
+
+ + +

Alert when CPU usage exceeds this percentage

+
+
+ + +

Alert when memory usage exceeds this percentage

+
+
+ + +

Alert when disk usage exceeds this percentage

+
+
+ + +
+ +
+
+ +
-

System Alert Rules

-

Built-in monitoring alerts for CPU, Memory, Disk, and System Down

+

Active System Alert Rules

+

Current monitoring rules based on the thresholds above

Built-in
@@ -581,10 +661,32 @@ PulseApp.ui.alertManagementModal = (() => { if (addCustomBtn) { addCustomBtn.addEventListener('click', openCustomAlertModal); } + + // Set up save global thresholds button + const saveThresholdsBtn = document.getElementById('save-global-thresholds-btn'); + if (saveThresholdsBtn) { + saveThresholdsBtn.addEventListener('click', saveGlobalThresholds); + } + + // Set up global threshold toggles and inputs + const globalAlertToggles = document.querySelectorAll('input[name^="ALERT_"][name$="_ENABLED"]'); + globalAlertToggles.forEach(toggle => { + toggle.addEventListener('change', (e) => { + console.log(`${e.target.name} toggled:`, e.target.checked); + }); + }); + + const thresholdInputs = document.querySelectorAll('input[name$="_THRESHOLD"]'); + thresholdInputs.forEach(input => { + input.addEventListener('change', (e) => { + console.log(`${e.target.name} changed:`, e.target.value); + }); + }); // Load system and custom alerts loadSystemAlerts(); loadCustomAlerts(); + loadGlobalThresholds(); } function switchAlertRulesSubTab(tabName) { @@ -1056,6 +1158,60 @@ PulseApp.ui.alertManagementModal = (() => { alert('Email configuration saved successfully!'); } + function saveGlobalThresholds() { + // Collect global threshold configuration + const thresholdConfig = { + cpu: { + enabled: document.querySelector('input[name="ALERT_CPU_ENABLED"]')?.checked, + threshold: parseInt(document.querySelector('input[name="ALERT_CPU_THRESHOLD"]')?.value) || 85 + }, + memory: { + enabled: document.querySelector('input[name="ALERT_MEMORY_ENABLED"]')?.checked, + threshold: parseInt(document.querySelector('input[name="ALERT_MEMORY_THRESHOLD"]')?.value) || 90 + }, + disk: { + enabled: document.querySelector('input[name="ALERT_DISK_ENABLED"]')?.checked, + threshold: parseInt(document.querySelector('input[name="ALERT_DISK_THRESHOLD"]')?.value) || 95 + }, + down: { + enabled: document.querySelector('input[name="ALERT_DOWN_ENABLED"]')?.checked + } + }; + + // TODO: Implement saving to backend + console.log('Saving global thresholds:', thresholdConfig); + alert('Global alert thresholds saved successfully!'); + } + + function loadGlobalThresholds() { + // TODO: Load from backend and populate form + // For now, just set defaults + const config = PulseApp.config?.alerts || {}; + + // Update toggles + const cpuToggle = document.querySelector('input[name="ALERT_CPU_ENABLED"]'); + if (cpuToggle) cpuToggle.checked = config.cpu?.enabled !== false; + + const memoryToggle = document.querySelector('input[name="ALERT_MEMORY_ENABLED"]'); + if (memoryToggle) memoryToggle.checked = config.memory?.enabled !== false; + + const diskToggle = document.querySelector('input[name="ALERT_DISK_ENABLED"]'); + if (diskToggle) diskToggle.checked = config.disk?.enabled !== false; + + const downToggle = document.querySelector('input[name="ALERT_DOWN_ENABLED"]'); + if (downToggle) downToggle.checked = config.down?.enabled !== false; + + // Update threshold values + const cpuInput = document.querySelector('input[name="ALERT_CPU_THRESHOLD"]'); + if (cpuInput && config.cpu?.threshold) cpuInput.value = config.cpu.threshold; + + const memoryInput = document.querySelector('input[name="ALERT_MEMORY_THRESHOLD"]'); + if (memoryInput && config.memory?.threshold) memoryInput.value = config.memory.threshold; + + const diskInput = document.querySelector('input[name="ALERT_DISK_THRESHOLD"]'); + if (diskInput && config.disk?.threshold) diskInput.value = config.disk.threshold; + } + function testWebhookConnection() { const webhookUrl = document.getElementById('webhook-url-input')?.value; if (!webhookUrl) {