257718e9d6
* fix(ssl): Ensure edit form saves notification_id and template_id in DB. - The SSL edit form was not saving the `notification_id` and `template_id` fields to the PB database when re-assigning the Notification Channel and Alert Template. * chore(partners): add Cloudflare to Ecosystem & Community Partner section - Cloudflare has been added to the Ecosystem & Community Partner list to acknowledge their support and contribution. * ⏳ chore(project): update development status and progress - fix(ssl): ensure edit form saves notification_id and template_id in DB - feat(notifications): add Notifiarr notification channel (planned) * feat: Add Notifiarr to notification channels (UI) - Add Notifiarr as a new channel type in the notification settings. The Notifiarr channel will use the `api_token` field for API key storage in PB. * feat: Add channel_id field for Notifiarr - Add channel_id field for Notifiarr to store record of the discord channel_id into the PB. * feat: Implement Notifiarr notification service - The Notifiarr notification functionality has been implemented. The alert configuration channel will now use the `api_token` and `channel_id` field for send to the Notifiarr API endpoint. * ⏳ chore(project): update development status and progress - feat: Add channel_id field for Notifiarr - feat: Implement Notifiarr notification service Closes: #133 * feat: add SSL history and Notifiarr notification channel schema * Fix: Remove duplicate close button - Removed the duplicate close button from the test email dialog. * feat: Add Gotify to notification channels - Add Gotify as a new channel type in the notification settings. The Gotify channel will use the `api_token` and `server_url` field for API key storage in PB. * feat: Implement Gotify notification service - The Gotify notification functionality has been implemented. The alert configuration channel will now use the `api_token` and `server_url` field for send to the Gotify API endpoint. * ⏳ chore(project): update development status and progress - feat: Add server_url field for Gotify - feat: Implement Gotify notification service * refactory(i18n): Improve internationalization configuration and add new translations - Added multiple new translation items - Updated the two language files: en and zhcn - Added type definitions for new translation items in types/services.ts - Modified some components to use the new translation items * refactory(i18n): Added architecture import function translation for the "About" page - Added translation items related to schema import in English, Chinese, and type definition files - Replaced hard-coded text with new translation items in the AboutSystem component * refactory(i18n): Added architecture import function translation for the "About" page - Added translation items related to schema import in English, Chinese, and type definition files - Replaced hard-coded text with new translation items in the AboutSystem component * refactory(i18n): Add internationalization support for the service statistics card * feat: Add NTFY API token field for Token-based authentication to ntfy server - Add the api_token field for NTFY notifications in both the dialog and service to save it to PB. NTFY schema to include api_token field. * feat(auth): add token support for ntfy - Updated the NTFY service to support API token authentication by adding Authorization Bearer header when api_token is provided. Closes: #89 * refactor(i18n): Added Chinese translations for Create Event and Maintenance - Supplemented missing Chinese translations - Added translation entries related to Create Event and Maintenance in both English and Chinese translation files * chore: deactivate GitHub donation * refactor(i18n): Optimize internationalization configuration and add new translation items - Add internationalization support to the LoadingState component - Implement internationalization translations in the Profile page - Use internationalized text in the TestEmailDialog component - Update English and Chinese translation files by adding new translation entries * docs(readme): deactivate donations, accept only infra support (cloud, domain, hosting) * feat(i18n): Enhanced internationalization support with variable interpolation - Refactored the `t` function in LanguageContext to support multiple parameter combinations - Added variable interpolation feature, allowing variables in translated texts - Optimized translation logic to improve accuracy and performance - Enhanced type safety by using TypeScript generics to ensure correct typing * refactor(i18n): Optimize service pagination internationalization copy - Added service pagination related copy in English and Chinese translation files - Updated type definitions to include new translation fields - Modified the ServicesPagination component to use the newly added translation fields * docs(README_zhcn): Update documentation content and sponsorship policy - Update image links in the documentation - Revise the sponsorship policy to no longer accept individual sponsorships, only enterprise-level collaborations - Update the display method for supporters and partners - Add Cloudflare and DigitalOcean as new partners * feat: Integrate data retention service - Implemented the data retention service in Go (service-operation) that manages cleanup of old records based on configured retention periods. The service runs once per day to ensure outdated data is removed automatically. * refactor: Remove manual cleanup buttons from Data Retention Settings - The three manual cleanup buttons have been removed from the dashboard. - The data retention service now automatically runs once per day, cleaning up older data based on the configured retention settings. --------- Co-authored-by: YiZixuan <sqkkyzx@qq.com> Co-authored-by: YiZixuan <sqkkyzx@outlook.com>
183 lines
6.6 KiB
Go
183 lines
6.6 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
"service-operation/config"
|
|
"service-operation/handlers"
|
|
"service-operation/monitoring"
|
|
"service-operation/pocketbase"
|
|
servermonitoring "service-operation/server-monitoring"
|
|
sslmonitoring "service-operation/ssl-monitoring"
|
|
uptimemonitoring "service-operation/uptime-monitoring"
|
|
dataretention "service-operation/data-retention"
|
|
)
|
|
|
|
func main() {
|
|
//log.Println("🚀 === STARTING SERVICE OPERATION SERVER ===")
|
|
|
|
cfg := config.Load()
|
|
//log.Printf("📋 Configuration loaded:")
|
|
//log.Printf(" - Port: %s", cfg.Port)
|
|
//log.Printf(" - Backend PB Enabled: %t", cfg.PocketBaseEnabled)
|
|
if cfg.PocketBaseEnabled {
|
|
//log.Printf(" - PocketBase URL: %s", cfg.PocketBaseURL)
|
|
}
|
|
|
|
// Initialize PocketBase client (no credentials required)
|
|
var pbClient *pocketbase.PocketBaseClient
|
|
var monitoringService *monitoring.MonitoringService
|
|
var sslMonitoringService *monitoring.SSLMonitoringService
|
|
var sslNotificationService *sslmonitoring.SSLMonitor
|
|
var serverMonitoringService *servermonitoring.ServerMonitoringService
|
|
var uptimeMonitoringService *uptimemonitoring.UptimeMonitor
|
|
var dataRetentionScheduler *dataretention.Scheduler
|
|
|
|
if cfg.PocketBaseEnabled {
|
|
//log.Println("🔧 Initializing PocketBase client...")
|
|
var err error
|
|
pbClient, err = pocketbase.NewPocketBaseClient(cfg.PocketBaseURL)
|
|
if err != nil {
|
|
//log.Printf("⚠️ WARNING: Failed to initialize PocketBase client: %v", err)
|
|
} else {
|
|
//log.Println("✅ PocketBase client initialized successfully")
|
|
|
|
//log.Println("🔍 Testing PocketBase connection...")
|
|
if err := pbClient.TestConnection(); err != nil {
|
|
//log.Printf("⚠️ WARNING: PocketBase connection test failed: %v", err)
|
|
} else {
|
|
//log.Println("✅ PocketBase connection test successful")
|
|
|
|
// Initialize and start service monitoring with regional support
|
|
//log.Println("🔧 Initializing service monitoring...")
|
|
monitoringService = monitoring.NewMonitoringService(pbClient)
|
|
go monitoringService.Start()
|
|
//log.Println("✅ Service monitoring started with regional agent support")
|
|
|
|
// Initialize and start SSL monitoring service (original)
|
|
//log.Println("🔧 Initializing SSL monitoring (original)...")
|
|
sslMonitoringService = monitoring.NewSSLMonitoringService(pbClient)
|
|
go sslMonitoringService.Start()
|
|
//log.Println("✅ SSL monitoring started (independent of regional agents)")
|
|
|
|
// Initialize and start SSL notification service (new)
|
|
//log.Println("🔧 Initializing SSL notification monitoring...")
|
|
sslNotificationService = sslmonitoring.NewSSLMonitor(pbClient)
|
|
go sslNotificationService.Start()
|
|
//log.Println("✅ SSL notification monitoring started with Telegram support")
|
|
|
|
// Initialize and start server monitoring service
|
|
//log.Println("🔧 Initializing server monitoring...")
|
|
serverMonitoringService = servermonitoring.NewServerMonitoringService(pbClient)
|
|
serverMonitoringService.Start()
|
|
//log.Println("✅ Server monitoring started with notification support")
|
|
|
|
// Initialize and start uptime monitoring service
|
|
//log.Println("🔧 Initializing uptime monitoring...")
|
|
uptimeMonitoringService = uptimemonitoring.NewUptimeMonitor(pbClient)
|
|
go uptimeMonitoringService.Start()
|
|
//log.Println("✅ Uptime monitoring started with notification support")
|
|
|
|
// Initialize and start data retention scheduler
|
|
//log.Println("🔧 Initializing data retention scheduler...")
|
|
dataRetentionScheduler = dataretention.NewScheduler(pbClient, 24*time.Hour) // Run daily
|
|
go dataRetentionScheduler.Start()
|
|
//log.Println("✅ Data retention scheduler started (daily cleanup)")
|
|
}
|
|
}
|
|
}
|
|
|
|
//log.Println("🔧 Initializing HTTP handlers...")
|
|
handler := handlers.NewOperationHandler(cfg, pbClient)
|
|
|
|
router := mux.NewRouter()
|
|
|
|
// Main operation endpoint
|
|
router.HandleFunc("/operation", handler.HandleOperation).Methods("POST")
|
|
|
|
// Quick operation endpoint with query parameters
|
|
router.HandleFunc("/operation/quick", handler.HandleQuickOperation).Methods("GET")
|
|
|
|
// Legacy ping endpoint for backward compatibility
|
|
router.HandleFunc("/ping", handler.HandleOperation).Methods("POST")
|
|
router.HandleFunc("/ping/quick", handler.HandleQuickOperation).Methods("GET")
|
|
|
|
// Health check
|
|
router.HandleFunc("/health", handler.HandleHealth).Methods("GET")
|
|
|
|
log.Printf("=== 🌐 CHECKCLE SERVICE OPERATION SERVER READY ===")
|
|
log.Printf("🚀 Starting on port %s", cfg.Port)
|
|
if pbClient != nil {
|
|
log.Printf("✓Backend integration enabled at %s ", pbClient.GetBaseURL())
|
|
}
|
|
if monitoringService != nil {
|
|
log.Printf("✓Service monitoring enabled with regional agent support")
|
|
}
|
|
if sslMonitoringService != nil {
|
|
//log.Printf("🔒 SSL certificate monitoring enabled (independent)")
|
|
}
|
|
if sslNotificationService != nil {
|
|
log.Printf("✓SSL notification monitoring enabled with Telegram support")
|
|
}
|
|
if serverMonitoringService != nil {
|
|
log.Printf("✓Server monitoring enabled with notification support")
|
|
}
|
|
if uptimeMonitoringService != nil {
|
|
log.Printf("✓Uptime monitoring enabled with notification support")
|
|
}
|
|
log.Printf("✓Supported operations: ping, dns, tcp, http, ssl")
|
|
if dataRetentionScheduler != nil {
|
|
log.Printf("✓Data retention scheduler enabled (daily cleanup)")
|
|
}
|
|
|
|
|
|
// Setup graceful shutdown
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
<-c
|
|
log.Println("🛑 === GRACEFUL SHUTDOWN INITIATED ===")
|
|
log.Println("🛑 Shutting down monitoring services...")
|
|
|
|
if monitoringService != nil {
|
|
log.Println("🛑 Stopping service monitoring...")
|
|
monitoringService.Stop()
|
|
}
|
|
if sslMonitoringService != nil {
|
|
log.Println("🛑 Stopping SSL monitoring...")
|
|
sslMonitoringService.Stop()
|
|
}
|
|
if sslNotificationService != nil {
|
|
log.Println("🛑 Stopping SSL notification monitoring...")
|
|
sslNotificationService.Stop()
|
|
}
|
|
if serverMonitoringService != nil {
|
|
log.Println("🛑 Stopping server monitoring...")
|
|
serverMonitoringService.Stop()
|
|
}
|
|
if uptimeMonitoringService != nil {
|
|
log.Println("🛑 Stopping uptime monitoring...")
|
|
uptimeMonitoringService.Stop()
|
|
}
|
|
if dataRetentionScheduler != nil {
|
|
log.Println("🛑 Stopping data retention scheduler...")
|
|
dataRetentionScheduler.Stop()
|
|
}
|
|
|
|
log.Println("✅ All services stopped gracefully")
|
|
log.Println("🛑 === SERVICE OPERATION SERVER STOPPED ===")
|
|
os.Exit(0)
|
|
}()
|
|
|
|
//log.Println("🌐 HTTP server starting...")
|
|
if err := http.ListenAndServe(":"+cfg.Port, router); err != nil {
|
|
log.Fatal("❌ FATAL: Failed to start HTTP server:", err)
|
|
}
|
|
} |