dashboard, status API and notifications tell apex domains from hostnames (closes #224)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
An apex domain's own records are still saved with the hostnames' records, under the domain's name, so the port and TLS checks find its addresses. Notifications about them now start `Domain:`, decided by the configured domains. The dashboard and /api/v1/status, which read only the saved state, take a hostname entry whose name also has a domain entry as that domain's own records: the dashboard shows them in a second table under Domains, the API in the domain's `recordsByNameserver`, and neither lists or counts them as hostnames. The startup notification counts domains and hostnames from the configuration. README says which of a domain's own records are watched and how their changes are notified. Model: opus-5-5
This commit was merged in pull request #244.
This commit is contained in:
+31
-17
@@ -271,8 +271,9 @@ func (w *Watcher) checkDomain(
|
||||
LastChecked: now,
|
||||
})
|
||||
|
||||
// The apex domain's records are also checked as a hostname's, so
|
||||
// that the port and TLS checks find its addresses.
|
||||
// The apex domain's records are also checked and saved as a
|
||||
// hostname's, so that the port and TLS checks find its addresses.
|
||||
// Notifications about them name it as a domain (see nameLine).
|
||||
w.checkHostname(ctx, domain)
|
||||
}
|
||||
|
||||
@@ -541,6 +542,17 @@ func (w *Watcher) detectHostnameChanges(
|
||||
w.detectCNAMEAddressChanges(ctx, hostname, prev, current)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (w *Watcher) nameLine(name string) string {
|
||||
if slices.Contains(w.config.Domains, name) {
|
||||
return "Domain: " + name
|
||||
}
|
||||
|
||||
return "Hostname: " + name
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -557,8 +569,8 @@ func (w *Watcher) detectCNAMEAddressChanges(
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf(
|
||||
"Hostname: %s\nOld: %s\nNew: %s",
|
||||
hostname,
|
||||
"%s\nOld: %s\nNew: %s",
|
||||
w.nameLine(hostname),
|
||||
strings.Join(old, ", "),
|
||||
strings.Join(cur, ", "),
|
||||
)
|
||||
@@ -590,8 +602,8 @@ func (w *Watcher) detectRecordChanges(
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf(
|
||||
"Hostname: %s\nNameserver: %s\n%s",
|
||||
hostname, ns,
|
||||
"%s\nNameserver: %s\n%s",
|
||||
w.nameLine(hostname), ns,
|
||||
recordDifferences(
|
||||
"Old", prevNS.Records,
|
||||
"New", cur.Records,
|
||||
@@ -618,8 +630,8 @@ func (w *Watcher) detectNSDisappearances(
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf(
|
||||
"Hostname: %s\nNameserver: %s disappeared",
|
||||
hostname, ns,
|
||||
"%s\nNameserver: %s disappeared",
|
||||
w.nameLine(hostname), ns,
|
||||
)
|
||||
|
||||
w.notify.SendNotification(
|
||||
@@ -648,8 +660,8 @@ func (w *Watcher) detectNSFailures(
|
||||
switch {
|
||||
case prevNS.Status == statusOK && cur.Status == statusError:
|
||||
msg := fmt.Sprintf(
|
||||
"Hostname: %s\nNameserver: %s\nError: %s",
|
||||
hostname, ns, cur.Error,
|
||||
"%s\nNameserver: %s\nError: %s",
|
||||
w.nameLine(hostname), ns, cur.Error,
|
||||
)
|
||||
|
||||
w.notify.SendNotification(
|
||||
@@ -660,8 +672,8 @@ func (w *Watcher) detectNSFailures(
|
||||
)
|
||||
case prevNS.Status == statusError && cur.Status == statusOK:
|
||||
msg := fmt.Sprintf(
|
||||
"Hostname: %s\nNameserver: %s recovered",
|
||||
hostname, ns,
|
||||
"%s\nNameserver: %s recovered",
|
||||
w.nameLine(hostname), ns,
|
||||
)
|
||||
|
||||
w.notify.SendNotification(
|
||||
@@ -683,8 +695,8 @@ func (w *Watcher) detectInconsistencies(
|
||||
ns1, ns2 := pair[0], pair[1]
|
||||
|
||||
msg := fmt.Sprintf(
|
||||
"Hostname: %s\n%s",
|
||||
hostname,
|
||||
"%s\n%s",
|
||||
w.nameLine(hostname),
|
||||
recordDifferences(
|
||||
ns1, current.RecordsByNameserver[ns1].Records,
|
||||
ns2, current.RecordsByNameserver[ns2].Records,
|
||||
@@ -1180,7 +1192,9 @@ func (w *Watcher) saveState() {
|
||||
// after the first full scan completes, if SEND_TEST_NOTIFICATION
|
||||
// is enabled. The message is informational, not an error or anomaly
|
||||
// alert. It is written before it reaches any endpoint, so it claims
|
||||
// nothing about whether the endpoints work.
|
||||
// nothing about whether the endpoints work. Domains and hostnames are
|
||||
// counted from the configuration: the state's hostnames also hold each
|
||||
// apex domain's own records.
|
||||
func (w *Watcher) maybeSendTestNotification(ctx context.Context) {
|
||||
if !w.config.SendTestNotification {
|
||||
return
|
||||
@@ -1194,8 +1208,8 @@ func (w *Watcher) maybeSendTestNotification(ctx context.Context) {
|
||||
"Tracking %d port endpoint(s) and %d TLS certificate(s).\n"+
|
||||
"This is a test notification, sent to every configured "+
|
||||
"notification endpoint.",
|
||||
len(snap.Domains),
|
||||
len(snap.Hostnames),
|
||||
len(w.config.Domains),
|
||||
len(w.config.Hostnames),
|
||||
len(snap.Ports),
|
||||
len(snap.Certificates),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user