mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 07:56:57 +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)
|
logPrefix := fmt.Sprintf("[App %s (%s)]", app.Name, app.PublicURL)
|
||||||
fmt.Printf("%s Checking...\n", logPrefix)
|
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 {
|
if parseErr != nil {
|
||||||
fmt.Printf("%s Invalid URL: %v\n", logPrefix, parseErr)
|
fmt.Printf("%s Invalid URL: %v\n", logPrefix, parseErr)
|
||||||
continue
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", app.PublicURL, nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", checkURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s Request creation failed: %v\n", logPrefix, err)
|
fmt.Printf("%s Request creation failed: %v\n", logPrefix, err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -36,7 +36,7 @@ func InitDB() (*sql.DB, error) {
|
|||||||
// GetApplications fetches all applications with public URLs
|
// GetApplications fetches all applications with public URLs
|
||||||
func GetApplications(db *sql.DB) ([]models.Application, error) {
|
func GetApplications(db *sql.DB) ([]models.Application, error) {
|
||||||
rows, err := db.Query(
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error fetching applications: %v", err)
|
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
|
var apps []models.Application
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var app models.Application
|
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)
|
fmt.Printf("Error scanning row: %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,10 +5,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
ID int
|
ID int
|
||||||
Name string
|
Name string
|
||||||
PublicURL string
|
PublicURL string
|
||||||
Online bool
|
Online bool
|
||||||
|
UptimeCheckURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user