Disable debug console logs for production

This commit is contained in:
Tola Leng
2025-07-14 15:45:05 +07:00
parent 0941250867
commit cb258d72c3
12 changed files with 88 additions and 88 deletions
+20 -20
View File
@@ -7,7 +7,7 @@ export const serverService = {
const records = await pb.collection('servers').getFullList<Server>();
return records;
} catch (error) {
console.error('Error fetching servers:', error);
// console.error('Error fetching servers:', error);
throw error;
}
},
@@ -17,22 +17,22 @@ export const serverService = {
const record = await pb.collection('servers').getOne<Server>(serverId);
return record;
} catch (error) {
console.error('Error fetching server:', error);
// console.error('Error fetching server:', error);
throw error;
}
},
async getServerMetrics(serverId: string, timeRange?: string): Promise<any[]> {
try {
console.log('serverService.getServerMetrics: Fetching metrics for serverId:', serverId, 'timeRange:', timeRange);
// console.log('serverService.getServerMetrics: Fetching metrics for serverId:', serverId, 'timeRange:', timeRange);
// First, get the server to find the correct server_id for metrics
let server;
try {
server = await this.getServer(serverId);
console.log('serverService.getServerMetrics: Found server:', server);
// console.log('serverService.getServerMetrics: Found server:', server);
} catch (error) {
console.log('serverService.getServerMetrics: Could not fetch server details:', error);
// console.log('serverService.getServerMetrics: Could not fetch server details:', error);
}
// Try multiple filter strategies to find data
@@ -43,17 +43,17 @@ export const serverService = {
if (server && server.server_id) {
metricsServerId = server.server_id;
filter = `server_id = "${metricsServerId}"`;
console.log('serverService.getServerMetrics: Strategy 1 - Using server.server_id for metrics:', metricsServerId);
// console.log('serverService.getServerMetrics: Strategy 1 - Using server.server_id for metrics:', metricsServerId);
} else {
// Strategy 2: Use the serverId directly
filter = `server_id = "${serverId}"`;
console.log('serverService.getServerMetrics: Strategy 2 - Using serverId directly for metrics:', serverId);
// console.log('serverService.getServerMetrics: Strategy 2 - Using serverId directly for metrics:', serverId);
}
// Add agent_id filter if available in server data
if (server && server.agent_id) {
filter += ` && agent_id = "${server.agent_id}"`;
console.log('serverService.getServerMetrics: Added agent_id filter:', server.agent_id);
// console.log('serverService.getServerMetrics: Added agent_id filter:', server.agent_id);
}
// Add time range filter
@@ -83,10 +83,10 @@ export const serverService = {
const cutoffISO = cutoffTime.toISOString();
filter += ` && created >= "${cutoffISO}"`;
console.log('serverService.getServerMetrics: Using time filter from:', cutoffISO, 'to now');
// console.log('serverService.getServerMetrics: Using time filter from:', cutoffISO, 'to now');
}
console.log('serverService.getServerMetrics: Final filter:', filter);
// console.log('serverService.getServerMetrics: Final filter:', filter);
// Fetch filtered records with proper sorting
let records = await pb.collection('server_metrics').getFullList({
@@ -95,11 +95,11 @@ export const serverService = {
requestKey: null
});
console.log('serverService.getServerMetrics: Found', records.length, 'records with primary filter');
// console.log('serverService.getServerMetrics: Found', records.length, 'records with primary filter');
// If no records found with primary strategy, try fallback strategies
if (records.length === 0) {
console.log('serverService.getServerMetrics: No records found, trying fallback strategies...');
// console.log('serverService.getServerMetrics: No records found, trying fallback strategies...');
// Fallback 1: Try without agent_id filter
let fallbackFilter = `server_id = "${metricsServerId}"`;
@@ -131,19 +131,19 @@ export const serverService = {
fallbackFilter += ` && created >= "${cutoffISO}"`;
}
console.log('serverService.getServerMetrics: Trying fallback filter without agent_id:', fallbackFilter);
// console.log('serverService.getServerMetrics: Trying fallback filter without agent_id:', fallbackFilter);
records = await pb.collection('server_metrics').getFullList({
filter: fallbackFilter,
sort: '-created',
requestKey: null
});
console.log('serverService.getServerMetrics: Fallback found', records.length, 'records');
// console.log('serverService.getServerMetrics: Fallback found', records.length, 'records');
// Fallback 2: Try with different server_id strategies
if (records.length === 0) {
const alternativeIds = [serverId, server?.server_id, server?.id].filter(Boolean);
console.log('serverService.getServerMetrics: Trying alternative server IDs:', alternativeIds);
// console.log('serverService.getServerMetrics: Trying alternative server IDs:', alternativeIds);
for (const altId of alternativeIds) {
if (altId && altId !== metricsServerId) {
@@ -176,7 +176,7 @@ export const serverService = {
altFilter += ` && created >= "${cutoffISO}"`;
}
console.log('serverService.getServerMetrics: Trying alternative ID filter:', altFilter);
// console.log('serverService.getServerMetrics: Trying alternative ID filter:', altFilter);
const altRecords = await pb.collection('server_metrics').getFullList({
filter: altFilter,
sort: '-created',
@@ -184,7 +184,7 @@ export const serverService = {
});
if (altRecords.length > 0) {
console.log('serverService.getServerMetrics: Alternative ID found', altRecords.length, 'records');
// console.log('serverService.getServerMetrics: Alternative ID found', altRecords.length, 'records');
records = altRecords;
break;
}
@@ -193,14 +193,14 @@ export const serverService = {
}
}
console.log('serverService.getServerMetrics: Final result:', records.length, 'records found');
// console.log('serverService.getServerMetrics: Final result:', records.length, 'records found');
if (records.length > 0) {
console.log('serverService.getServerMetrics: Sample record:', records[0]);
// console.log('serverService.getServerMetrics: Sample record:', records[0]);
}
return records;
} catch (error) {
console.error('Error fetching server metrics:', error);
// console.error('Error fetching server metrics:', error);
throw error;
}
},
@@ -10,7 +10,7 @@ import { toast } from "sonner";
* This should be called once per day
*/
export async function checkAllCertificatesAndNotify(): Promise<void> {
console.log("Starting daily SSL certificates check...");
// console.log("Starting daily SSL certificates check...");
try {
// Fetch all SSL certificates from database
@@ -18,16 +18,16 @@ export async function checkAllCertificatesAndNotify(): Promise<void> {
// Properly cast the items as SSLCertificate
const certificates = response.items as unknown as SSLCertificate[];
console.log(`Found ${certificates.length} certificates to check`);
// console.log(`Found ${certificates.length} certificates to check`);
// Check each certificate
for (const cert of certificates) {
await checkCertificateAndNotify(cert);
}
console.log("Daily SSL certificates check completed");
// console.log("Daily SSL certificates check completed");
} catch (error) {
console.error("Error during SSL certificates daily check:", error);
// console.error("Error during SSL certificates daily check:", error);
}
}
@@ -37,7 +37,7 @@ export async function checkAllCertificatesAndNotify(): Promise<void> {
* Note: SSL checking is now handled by the Go service, this function focuses on notifications
*/
export async function checkCertificateAndNotify(certificate: SSLCertificate): Promise<boolean> {
console.log(`Checking certificate for ${certificate.domain}...`);
// console.log(`Checking certificate for ${certificate.domain}...`);
try {
// Use the current certificate data (updated by Go service)
@@ -47,7 +47,7 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
const warningThreshold = Number(certificate.warning_threshold) || 30;
const expiryThreshold = Number(certificate.expiry_threshold) || 7;
console.log(`Certificate ${certificate.domain} thresholds: warning=${warningThreshold}, expiry=${expiryThreshold}, days left=${daysLeft}`);
// console.log(`Certificate ${certificate.domain} thresholds: warning=${warningThreshold}, expiry=${expiryThreshold}, days left=${daysLeft}`);
// Update status based on thresholds
const status = determineSSLStatus(daysLeft, warningThreshold, expiryThreshold);
@@ -67,7 +67,7 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
isCritical = false;
}
console.log(`${certificate.domain}: ${daysLeft} days left, status: ${status}, should notify: ${shouldNotify}, critical: ${isCritical}`);
// console.log(`${certificate.domain}: ${daysLeft} days left, status: ${status}, should notify: ${shouldNotify}, critical: ${isCritical}`);
// Update certificate status in database
await pb.collection('ssl_certificates').update(certificate.id, {
@@ -76,7 +76,7 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
// Send notification if needed
if (shouldNotify && certificate.notification_channel) {
console.log(`Sending notification for ${certificate.domain}`);
// console.log(`Sending notification for ${certificate.domain}`);
// Different message based on expiry threshold
const message = isCritical
@@ -92,28 +92,28 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
last_notified: new Date().toISOString()
});
console.log(`Notification sent for ${certificate.domain}`);
// console.log(`Notification sent for ${certificate.domain}`);
// Show toast for manual checks
toast.success(`Notification sent for ${certificate.domain}`);
return true;
} else {
console.error(`Failed to send notification for ${certificate.domain}`);
// console.error(`Failed to send notification for ${certificate.domain}`);
// Show error toast for manual checks
toast.error(`Failed to send notification for ${certificate.domain}`);
return false;
}
} else if (shouldNotify && !certificate.notification_channel) {
console.log(`No notification channel set for ${certificate.domain}, skipping notification`);
// console.log(`No notification channel set for ${certificate.domain}, skipping notification`);
toast.info(`No notification channel set for ${certificate.domain}, skipping notification`);
} else {
console.log(`No notification needed for ${certificate.domain} (${daysLeft} days left)`);
// console.log(`No notification needed for ${certificate.domain} (${daysLeft} days left)`);
// For manual checks, inform the user that thresholds weren't met
toast.info(`Certificate for ${certificate.domain} is valid (${daysLeft} days left)`);
}
return true;
} catch (error) {
console.error(`Error checking certificate for ${certificate.domain}:`, error);
// console.error(`Error checking certificate for ${certificate.domain}:`, error);
toast.error(`Error checking certificate: ${error instanceof Error ? error.message : "Unknown error"}`);
return false;
}
+14 -14
View File
@@ -8,7 +8,7 @@ export const serverService = {
const records = await pb.collection('servers').getFullList<Server>();
return records;
} catch (error) {
console.error('Error fetching servers:', error);
// console.error('Error fetching servers:', error);
throw error;
}
},
@@ -18,29 +18,29 @@ export const serverService = {
const record = await pb.collection('servers').getOne<Server>(serverId);
return record;
} catch (error) {
console.error('Error fetching server:', error);
// console.error('Error fetching server:', error);
throw error;
}
},
async getServerMetrics(serverId: string): Promise<any[]> {
try {
console.log('serverService.getServerMetrics: Fetching metrics for serverId:', serverId);
// console.log('serverService.getServerMetrics: Fetching metrics for serverId:', serverId);
// First, get the server to find the correct server_id for metrics
let server;
try {
server = await this.getServer(serverId);
console.log('serverService.getServerMetrics: Found server:', server);
// console.log('serverService.getServerMetrics: Found server:', server);
} catch (error) {
console.log('serverService.getServerMetrics: Could not fetch server details:', error);
// console.log('serverService.getServerMetrics: Could not fetch server details:', error);
}
// Try to get metrics using the server's server_id field if available
let metricsServerId = serverId;
if (server && server.server_id) {
metricsServerId = server.server_id;
console.log('serverService.getServerMetrics: Using server.server_id for metrics:', metricsServerId);
// console.log('serverService.getServerMetrics: Using server.server_id for metrics:', metricsServerId);
}
// Try filtering by server_id first
@@ -50,11 +50,11 @@ export const serverService = {
requestKey: null
});
console.log('serverService.getServerMetrics: Filtered records by server_id:', filteredRecords.length);
// console.log('serverService.getServerMetrics: Filtered records by server_id:', filteredRecords.length);
// If no records found with server_id, try alternative approaches
if (filteredRecords.length === 0) {
console.log('serverService.getServerMetrics: No records found with server_id filter, trying alternatives...');
// console.log('serverService.getServerMetrics: No records found with server_id filter, trying alternatives...');
// Get all records to see what's available
const allRecords = await pb.collection('server_metrics').getFullList({
@@ -62,24 +62,24 @@ export const serverService = {
requestKey: null
});
console.log('serverService.getServerMetrics: Total server_metrics records:', allRecords.length);
// console.log('serverService.getServerMetrics: Total server_metrics records:', allRecords.length);
if (allRecords.length > 0) {
console.log('serverService.getServerMetrics: Sample record fields:', Object.keys(allRecords[0]));
console.log('serverService.getServerMetrics: Sample server_id values:', allRecords.slice(0, 5).map(r => r.server_id));
// console.log('serverService.getServerMetrics: Sample record fields:', Object.keys(allRecords[0]));
// console.log('serverService.getServerMetrics: Sample server_id values:', allRecords.slice(0, 5).map(r => r.server_id));
}
// For now, return some sample data from available records if server matches pattern
// This is temporary until the correct server_id mapping is established
if (allRecords.length > 0) {
console.log('serverService.getServerMetrics: Using available records as fallback');
// console.log('serverService.getServerMetrics: Using available records as fallback');
filteredRecords = allRecords.slice(0, 50); // Get recent 50 records
}
}
console.log('serverService.getServerMetrics: Returning', filteredRecords.length, 'records');
// console.log('serverService.getServerMetrics: Returning', filteredRecords.length, 'records');
return filteredRecords;
} catch (error) {
console.error('Error fetching server metrics:', error);
// console.error('Error fetching server metrics:', error);
throw error;
}
},