feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
39
checks/cdns/a_records.go
Обычный файл
39
checks/cdns/a_records.go
Обычный файл
@@ -0,0 +1,39 @@
|
||||
// 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
|
||||
}
|
||||
Ссылка в новой задаче
Block a user