feat: Add check interval and check_at update

- Added a "Check Interval" field to the SSL certificate create/edit forms.
- Implemented functionality to update the `check_at` field in Pocketbase with the current time when the "Check" button is clicked.
This commit is contained in:
Tola Leng
2025-06-20 17:17:34 +07:00
parent 11408dcba0
commit 614c10188d
10 changed files with 390 additions and 357 deletions
+2 -1
View File
@@ -13,7 +13,8 @@ export {
addSSLCertificate,
checkAndUpdateCertificate,
deleteSSLCertificate,
refreshAllCertificates
refreshAllCertificates,
triggerImmediateCheck
} from './sslCertificateOperations';
// SSL-specific notification service
@@ -30,6 +30,7 @@ export const addSSLCertificate = async (
warning_threshold: Number(certificateData.warning_threshold) || 30,
expiry_threshold: Number(certificateData.expiry_threshold) || 7,
notification_channel: certificateData.notification_channel || "",
check_interval: Number(certificateData.check_interval) || 1, // New field
};
// Save to database
@@ -71,6 +72,27 @@ export const checkAndUpdateCertificate = async (
}
};
/**
* Trigger immediate SSL check by setting check_at to current time
*/
export const triggerImmediateCheck = async (certificateId: string): Promise<void> => {
try {
const currentTime = new Date().toISOString();
// Update the check_at field to current time to trigger immediate check by Go service
await pb.collection("ssl_certificates").update(certificateId, {
check_at: currentTime
});
console.log(`Triggered immediate check for certificate ${certificateId} at ${currentTime}`);
toast.success("SSL check scheduled - certificate will be checked shortly");
} catch (error) {
console.error("Error triggering immediate SSL check:", error);
toast.error("Failed to schedule SSL check");
throw error;
}
};
/**
* Delete an SSL certificate from monitoring
*/
+9 -1
View File
@@ -1,10 +1,10 @@
// SSL Certificate DTO for adding new certificates
export interface AddSSLCertificateDto {
domain: string;
warning_threshold: number;
expiry_threshold: number;
notification_channel: string;
check_interval?: number; // New field for check interval in days
}
// SSL Certificate model
@@ -28,6 +28,14 @@ export interface SSLCertificate {
last_notified?: string;
created?: string;
updated?: string;
// New fields
check_interval?: number; // Check interval in days
check_at?: string; // Next check time
// Existing fields based on the provided structure
collectionId?: string;
collectionName?: string;
resolved_ip?: string;
issuer_cn?: string;
}
// SSL specific notification types
@@ -3,7 +3,9 @@
import {
fetchSSLCertificates,
addSSLCertificate,
checkAndUpdateCertificate
checkAndUpdateCertificate,
triggerImmediateCheck,
deleteSSLCertificate
} from './ssl';
import { determineSSLStatus } from './ssl/sslStatusUtils';
@@ -20,6 +22,8 @@ export {
fetchSSLCertificates,
addSSLCertificate,
checkAndUpdateCertificate,
triggerImmediateCheck,
deleteSSLCertificate,
checkAllCertificatesAndNotify,
checkCertificateAndNotify,
shouldRunDailyCheck