|
|
|
@ -9,6 +9,8 @@ let currentHistoryRetentionDays = 30;
|
|
|
|
let historyIntervalId = null;
|
|
|
|
let historyIntervalId = null;
|
|
|
|
let dashboardUpdateInProgress = false;
|
|
|
|
let dashboardUpdateInProgress = false;
|
|
|
|
let alarmControlsInitialized = false;
|
|
|
|
let alarmControlsInitialized = false;
|
|
|
|
|
|
|
|
let notificationConfigLoaded = false;
|
|
|
|
|
|
|
|
let telegramTokenConfigured = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Diccionario para traducir estados en la UI sin romper las clases CSS
|
|
|
|
// Diccionario para traducir estados en la UI sin romper las clases CSS
|
|
|
|
const stateTranslations = {
|
|
|
|
const stateTranslations = {
|
|
|
|
@ -319,6 +321,72 @@ async function readRuntimeConfig() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function loadNotificationConfig() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const response = await fetch('/api/config/notifications', { cache: 'no-store' });
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok || !result.config) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const config = result.config;
|
|
|
|
|
|
|
|
telegramTokenConfigured = config.channels.telegram.botToken === "[configured]";
|
|
|
|
|
|
|
|
document.getElementById("notifications-enabled").checked = config.enabled === true;
|
|
|
|
|
|
|
|
document.getElementById("notification-min-severity").value = config.minSeverity || "CRITICAL";
|
|
|
|
|
|
|
|
document.getElementById("webhook-enabled").checked = config.channels.webhook.enabled === true;
|
|
|
|
|
|
|
|
document.getElementById("webhook-url").value = config.channels.webhook.url || "";
|
|
|
|
|
|
|
|
document.getElementById("telegram-enabled").checked = config.channels.telegram.enabled === true;
|
|
|
|
|
|
|
|
document.getElementById("telegram-chat-id").value = config.channels.telegram.chatId || "";
|
|
|
|
|
|
|
|
document.getElementById("telegram-bot-token").placeholder = telegramTokenConfigured
|
|
|
|
|
|
|
|
? "Token configurado"
|
|
|
|
|
|
|
|
: "Bot token";
|
|
|
|
|
|
|
|
notificationConfigLoaded = true;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.warn("No se pudo cargar la configuracion de notificaciones:", error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.saveNotificationConfig = async function () {
|
|
|
|
|
|
|
|
const botTokenInput = document.getElementById("telegram-bot-token");
|
|
|
|
|
|
|
|
const botToken = botTokenInput.value.trim();
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
|
|
|
|
enabled: document.getElementById("notifications-enabled").checked,
|
|
|
|
|
|
|
|
minSeverity: document.getElementById("notification-min-severity").value,
|
|
|
|
|
|
|
|
channels: {
|
|
|
|
|
|
|
|
webhook: {
|
|
|
|
|
|
|
|
enabled: document.getElementById("webhook-enabled").checked,
|
|
|
|
|
|
|
|
url: document.getElementById("webhook-url").value.trim(),
|
|
|
|
|
|
|
|
headers: {}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
telegram: {
|
|
|
|
|
|
|
|
enabled: document.getElementById("telegram-enabled").checked,
|
|
|
|
|
|
|
|
botToken: botToken || (telegramTokenConfigured ? "__KEEP__" : ""),
|
|
|
|
|
|
|
|
chatId: document.getElementById("telegram-chat-id").value.trim()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const response = await fetch('/api/config/notifications', {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
headers: getApiHeaders({ 'Content-Type': 'application/json' }),
|
|
|
|
|
|
|
|
body: JSON.stringify({ config })
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
|
|
throw new Error(result.error || "No se pudo guardar notificaciones.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
botTokenInput.value = "";
|
|
|
|
|
|
|
|
notificationConfigLoaded = false;
|
|
|
|
|
|
|
|
await loadNotificationConfig();
|
|
|
|
|
|
|
|
alert("Configuracion de notificaciones actualizada.");
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error("Error guardando notificaciones:", error);
|
|
|
|
|
|
|
|
alert(error.message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
async function readAlarmConfig() {
|
|
|
|
async function readAlarmConfig() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const response = await fetch('/api/config/alarms', {
|
|
|
|
const response = await fetch('/api/config/alarms', {
|
|
|
|
@ -854,6 +922,7 @@ updateDashboard();
|
|
|
|
setInterval(updateDashboard, POLLING_INTERVAL_MS);
|
|
|
|
setInterval(updateDashboard, POLLING_INTERVAL_MS);
|
|
|
|
updateHistoricalTrends();
|
|
|
|
updateHistoricalTrends();
|
|
|
|
startHistoryPolling();
|
|
|
|
startHistoryPolling();
|
|
|
|
|
|
|
|
loadNotificationConfig();
|
|
|
|
|
|
|
|
|
|
|
|
// --- FUNCIONES DE CONTROL DE ALMACENAMIENTO ---
|
|
|
|
// --- FUNCIONES DE CONTROL DE ALMACENAMIENTO ---
|
|
|
|
|
|
|
|
|
|
|
|
|