Prevent uneccessary notifications to slaves

This commit is contained in:
Joachim Lusiardi 2025-02-25 07:17:40 +01:00
parent 9a56c5b8a7
commit 3f772923c4
3 changed files with 35 additions and 8 deletions

1
go.mod
View File

@ -9,4 +9,5 @@ require (
github.com/pquerna/otp v1.4.0 // indirect
github.com/xlzd/gotp v0.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

19
go.sum Normal file
View File

@ -0,0 +1,19 @@
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dspinhirne/netaddr-go v0.0.0-20211008142535-a4c5bccad224 h1:Y7k0gYiBQz/sMahnvLzM9I40UOvCeQ8WVjjsBeCtFF8=
github.com/dspinhirne/netaddr-go v0.0.0-20211008142535-a4c5bccad224/go.mod h1:j1oDdmBtACJEAQr2T3DQNZQDfSuJzRKHadPABYd/MHo=
github.com/joeig/go-powerdns/v3 v3.14.3 h1:z55hTGtBe7mEaKG1B/xtMHagqWPpxH+z4VVf8u9+NTc=
github.com/joeig/go-powerdns/v3 v3.14.3/go.mod h1:hA54LX2p4A/Jp1Kgdhd7Lh3jAU0u7wV1mk1JbGywt60=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/otp v1.4.0 h1:wZvl1TIVxKRThZIBiwOOHOGP/1+nZyWBil9Y2XNEDzg=
github.com/pquerna/otp v1.4.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/xlzd/gotp v0.1.0 h1:37blvlKCh38s+fkem+fFh7sMnceltoIEBYTVXyoa5Po=
github.com/xlzd/gotp v0.1.0/go.mod h1:ndLJ3JKzi3xLmUProq4LLxCuECL93dG9WASNLpHz8qg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

23
main.go
View File

@ -3,6 +3,8 @@ package main
/*
* https://github.com/joeig/go-powerdns
* https://github.com/xlzd/gotp
* https://github.com/dspinhirne/netaddr-go => https://pkg.go.dev/github.com/dspinhirne/netaddr-go
* https://github.com/go-yaml/yaml/tree/v2.4.0 =>
*/
import (
"context"
@ -10,7 +12,7 @@ import (
"github.com/dspinhirne/netaddr-go"
"github.com/joeig/go-powerdns/v3"
"github.com/xlzd/gotp"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
"log"
"net"
"net/http"
@ -62,6 +64,7 @@ func main() {
ipv6, _ := netaddr.ParseIPv6(ip)
new_prefix := ipv6.NetId()
updated := false
for _, record_to_update := range c.Records {
records, err := pdns.Records.Get(ctx, c.Zone, record_to_update, powerdns.RRTypePtr(powerdns.RRTypeAAAA))
if err != nil {
@ -75,17 +78,21 @@ func main() {
}
hostId := ipv6.HostId()
new_ipv6 := netaddr.NewIPv6(new_prefix, hostId)
log.Println(fmt.Sprintf("Host: %q -> %q", ipv6, new_ipv6))
err = pdns.Records.Change(ctx, c.Zone, record_to_update+"."+c.Zone, powerdns.RRTypeAAAA, 30, []string{new_ipv6.Long()})
if err != nil {
log.Fatalf("Update err %v ", err)
log.Println(fmt.Sprintf("Host: %q -> %q needs update: %t", ipv6, new_ipv6, ipv6.Long() != new_ipv6.Long()))
if ipv6.Long() != new_ipv6.Long() {
updated = true
err = pdns.Records.Change(ctx, c.Zone, record_to_update+"."+c.Zone, powerdns.RRTypeAAAA, 30, []string{new_ipv6.Long()})
if err != nil {
log.Fatalf("Update err %v ", err)
}
}
}
}
}
pdns.Zones.Notify(ctx, c.Zone)
log.Println("Updated...")
if updated {
pdns.Zones.Notify(ctx, c.Zone)
log.Println("Updated...")
}
}
})