watcher: Port Change notifications list domains apart from hostnames (closes #248)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
A Port Change notification's `Hosts:` line listed a port's apex domains and hostnames together. It now has a `Domains:` line and a `Hostnames:` line, and leaves out one that would name nothing. A name is a domain when it is a configured domain, the rule record notifications already use to start `Domain:` or `Hostname:`; that rule is now one method, isDomain, which both use. The port entries saved in the state are unchanged. README describes the new lines. Model: opus-5-5
This commit was merged in pull request #249.
This commit is contained in:
@@ -542,17 +542,50 @@ func (w *Watcher) detectHostnameChanges(
|
||||
w.detectCNAMEAddressChanges(ctx, hostname, prev, current)
|
||||
}
|
||||
|
||||
// isDomain reports whether name is a configured apex domain, whose own
|
||||
// records are checked and saved as a hostname's are.
|
||||
func (w *Watcher) isDomain(name string) bool {
|
||||
return slices.Contains(w.config.Domains, name)
|
||||
}
|
||||
|
||||
// nameLine is the line a notification about name's records starts with:
|
||||
// "Domain: " and the name for a configured apex domain, whose own
|
||||
// records are checked as a hostname's are, and "Hostname: " otherwise.
|
||||
// "Domain: " and the name for a configured apex domain, and
|
||||
// "Hostname: " otherwise.
|
||||
func (w *Watcher) nameLine(name string) string {
|
||||
if slices.Contains(w.config.Domains, name) {
|
||||
if w.isDomain(name) {
|
||||
return "Domain: " + name
|
||||
}
|
||||
|
||||
return "Hostname: " + name
|
||||
}
|
||||
|
||||
// portNameLines lists the names that resolve to a port's address, the
|
||||
// configured apex domains on one line and the hostnames on the next,
|
||||
// leaving out a line that would name nothing.
|
||||
func (w *Watcher) portNameLines(names []string) string {
|
||||
var domains, hostnames []string
|
||||
|
||||
for _, name := range names {
|
||||
if w.isDomain(name) {
|
||||
domains = append(domains, name)
|
||||
} else {
|
||||
hostnames = append(hostnames, name)
|
||||
}
|
||||
}
|
||||
|
||||
var lines []string
|
||||
|
||||
if len(domains) > 0 {
|
||||
lines = append(lines, "Domains: "+strings.Join(domains, ", "))
|
||||
}
|
||||
|
||||
if len(hostnames) > 0 {
|
||||
lines = append(lines, "Hostnames: "+strings.Join(hostnames, ", "))
|
||||
}
|
||||
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
// detectCNAMEAddressChanges notifies when the addresses at the end of
|
||||
// hostname's CNAME chain differ from those the previous check saved,
|
||||
// including a change from or to none. When the previous addresses are
|
||||
@@ -952,8 +985,8 @@ func (w *Watcher) checkSinglePort(
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf(
|
||||
"Hosts: %s\nAddress: %s\nPort now %s",
|
||||
strings.Join(hostnames, ", "), key, stateStr,
|
||||
"%s\nAddress: %s\nPort now %s",
|
||||
w.portNameLines(hostnames), key, stateStr,
|
||||
)
|
||||
|
||||
w.notify.SendNotification(
|
||||
|
||||
Reference in New Issue
Block a user