Files
worker/checks/cdns/a_records.go
Gleb Tv 2c7a0236da feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
2026-07-13 17:55:14 +03:00

40 строки
888 B
Go

// Package cdns provides functionality.
package cdns
import (
"errors"
"strconv"
"github.com/miekg/dns"
"rsgit.ru/rsmon/rsmon/internal/netaddr"
)
// FetchARecords provides functionality.
func FetchARecords(zone, ns string) ([]NSRecord, error) {
config := dns.ClientConfig{Servers: []string{ns}}
c := new(dns.Client)
m := new(dns.Msg)
m.SetQuestion(zone, dns.TypeA)
m.RecursionDesired = true
r, _, err := c.Exchange(m, config.Servers[0]+":53")
if err != nil {
return nil, err
}
if r.Rcode != dns.RcodeSuccess {
return nil, errors.New("bad rcode: " + strconv.Itoa(r.Rcode))
}
var result []NSRecord
for _, a := range r.Answer {
if ar, ok := a.(*dns.A); ok {
// spew.Dump(ar)
val := netaddr.Inet{Inet: ar.A}
result = append(result, NSRecord{Name: a.Header().Name, Kind: "A", Value: val})
// fmt.Printf("%s\n", mx.String())
}
}
return result, nil
}