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
// Проверка через 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)
}
}