feat: database monitors with sealed credentials
ci / image (pull_request) Successful in 2m38s
ci / build (pull_request) Successful in 7m5s
ci / lint (pull_request) Successful in 10m15s
ci / test (pull_request) Failing after 11m53s

Secret monitor settings such as database passwords are stored sealed,
bound to monitor type and field, never returned by the API, the console
or exports, kept when an edit leaves them empty, and opened only for the
checker's job. Monitor types are validated by the check package; the
database only checks their format. Compose gets a checks profile with
MariaDB, MongoDB and SQL Server, and CI tests against MariaDB and
MongoDB.

Closes #93

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 16:17:08 +01:00
1 parent a62ffb43de
commit d3cf9f48e1
15 files changed
+1079 -495

No files matched your search

+55 -1
View File
@@ -491,6 +491,18 @@ type MonitorForm struct {
PromVerify bool
Matchers []MatcherRow
StaleHours int
DB DBForm
}
// DBForm holds the settings of database checks. The password is never
// filled in; PasswordSet tells the form one is stored.
type DBForm struct {
User string
Database string
TLS string
Query string
Expect string
PasswordSet bool
}
// MatcherRow is one label matcher of an alertmanager monitor.
@@ -576,7 +588,7 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.type") }</span>
<select name="type" data-type-select class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, t := range []string{"http", "json", "prometheus", "tcp", "tls", "dns", "icmp", "heartbeat", "alertmanager"} {
for _, t := range []string{"http", "json", "prometheus", "tcp", "tls", "dns", "icmp", "postgres", "mysql", "mssql", "mongodb", "redis", "heartbeat", "alertmanager"} {
<option value={ t } selected?={ t == f.Type }>{ i18n.T(ctx, "monitors.type_"+t) }</option>
}
</select>
@@ -585,6 +597,11 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
@valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", f.Type != "heartbeat")
<p class="-mt-3 mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.target_hint") }</p>
</div>
for _, t := range []string{"postgres", "mysql", "mssql", "mongodb", "redis"} {
@typeFields(t, f.Type) {
@dbFields(t, f.DB)
}
}
@typeFields("alertmanager", f.Type) {
<p class="mb-4 text-xs text-muted">
{ i18n.T(ctx, "monitors.alertmanager_hint") }
@@ -1039,3 +1056,40 @@ func opKey(op string) string {
}
func passiveType(t string) bool { return t == "heartbeat" || t == "alertmanager" }
templ dbFields(typ string, d DBForm) {
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.db_hint") }</p>
if typ != "redis" {
@valueField(i18n.T(ctx, "monitors.db_user"), "config.user", d.User, "", false)
} else {
@valueField(i18n.T(ctx, "monitors.db_user_redis"), "config.user", d.User, "", false)
}
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.db_password") }</span>
<input
type="password"
name="config.password"
autocomplete="new-password"
if d.PasswordSet {
placeholder={ i18n.T(ctx, "monitors.secret_unchanged") }
}
class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
/>
</label>
@valueField(i18n.T(ctx, "monitors.db_database_"+typ), "config.database", d.Database, "", false)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.db_tls") }</span>
<select name="config.tls" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
for _, m := range []string{"require", "verify", "disable"} {
<option value={ m } selected?={ m == d.TLS }>{ i18n.T(ctx, "monitors.db_tls_"+m) }</option>
}
</select>
</label>
if typ != "redis" && typ != "mongodb" {
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.db_query") }</span>
<textarea name="config.query" rows="2" placeholder="SELECT 1" class="w-full border border-rule bg-transparent px-2.5 py-1.5 font-mono text-xs outline-none focus:border-ink">{ d.Query }</textarea>
</label>
@valueField(i18n.T(ctx, "monitors.db_expect"), "config.expect", d.Expect, "", false)
}
}