This commit is contained in:
2025-10-06 00:56:47 -04:00
parent 6806bf5b69
commit e1786a62fb

View File

@@ -54,9 +54,14 @@ async function updateMessages() {
return;
}
console.log(`Fetching from backend: ${config.backendUrl}`);
const response = await axios.get(config.backendUrl);
const monitors = response.data;
console.log('Backend response status:', response.status);
console.log('Backend response data type:', typeof monitors);
console.log('Backend response data:', JSON.stringify(monitors).substring(0, 500) + '...');
// Check if the backend returned an error
if (monitors.error) {
console.error('Backend API error:', monitors.message);
@@ -66,6 +71,7 @@ async function updateMessages() {
// Ensure monitors is an array
if (!Array.isArray(monitors)) {
console.error('Backend returned invalid data format:', typeof monitors);
console.error('Expected array, got:', monitors);
return;
}
@@ -94,6 +100,12 @@ async function updateMessages() {
// await sendMonitorsMessage(channel, 'Infrastructure', infrastructureMonitors);
//await sendMonitorsMessage(channel, 'Network', networkMonitors);
// Send a test message if no monitors found
if (webServicesMonitors.length === 0) {
console.log('No monitors found, sending test message');
await channel.send('🔧 Bot is running but no monitors found. Check backend configuration.');
}
} catch (error) {
console.error('Error updating messages:', error);
@@ -110,6 +122,8 @@ async function updateMessages() {
}
async function sendMonitorsMessage(channel, category, monitors) {
console.log(`Processing ${category}: ${monitors.length} monitors`);
let description = monitors.map(monitor => {
let statusEmoji = '';
switch (monitor.status) {
@@ -131,9 +145,12 @@ async function sendMonitorsMessage(channel, category, monitors) {
return `${statusEmoji} | ${monitor.monitor_name}`;
}).join('\n');
console.log(`Generated description for ${category}: "${description}"`);
// Ensure description is not empty (Discord.js validation requirement)
if (!description || description.trim() === '') {
description = `No ${category.toLowerCase()} monitors found.`;
console.log(`Empty description, using fallback: "${description}"`);
}
let embed = new EmbedBuilder()