Added backup

This commit is contained in:
Magnus Root 2026-05-14 18:07:39 +03:00
parent 7c93457076
commit 33eb27f892

View file

@ -261,9 +261,11 @@ func wcCheckDomainFull(domain string, backendIPs []string) []wcDomainResult {
var results []wcDomainResult var results []wcDomainResult
// Проверка через backend IPs (curl) — каждый протокол независимо // Проверка через backend IPs (curl) — каждый протокол независимо
for _, ip := range backendIPs { for _, ipRaw := range backendIPs {
// Убираем суффикс " (backup)" для реального подключения
ip := strings.TrimSuffix(ipRaw, " (backup)")
for _, proto := range []string{"https", "http"} { 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) code, err := wcCurlGet(domain, ip, proto)
if err != nil { if err != nil {
r.Protocol = proto r.Protocol = proto
@ -455,8 +457,11 @@ func wcGetBackendIPs(db *sql.DB, sid string, excludedNets []*net.IPNet) ([]strin
seen := make(map[string]bool) seen := make(map[string]bool)
for _, e := range entries { for _, e := range entries {
// Берём только primary — down и другие режимы пропускаем // Берём primary и backup — down и другие режимы пропускаем
if e.Mode != "primary" { switch e.Mode {
case "primary", "backup":
// продолжаем
default:
log.Printf(" ⏭️ %s пропущен (mode: %s)", e.IP, e.Mode) log.Printf(" ⏭️ %s пропущен (mode: %s)", e.IP, e.Mode)
continue continue
} }
@ -472,9 +477,14 @@ func wcGetBackendIPs(db *sql.DB, sid string, excludedNets []*net.IPNet) ([]strin
continue continue
} }
if !seen[ip.String()] { ipStr := ip.String()
seen[ip.String()] = true if e.Mode == "backup" {
result = append(result, ip.String()) ipStr = ip.String() + " (backup)"
}
if !seen[ipStr] {
seen[ipStr] = true
result = append(result, ipStr)
} }
} }