feat: Add error message and details columns

Adds error_message and details columns to the Incident History table in the service detail page.
This commit is contained in:
Tola Leng
2025-06-20 20:13:18 +07:00
parent 458f5f7d82
commit 918a248b8f
8 changed files with 116 additions and 28 deletions
@@ -13,7 +13,8 @@ export async function handleServiceUp(service: any, responseTime: number, format
// Create a history record of this check with a more accurate timestamp
const uptimeData: UptimeData = {
serviceId: service.id,
service_id: service.id, // Include service_id
serviceId: service.id, // Keep for backward compatibility
timestamp: new Date().toISOString(),
status: "up",
responseTime: responseTime,
@@ -92,7 +93,8 @@ export async function handleServiceDown(service: any, formattedTime: string): Pr
// Create a history record of this check
const uptimeData: UptimeData = {
serviceId: service.id,
service_id: service.id, // Include service_id
serviceId: service.id, // Keep for backward compatibility
timestamp: new Date().toISOString(),
status: "down",
responseTime: 0,
@@ -161,4 +163,4 @@ export async function handleServiceDown(service: any, formattedTime: string): Pr
} catch (error) {
console.error("Error handling service DOWN state:", error);
}
}
}
@@ -37,6 +37,7 @@ export async function resumeMonitoring(serviceId: string): Promise<void> {
id: service.id,
name: service.name,
url: service.url || "",
host: service.host || "", // Include host property
type: service.service_type || service.type || "HTTP",
status: "up",
responseTime: service.response_time || 0,
@@ -77,4 +78,4 @@ export async function resumeMonitoring(serviceId: string): Promise<void> {
} catch (error) {
console.error("Error resuming service:", error);
}
}
}
@@ -19,6 +19,7 @@ export function prepareServiceForNotification(pbRecord: any, status: string, res
id: pbRecord.id,
name: pbRecord.name,
url: pbRecord.url,
host: pbRecord.host || "", // Include host property with fallback
type: pbRecord.type || pbRecord.service_type || "HTTP",
status: status as any,
responseTime: responseTime,
+10 -6
View File
@@ -31,22 +31,23 @@ const getCollectionForServiceType = (serviceType: string): string => {
export const uptimeService = {
async recordUptimeData(data: UptimeData): Promise<void> {
try {
console.log(`Recording uptime data for service ${data.serviceId}: Status ${data.status}, Response time: ${data.responseTime}ms`);
console.log(`Recording uptime data for service ${data.serviceId || data.service_id}: Status ${data.status}, Response time: ${data.responseTime}ms`);
const options = {
$autoCancel: false,
$cancelKey: `uptime_record_${data.serviceId}_${Date.now()}`
$cancelKey: `uptime_record_${data.serviceId || data.service_id}_${Date.now()}`
};
const record = await pb.collection('uptime_data').create({
service_id: data.serviceId,
service_id: data.service_id || data.serviceId,
timestamp: data.timestamp,
status: data.status,
response_time: data.responseTime
}, options);
// Invalidate cache for this service
const keysToDelete = Array.from(uptimeCache.keys()).filter(key => key.includes(`uptime_${data.serviceId}`));
const serviceId = data.service_id || data.serviceId;
const keysToDelete = Array.from(uptimeCache.keys()).filter(key => key.includes(`uptime_${serviceId}`));
keysToDelete.forEach(key => uptimeCache.delete(key));
console.log(`Uptime data recorded successfully with ID: ${record.id}`);
@@ -116,12 +117,15 @@ export const uptimeService = {
// Transform the response items to UptimeData format
const uptimeData = response.items.map(item => ({
id: item.id,
serviceId: item.service_id,
service_id: item.service_id, // Include service_id
serviceId: item.service_id, // Keep for backward compatibility
timestamp: item.timestamp,
status: item.status as "up" | "down" | "warning" | "paused",
responseTime: item.response_time || 0,
date: item.timestamp,
uptime: 100
uptime: 100,
error_message: item.error_message,
details: item.details
}));
// Cache the result