All checks were successful
check / check (push) Successful in 4s
Add a read-only web dashboard at GET / that displays: - Summary counts for all monitored resources - Domain nameserver state with per-NS records and status - Hostname DNS records per authoritative nameserver - TCP port open/closed state with associated hostnames - TLS certificate details (CN, issuer, expiry, status) - Last 100 alerts in reverse chronological order Every data point shows relative age (e.g. '5m ago') for freshness. Page auto-refreshes every 30 seconds via meta refresh. Uses Tailwind CSS via CDN for a dark, technical aesthetic with saturated teals and blues on dark slate. Single page, no navigation. Implementation: - internal/notify/history.go: thread-safe ring buffer (last 100 alerts) - internal/notify/notify.go: record alerts in history before dispatch, refactor SendNotification into smaller dispatch helpers (funlen) - internal/handlers/dashboard.go: template rendering with embedded HTML, helper functions for relative time, record formatting, expiry days - internal/handlers/templates/dashboard.html: Tailwind-styled dashboard - internal/handlers/handlers.go: add State and Notify dependencies - internal/server/routes.go: register GET / dashboard route - README.md: document dashboard and new / endpoint No secrets (webhook URLs, API tokens, notification endpoints) are exposed in the dashboard. closes #82
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package notify
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"log/slog"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// NtfyPriority exports ntfyPriority for testing.
|
|
func NtfyPriority(priority string) string {
|
|
return ntfyPriority(priority)
|
|
}
|
|
|
|
// SlackColor exports slackColor for testing.
|
|
func SlackColor(priority string) string {
|
|
return slackColor(priority)
|
|
}
|
|
|
|
// NewRequestForTest exports newRequest for testing.
|
|
func NewRequestForTest(
|
|
ctx context.Context,
|
|
method string,
|
|
target *url.URL,
|
|
body io.Reader,
|
|
) *http.Request {
|
|
return newRequest(ctx, method, target, body)
|
|
}
|
|
|
|
// NewTestService creates a Service suitable for unit testing.
|
|
// It discards log output and uses the given transport.
|
|
func NewTestService(transport http.RoundTripper) *Service {
|
|
return &Service{
|
|
log: slog.New(slog.DiscardHandler),
|
|
transport: transport,
|
|
history: NewAlertHistory(),
|
|
}
|
|
}
|
|
|
|
// SetNtfyURL sets the ntfy URL on a Service for testing.
|
|
func (svc *Service) SetNtfyURL(u *url.URL) {
|
|
svc.ntfyURL = u
|
|
}
|
|
|
|
// SetSlackWebhookURL sets the Slack webhook URL on a
|
|
// Service for testing.
|
|
func (svc *Service) SetSlackWebhookURL(u *url.URL) {
|
|
svc.slackWebhookURL = u
|
|
}
|
|
|
|
// SetMattermostWebhookURL sets the Mattermost webhook URL on
|
|
// a Service for testing.
|
|
func (svc *Service) SetMattermostWebhookURL(u *url.URL) {
|
|
svc.mattermostWebhookURL = u
|
|
}
|
|
|
|
// SendNtfy exports sendNtfy for testing.
|
|
func (svc *Service) SendNtfy(
|
|
ctx context.Context,
|
|
topicURL *url.URL,
|
|
title, message, priority string,
|
|
) error {
|
|
return svc.sendNtfy(ctx, topicURL, title, message, priority)
|
|
}
|
|
|
|
// SendSlack exports sendSlack for testing.
|
|
func (svc *Service) SendSlack(
|
|
ctx context.Context,
|
|
webhookURL *url.URL,
|
|
title, message, priority string,
|
|
) error {
|
|
return svc.sendSlack(
|
|
ctx, webhookURL, title, message, priority,
|
|
)
|
|
}
|