From 33eb27f89224d95d9395b25b7208b7a574fc0b30 Mon Sep 17 00:00:00 2001 From: Magnus Root Date: Thu, 14 May 2026 18:07:39 +0300 Subject: [PATCH] Added backup --- webcheck.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/webcheck.go b/webcheck.go index ee1c110..5838f07 100644 --- a/webcheck.go +++ b/webcheck.go @@ -261,9 +261,11 @@ func wcCheckDomainFull(domain string, backendIPs []string) []wcDomainResult { var results []wcDomainResult // Проверка через backend IPs (curl) — каждый протокол независимо - for _, ip := range backendIPs { + for _, ipRaw := range backendIPs { + // Убираем суффикс " (backup)" для реального подключения + ip := strings.TrimSuffix(ipRaw, " (backup)") for _, proto := range []string{"https", "http"} { - r := wcDomainResult{Domain: domain, BackendIP: ip, Source: "curl", CheckedAt: time.Now()} + r := wcDomainResult{Domain: domain, BackendIP: ipRaw, Source: "curl", CheckedAt: time.Now()} code, err := wcCurlGet(domain, ip, proto) if err != nil { r.Protocol = proto @@ -455,8 +457,11 @@ func wcGetBackendIPs(db *sql.DB, sid string, excludedNets []*net.IPNet) ([]strin seen := make(map[string]bool) for _, e := range entries { - // Берём только primary — down и другие режимы пропускаем - if e.Mode != "primary" { + // Берём primary и backup — down и другие режимы пропускаем + switch e.Mode { + case "primary", "backup": + // продолжаем + default: log.Printf(" ⏭️ %s пропущен (mode: %s)", e.IP, e.Mode) continue } @@ -472,9 +477,14 @@ func wcGetBackendIPs(db *sql.DB, sid string, excludedNets []*net.IPNet) ([]strin continue } - if !seen[ip.String()] { - seen[ip.String()] = true - result = append(result, ip.String()) + ipStr := ip.String() + if e.Mode == "backup" { + ipStr = ip.String() + " (backup)" + } + + if !seen[ipStr] { + seen[ipStr] = true + result = append(result, ipStr) } }