fix 2
This commit is contained in:
19
Bot/index.js
19
Bot/index.js
@@ -54,9 +54,14 @@ async function updateMessages() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Fetching from backend: ${config.backendUrl}`);
|
||||||
const response = await axios.get(config.backendUrl);
|
const response = await axios.get(config.backendUrl);
|
||||||
const monitors = response.data;
|
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
|
// Check if the backend returned an error
|
||||||
if (monitors.error) {
|
if (monitors.error) {
|
||||||
console.error('Backend API error:', monitors.message);
|
console.error('Backend API error:', monitors.message);
|
||||||
@@ -66,6 +71,7 @@ async function updateMessages() {
|
|||||||
// Ensure monitors is an array
|
// Ensure monitors is an array
|
||||||
if (!Array.isArray(monitors)) {
|
if (!Array.isArray(monitors)) {
|
||||||
console.error('Backend returned invalid data format:', typeof monitors);
|
console.error('Backend returned invalid data format:', typeof monitors);
|
||||||
|
console.error('Expected array, got:', monitors);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,8 +97,14 @@ async function updateMessages() {
|
|||||||
console.log(`Web Services: ${webServicesMonitors.length}, Infrastructure: ${infrastructureMonitors.length}, Network: ${networkMonitors.length}`);
|
console.log(`Web Services: ${webServicesMonitors.length}, Infrastructure: ${infrastructureMonitors.length}, Network: ${networkMonitors.length}`);
|
||||||
|
|
||||||
await sendMonitorsMessage(channel, 'Web Services', webServicesMonitors);
|
await sendMonitorsMessage(channel, 'Web Services', webServicesMonitors);
|
||||||
// await sendMonitorsMessage(channel, 'Infrastructure', infrastructureMonitors);
|
// await sendMonitorsMessage(channel, 'Infrastructure', infrastructureMonitors);
|
||||||
//await sendMonitorsMessage(channel, 'Network', networkMonitors);
|
//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) {
|
} catch (error) {
|
||||||
console.error('Error updating messages:', error);
|
console.error('Error updating messages:', error);
|
||||||
@@ -110,6 +122,8 @@ async function updateMessages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendMonitorsMessage(channel, category, monitors) {
|
async function sendMonitorsMessage(channel, category, monitors) {
|
||||||
|
console.log(`Processing ${category}: ${monitors.length} monitors`);
|
||||||
|
|
||||||
let description = monitors.map(monitor => {
|
let description = monitors.map(monitor => {
|
||||||
let statusEmoji = '';
|
let statusEmoji = '';
|
||||||
switch (monitor.status) {
|
switch (monitor.status) {
|
||||||
@@ -131,9 +145,12 @@ async function sendMonitorsMessage(channel, category, monitors) {
|
|||||||
return `${statusEmoji} | ${monitor.monitor_name}`;
|
return `${statusEmoji} | ${monitor.monitor_name}`;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
|
console.log(`Generated description for ${category}: "${description}"`);
|
||||||
|
|
||||||
// Ensure description is not empty (Discord.js validation requirement)
|
// Ensure description is not empty (Discord.js validation requirement)
|
||||||
if (!description || description.trim() === '') {
|
if (!description || description.trim() === '') {
|
||||||
description = `No ${category.toLowerCase()} monitors found.`;
|
description = `No ${category.toLowerCase()} monitors found.`;
|
||||||
|
console.log(`Empty description, using fallback: "${description}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let embed = new EmbedBuilder()
|
let embed = new EmbedBuilder()
|
||||||
|
|||||||
Reference in New Issue
Block a user