mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 23:47:13 +00:00
Enhance application monitoring by integrating custom uptime check URL support. Updated database queries and application model to include UptimeCheckURL, allowing for more flexible monitoring options.
This commit is contained in:
parent
30aa4bcf57
commit
fcb7196d1c
@ -28,7 +28,14 @@ func MonitorApplications(db *sql.DB, client *http.Client, apps []models.Applicat
|
||||
logPrefix := fmt.Sprintf("[App %s (%s)]", app.Name, app.PublicURL)
|
||||
fmt.Printf("%s Checking...\n", logPrefix)
|
||||
|
||||
parsedURL, parseErr := url.Parse(app.PublicURL)
|
||||
// Determine which URL to use for monitoring
|
||||
checkURL := app.PublicURL
|
||||
if app.UptimeCheckURL != "" {
|
||||
checkURL = app.UptimeCheckURL
|
||||
fmt.Printf("%s Using custom uptime check URL: %s\n", logPrefix, checkURL)
|
||||
}
|
||||
|
||||
parsedURL, parseErr := url.Parse(checkURL)
|
||||
if parseErr != nil {
|
||||
fmt.Printf("%s Invalid URL: %v\n", logPrefix, parseErr)
|
||||
continue
|
||||
@ -40,7 +47,7 @@ func MonitorApplications(db *sql.DB, client *http.Client, apps []models.Applicat
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", app.PublicURL, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", checkURL, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("%s Request creation failed: %v\n", logPrefix, err)
|
||||
continue
|
||||
|
||||
@ -36,7 +36,7 @@ func InitDB() (*sql.DB, error) {
|
||||
// GetApplications fetches all applications with public URLs
|
||||
func GetApplications(db *sql.DB) ([]models.Application, error) {
|
||||
rows, err := db.Query(
|
||||
`SELECT id, name, "publicURL", online FROM application WHERE "publicURL" IS NOT NULL`,
|
||||
`SELECT id, name, "publicURL", online, "uptimeCheckURL" FROM application WHERE "publicURL" IS NOT NULL`,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error fetching applications: %v", err)
|
||||
@ -46,7 +46,7 @@ func GetApplications(db *sql.DB) ([]models.Application, error) {
|
||||
var apps []models.Application
|
||||
for rows.Next() {
|
||||
var app models.Application
|
||||
if err := rows.Scan(&app.ID, &app.Name, &app.PublicURL, &app.Online); err != nil {
|
||||
if err := rows.Scan(&app.ID, &app.Name, &app.PublicURL, &app.Online, &app.UptimeCheckURL); err != nil {
|
||||
fmt.Printf("Error scanning row: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -5,10 +5,11 @@ import (
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
ID int
|
||||
Name string
|
||||
PublicURL string
|
||||
Online bool
|
||||
ID int
|
||||
Name string
|
||||
PublicURL string
|
||||
Online bool
|
||||
UptimeCheckURL string
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user