From fb03b28df7f9b64f48622be1748da2be63b28852 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?=
Date: Sun, 22 Nov 2026 16:35:49 +0100
Subject: [PATCH] feat: platform admins can switch off check types
Types an installation cannot offer, such as Docker on shared cloud
checkers, can be switched off in the admin panel. They are not offered
in the editor or accepted by the API for new monitors or type changes;
existing monitors keep running and stay editable. The setting lives in
a new platform_settings table and reaches every replica at once through
the versioned cache. GET /api/v1/org/check-types lists what is offered.
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
---
internal/api/apidocs.go | 7 +
internal/api/audit.go | 1 +
internal/api/checktypes.go | 123 ++++++++
internal/api/checktypes_test.go | 77 +++++
internal/api/console.go | 4 +
internal/api/monitors.go | 13 +
internal/api/pages.go | 8 +-
internal/api/server.go | 34 ++-
internal/i18n/locales/de.json | 5 +
internal/i18n/locales/en.json | 5 +
.../sql/00036_platform_settings.sql | 17 ++
internal/store/models.go | 6 +
internal/store/platform_settings.sql.go | 36 +++
internal/store/querier.go | 2 +
internal/store/queries/platform_settings.sql | 6 +
internal/web/monitors.templ | 4 +-
internal/web/monitors_templ.go | 286 +++++++++---------
internal/web/regions.templ | 28 +-
internal/web/regions_templ.go | 125 +++++++-
19 files changed, 627 insertions(+), 160 deletions(-)
create mode 100644 internal/api/checktypes.go
create mode 100644 internal/api/checktypes_test.go
create mode 100644 internal/migrations/sql/00036_platform_settings.sql
create mode 100644 internal/store/platform_settings.sql.go
create mode 100644 internal/store/queries/platform_settings.sql
diff --git a/internal/api/apidocs.go b/internal/api/apidocs.go
index 9d93e4d..a8724d6 100644
--- a/internal/api/apidocs.go
+++ b/internal/api/apidocs.go
@@ -71,6 +71,8 @@ var endpoints = []endpoint{
{method: "GET", path: "/api/v1/org/checkers/:id", tag: "Monitors", summary: "What a checker instance is doing",
description: "Platform checkers serve every organization; other organizations' work appears only as a count.",
resp: checkerActivity{}},
+ {method: "GET", path: "/api/v1/org/check-types", tag: "Monitors", summary: "Monitor types this installation offers",
+ resp: obj{"types": []string{}}},
{method: "GET", path: "/api/v1/org/groups", tag: "Monitors", summary: "List monitor groups", resp: obj{"groups": []groupView{}}},
{method: "POST", path: "/api/v1/org/groups", tag: "Monitors", summary: "Create a group", perm: "monitors.write",
req: groupRequest{}, status: http.StatusCreated, resp: groupView{}},
@@ -203,6 +205,11 @@ var endpoints = []endpoint{
resp: obj{"documents": []legalView{}}},
{method: "PUT", path: "/api/v1/admin/legal/:kind", tag: "Platform", summary: "Set a platform legal document", perm: "platform admin",
req: legalRequest{}, status: http.StatusNoContent},
+ {method: "GET", path: "/api/v1/admin/check-types", tag: "Platform", summary: "Check types and whether they are offered", perm: "platform admin",
+ resp: obj{"types": []checkTypeView{}}},
+ {method: "PUT", path: "/api/v1/admin/check-types", tag: "Platform", summary: "Choose the check types offered for new monitors",
+ description: "Types left out are switched off: not offered for new monitors or type changes; existing monitors keep running.",
+ perm: "platform admin", req: checkTypesRequest{}, status: http.StatusNoContent},
{method: "GET", path: "/api/v1/admin/regions", tag: "Platform", summary: "List platform regions", perm: "platform admin",
resp: obj{"regions": []regionView{}}},
{method: "POST", path: "/api/v1/admin/regions", tag: "Platform", summary: "Create a platform region", perm: "platform admin",
diff --git a/internal/api/audit.go b/internal/api/audit.go
index 3344026..71e3f52 100644
--- a/internal/api/audit.go
+++ b/internal/api/audit.go
@@ -84,6 +84,7 @@ var auditActions = map[string]string{
"PUT /api/v1/admin/legal/:kind": "platform.legal_update",
"PUT /api/v1/org/legal/:kind": "org.legal_update",
+ "PUT /api/v1/admin/check-types": "platform.check_types_update",
"POST /api/v1/admin/regions": "platform.region_create",
"DELETE /api/v1/admin/regions/:id": "platform.region_delete",
"POST /api/v1/admin/agents": "platform.agent_create",
diff --git a/internal/api/checktypes.go b/internal/api/checktypes.go
new file mode 100644
index 0000000..b32aa57
--- /dev/null
+++ b/internal/api/checktypes.go
@@ -0,0 +1,123 @@
+package api
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "net/http"
+ "slices"
+
+ "github.com/gin-gonic/gin"
+ "github.com/jackc/pgx/v5"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/check"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/store"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
+)
+
+// Platform admins can switch off check types the installation cannot
+// offer, such as Docker on shared cloud checkers. Switched-off types are
+// not offered for new monitors; existing ones keep running and stay
+// editable.
+
+const settingDisabledChecks = "disabled_check_types"
+
+func (s *Server) disabledChecks(ctx context.Context) map[string]bool {
+ set, err := s.checkTypes.get(ctx, s.rdb, func(ctx context.Context) (map[string]bool, error) {
+ out := map[string]bool{}
+ err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
+ raw, err := q.GetPlatformSetting(ctx, settingDisabledChecks)
+ if errors.Is(err, pgx.ErrNoRows) {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ var list []string
+ _ = json.Unmarshal(raw, &list)
+ for _, t := range list {
+ out[t] = true
+ }
+ return nil
+ })
+ return out, err
+ })
+ if err != nil {
+ s.log.WarnContext(ctx, "loading disabled check types failed", "error", err)
+ }
+ return set
+}
+
+// enabledCheckTypes lists the types offered for new monitors, plus keep
+// when a monitor of a switched-off type is being edited.
+func (s *Server) enabledCheckTypes(ctx context.Context, keep string) []string {
+ off := s.disabledChecks(ctx)
+ var out []string
+ for _, t := range check.Types {
+ if !off[string(t)] || string(t) == keep {
+ out = append(out, string(t))
+ }
+ }
+ return out
+}
+
+type checkTypeView struct {
+ Type string `json:"type"`
+ Enabled bool `json:"enabled"`
+}
+
+func (s *Server) adminListCheckTypes(c *gin.Context) {
+ off := s.disabledChecks(c.Request.Context())
+ out := make([]checkTypeView, len(check.Types))
+ for i, t := range check.Types {
+ out[i] = checkTypeView{Type: string(t), Enabled: !off[string(t)]}
+ }
+ c.JSON(http.StatusOK, gin.H{"types": out})
+}
+
+type checkTypesRequest struct {
+ // Enabled lists the types to offer; all others are switched off.
+ Enabled []string `json:"enabled" binding:"max=100"`
+}
+
+func (s *Server) adminSetCheckTypes(c *gin.Context) {
+ var req checkTypesRequest
+ if !bind(c, &req) {
+ return
+ }
+ var disabled []string
+ for _, t := range check.Types {
+ if !slices.Contains(req.Enabled, string(t)) {
+ disabled = append(disabled, string(t))
+ }
+ }
+ for _, t := range req.Enabled {
+ if !slices.Contains(check.Types, check.Type(t)) {
+ fail(c, http.StatusUnprocessableEntity, "invalid_type")
+ return
+ }
+ }
+ if len(disabled) == len(check.Types) {
+ fail(c, http.StatusUnprocessableEntity, "all_check_types_disabled")
+ return
+ }
+ ctx := c.Request.Context()
+ raw, _ := json.Marshal(append([]string{}, disabled...))
+ auditDetail(c, "disabled", disabled)
+ err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
+ return q.SetPlatformSetting(ctx, store.SetPlatformSettingParams{Key: settingDisabledChecks, Value: raw})
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if err := s.checkTypes.bump(ctx, s.rdb); err != nil {
+ s.log.ErrorContext(ctx, "announcing check type change failed", "error", err)
+ }
+ c.Status(http.StatusNoContent)
+}
+
+// orgCheckTypes tells API clients which monitor types they can create.
+func (s *Server) orgCheckTypes(c *gin.Context) {
+ c.JSON(http.StatusOK, gin.H{"types": s.enabledCheckTypes(c.Request.Context(), "")})
+}
diff --git a/internal/api/checktypes_test.go b/internal/api/checktypes_test.go
new file mode 100644
index 0000000..8754cb6
--- /dev/null
+++ b/internal/api/checktypes_test.go
@@ -0,0 +1,77 @@
+package api_test
+
+import (
+ "context"
+ "net/http"
+ "slices"
+ "strings"
+ "testing"
+
+ "github.com/jackc/pgx/v5"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/check"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/store"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
+)
+
+func TestCheckTypesCanBeSwitchedOff(t *testing.T) {
+ e := newEnv(t)
+ // A second replica, started first: starting it clears the Redis test
+ // database, sessions included.
+ other := newEnv(t)
+ _, region := e.platformChecker(t, uniq("eu-"))
+ admin := e.browser(t)
+ admin.signup("a@"+uniq("ct")+".test", uniq("ct-"))
+ if err := tenant.New(e.dbPool).Tx(context.Background(), tenant.Global(), func(q *store.Queries) error {
+ return q.MakeAdmin(context.Background(), admin.userIDSelf())
+ }); err != nil {
+ t.Fatal(err)
+ }
+ all := make([]string, len(check.Types))
+ for i, ty := range check.Types {
+ all[i] = string(ty)
+ }
+ // The setting is platform-wide: reset it directly, whatever happens
+ // to sessions during the test.
+ reset := func() {
+ _ = e.asSystem(t, func(tx pgx.Tx) error {
+ _, err := tx.Exec(context.Background(), `DELETE FROM platform_settings WHERE key = 'disabled_check_types'`)
+ return err
+ })
+ }
+ reset()
+ t.Cleanup(reset)
+
+ // A heartbeat created while allowed stays editable afterwards.
+ _, hb := admin.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Backup", "type": "heartbeat", "interval_seconds": 3600})
+ _, tcp := admin.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Port", "type": "tcp", "target": "example.com:443", "interval_seconds": 60, "regions": []string{region}})
+
+ enabled := slices.DeleteFunc(slices.Clone(all), func(s string) bool { return s == "icmp" || s == "heartbeat" })
+ if st, body := admin.do("PUT", "/api/v1/admin/check-types", map[string]any{"enabled": enabled}); st != http.StatusNoContent {
+ t.Fatalf("switch off = %d %v", st, body)
+ }
+ if st, body := admin.do("PUT", "/api/v1/admin/check-types", map[string]any{"enabled": []string{}}); st != http.StatusUnprocessableEntity {
+ t.Errorf("switching off everything = %d %v", st, body)
+ }
+
+ // Another replica sees the change at once.
+ member := other.browser(t)
+ member.signup("m@"+uniq("ct")+".test", uniq("ctm-"))
+ _, types := member.do("GET", "/api/v1/org/check-types", nil)
+ if raw := mustJSON(types); strings.Contains(raw, `"icmp"`) || strings.Contains(raw, `"heartbeat"`) || !strings.Contains(raw, `"http"`) {
+ t.Errorf("offered types = %s", raw)
+ }
+ st, body := member.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Ping", "type": "icmp", "target": "example.com", "interval_seconds": 60, "regions": []string{region}})
+ expect(t, "create switched-off type", st, body, http.StatusUnprocessableEntity, "check_type_disabled")
+ if _, _, page := member.page("/monitors/new"); strings.Contains(page, `value="icmp"`) || !strings.Contains(page, `value="http"`) {
+ t.Error("the editor still offers a switched-off type")
+ }
+
+ st, body = admin.do("PUT", "/api/v1/org/monitors/"+hb["id"].(string), map[string]any{"name": "Nightly backup", "type": "heartbeat", "interval_seconds": 7200})
+ expect(t, "edit existing heartbeat", st, body, http.StatusOK, "")
+ st, body = admin.do("PUT", "/api/v1/org/monitors/"+tcp["id"].(string), map[string]any{"name": "Port", "type": "icmp", "target": "example.com", "interval_seconds": 60, "regions": []string{region}})
+ expect(t, "switch to a switched-off type", st, body, http.StatusUnprocessableEntity, "check_type_disabled")
+ if _, _, page := admin.page("/monitors/" + hb["id"].(string) + "/edit"); !strings.Contains(page, `value="heartbeat" selected`) {
+ t.Error("editing a monitor of a switched-off type does not keep its type")
+ }
+}
diff --git a/internal/api/console.go b/internal/api/console.go
index 7700fe9..1ca5c1d 100644
--- a/internal/api/console.go
+++ b/internal/api/console.go
@@ -554,6 +554,10 @@ func (s *Server) monitorEditor(c *gin.Context, p *principal, page web.Page, me w
if err != nil {
return nil, err
}
+ f.Types = s.enabledCheckTypes(ctx, f.Type)
+ if !slices.Contains(f.Types, f.Type) {
+ f.Type = f.Types[0]
+ }
for i, r := range regions {
live, err := s.sched.Instances(ctx, r.ID.String())
if err != nil {
diff --git a/internal/api/monitors.go b/internal/api/monitors.go
index 7dd759b..33121cc 100644
--- a/internal/api/monitors.go
+++ b/internal/api/monitors.go
@@ -248,6 +248,10 @@ func (s *Server) createMonitor(c *gin.Context) {
if !s.validateMonitor(c, &req, t) {
return
}
+ if s.disabledChecks(ctx)[req.Type] {
+ fail(c, http.StatusUnprocessableEntity, "check_type_disabled")
+ return
+ }
req.Target = passiveTarget(check.Type(req.Type), req.Target)
req.Config = s.sealMonitorConfig(check.Type(req.Type), req.Config, nil)
var m store.Monitor
@@ -344,6 +348,9 @@ func (s *Server) updateMonitor(c *gin.Context) {
if previous, err = q.MonitorRegions(ctx, id); err != nil {
return err
}
+ if old.Type != req.Type && s.disabledChecks(ctx)[req.Type] {
+ return errCheckTypeDisabled
+ }
if old.Type == req.Type {
req.Config = s.sealMonitorConfig(check.Type(req.Type), req.Config, old.Config)
} else {
@@ -367,6 +374,10 @@ func (s *Server) updateMonitor(c *gin.Context) {
}
return setRegions(ctx, q, m, req.Regions)
})
+ if errors.Is(err, errCheckTypeDisabled) {
+ fail(c, http.StatusUnprocessableEntity, "check_type_disabled")
+ return
+ }
if errors.Is(err, pgx.ErrNoRows) || (err == nil && denied) {
fail(c, http.StatusNotFound, "not_found")
return
@@ -526,3 +537,5 @@ func passiveRegion(t check.Type) string {
}
return heartbeatRegion
}
+
+var errCheckTypeDisabled = errors.New("api: check type switched off")
diff --git a/internal/api/pages.go b/internal/api/pages.go
index a9d7855..0b856c1 100644
--- a/internal/api/pages.go
+++ b/internal/api/pages.go
@@ -16,6 +16,7 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/check"
"git.zb-server.de/ZB-Server/uptimesebi/internal/datapolicy"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
@@ -490,7 +491,12 @@ func (s *Server) adminPage(c *gin.Context) {
internalError(c, err)
return
}
- web.Render(c, http.StatusOK, web.AdminPage(s.pageFor(c, "admin.title"), me, v, storageView(c, stats)))
+ off := s.disabledChecks(ctx)
+ var types []web.CheckTypeOption
+ for _, t := range check.Types {
+ types = append(types, web.CheckTypeOption{Type: string(t), Enabled: !off[string(t)]})
+ }
+ web.Render(c, http.StatusOK, web.AdminPage(s.pageFor(c, "admin.title"), me, v, storageView(c, stats), types))
}
func (s *Server) buildRegionsView(ctx context.Context, regions []store.Region, agents []store.ListAgentsRow, apiBase, next string, manageable func(store.Region) bool) (web.RegionsView, error) {
diff --git a/internal/api/server.go b/internal/api/server.go
index 28bfb18..a0342ef 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -44,6 +44,8 @@ type Server struct {
eval *evaluate.Evaluator
smtp *notify.SMTP
legal *versioned[[]agentapi.LegalDoc]
+ // checkTypes caches the check types switched off platform-wide.
+ checkTypes *versioned[map[string]bool]
}
// Deps are the external resources a Server needs.
@@ -61,20 +63,21 @@ func New(cfg config.API, d Deps) *Server {
allowPrivate := cfg.SSOAllowPrivate()
mail, _ := notify.ParseSMTP(cfg.SMTPURL)
return &Server{
- eval: evaluate.New(d.Redis),
- smtp: mail,
- cfg: cfg,
- log: d.Log,
- db: d.DB,
- rdb: d.Redis,
- keys: d.Keys,
- catalog: d.Catalog,
- sessions: auth.NewSessions(d.Redis, cfg.SessionIdle, cfg.SessionAbsolute),
- limiter: auth.NewLimiter(d.Redis),
- totp: auth.NewTOTPVerifier(d.Redis),
- sso: sso.New(sso.SafeHTTPClient(allowPrivate), cfg.PublicURL+"/sso/callback", allowPrivate),
- sched: schedule.New(d.Redis),
- legal: newVersioned[[]agentapi.LegalDoc]("legal"),
+ eval: evaluate.New(d.Redis),
+ smtp: mail,
+ cfg: cfg,
+ log: d.Log,
+ db: d.DB,
+ rdb: d.Redis,
+ keys: d.Keys,
+ catalog: d.Catalog,
+ sessions: auth.NewSessions(d.Redis, cfg.SessionIdle, cfg.SessionAbsolute),
+ limiter: auth.NewLimiter(d.Redis),
+ totp: auth.NewTOTPVerifier(d.Redis),
+ sso: sso.New(sso.SafeHTTPClient(allowPrivate), cfg.PublicURL+"/sso/callback", allowPrivate),
+ sched: schedule.New(d.Redis),
+ legal: newVersioned[[]agentapi.LegalDoc]("legal"),
+ checkTypes: newVersioned[map[string]bool]("check-types"),
}
}
@@ -136,6 +139,7 @@ func (s *Server) Mount(r gin.IRouter) {
org.POST("/alertmanager/receivers", sessionOnly(), can(authz.OrgManage), s.createReceiver)
org.DELETE("/alertmanager/receivers/:id", sessionOnly(), can(authz.OrgManage), s.deleteReceiver)
org.GET("/alertmanager/alerts", can(authz.MonitorsRead), s.listFiringAlerts)
+ org.GET("/check-types", s.orgCheckTypes)
org.GET("/maintenance", s.listMaintenance)
org.POST("/maintenance", s.createMaintenance)
org.PUT("/maintenance/:id", s.updateMaintenance)
@@ -154,6 +158,8 @@ func (s *Server) Mount(r gin.IRouter) {
admin := v1.Group("/admin", s.requireAdmin())
admin.GET("/audit", s.listPlatformAudit)
+ admin.GET("/check-types", s.adminListCheckTypes)
+ admin.PUT("/check-types", s.adminSetCheckTypes)
admin.GET("/legal", s.adminListLegal)
admin.PUT("/legal/:kind", s.adminSaveLegal)
admin.GET("/regions", s.adminListRegions)
diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json
index bee1ccd..9be4704 100644
--- a/internal/i18n/locales/de.json
+++ b/internal/i18n/locales/de.json
@@ -1,4 +1,6 @@
{
+ "admin.check_types": "Check-Typen",
+ "admin.check_types_intro": "Schalte Typen ab, die diese Installation nicht anbieten kann, etwa Docker auf geteilten Cloud-Checkern oder ICMP ohne die nötigen Rechte. Sie verschwinden für neue Monitore; bestehende laufen weiter.",
"admin.intro": "Hier angelegte Regionen, Checker und Statuspage-Server stehen allen Organisationen zur Verfügung. Organisationen legen ihre eigenen unter Regionen & Checker an.",
"admin.title": "Plattform-Verwaltung",
"agents.create": "Agent anlegen",
@@ -65,6 +67,7 @@
"audit.action.org.policy_update": "Sicherheitsrichtlinie geändert",
"audit.action.platform.agent_create": "Plattform-Agent erstellt",
"audit.action.platform.agent_delete": "Plattform-Agent widerrufen",
+ "audit.action.platform.check_types_update": "Check-Typen geändert",
"audit.action.platform.legal_update": "Rechtstext der Plattform geändert",
"audit.action.platform.region_create": "Plattform-Region erstellt",
"audit.action.platform.region_delete": "Plattform-Region gelöscht",
@@ -221,10 +224,12 @@
"email.test.body": "Dies ist ein Test. Wenn du ihn lesen kannst, funktioniert der Kanal.",
"email.test.subject": "Testbenachrichtigung von UptimeSebi",
"error.agent_protocol_unsupported": "Diese Agent-Version wird von der API nicht unterstützt. Bitte den Agent aktualisieren.",
+ "error.all_check_types_disabled": "Lass mindestens einen Check-Typ eingeschaltet.",
"error.already_assigned": "Das Mitglied hat diese Rolle bereits.",
"error.already_member": "Diese Person ist bereits Mitglied.",
"error.channel_test_failed": "Die Testbenachrichtigung konnte nicht zugestellt werden.",
"error.channel_type_immutable": "Der Typ eines Kanals kann nicht geändert werden.",
+ "error.check_type_disabled": "Dieser Check-Typ ist auf dieser Installation abgeschaltet.",
"error.confirmation_failed": "Die Bestätigung stimmt nicht.",
"error.domain_not_verified": "Der TXT-Eintrag wurde noch nicht gefunden. DNS-Änderungen brauchen manchmal etwas Zeit.",
"error.domain_taken": "Diese Domain nutzt bereits eine andere Statuspage.",
diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json
index b110005..1d0e8b4 100644
--- a/internal/i18n/locales/en.json
+++ b/internal/i18n/locales/en.json
@@ -1,4 +1,6 @@
{
+ "admin.check_types": "Check types",
+ "admin.check_types_intro": "Switch off types this installation cannot offer, such as Docker on shared cloud checkers or ICMP without the needed privileges. They disappear for new monitors; existing monitors keep running.",
"admin.intro": "Regions, checkers and status page servers created here are shared by every organization. Organizations add their own under Regions & checkers.",
"admin.title": "Platform administration",
"agents.create": "Create agent",
@@ -65,6 +67,7 @@
"audit.action.org.policy_update": "Security policy changed",
"audit.action.platform.agent_create": "Platform agent created",
"audit.action.platform.agent_delete": "Platform agent revoked",
+ "audit.action.platform.check_types_update": "Check types changed",
"audit.action.platform.legal_update": "Platform legal document changed",
"audit.action.platform.region_create": "Platform region created",
"audit.action.platform.region_delete": "Platform region deleted",
@@ -221,10 +224,12 @@
"email.test.body": "This is a test. If you can read it, the channel works.",
"email.test.subject": "Test notification from UptimeSebi",
"error.agent_protocol_unsupported": "This agent version is not supported by the API. Please update the agent.",
+ "error.all_check_types_disabled": "Leave at least one check type on.",
"error.already_assigned": "The member already has this role.",
"error.already_member": "This person is already a member.",
"error.channel_test_failed": "The test notification could not be delivered.",
"error.channel_type_immutable": "The type of a channel cannot be changed.",
+ "error.check_type_disabled": "This check type is switched off on this installation.",
"error.confirmation_failed": "The confirmation does not match.",
"error.domain_not_verified": "The TXT record was not found yet. DNS changes can take a while to appear.",
"error.domain_taken": "This domain is already used by another status page.",
diff --git a/internal/migrations/sql/00036_platform_settings.sql b/internal/migrations/sql/00036_platform_settings.sql
new file mode 100644
index 0000000..5f559e5
--- /dev/null
+++ b/internal/migrations/sql/00036_platform_settings.sql
@@ -0,0 +1,17 @@
+-- +goose Up
+-- Settings of the whole installation, changed by platform admins.
+CREATE TABLE platform_settings (
+ key text PRIMARY KEY,
+ value jsonb NOT NULL,
+ updated_at timestamptz NOT NULL DEFAULT now()
+);
+
+ALTER TABLE platform_settings ENABLE ROW LEVEL SECURITY;
+ALTER TABLE platform_settings FORCE ROW LEVEL SECURITY;
+-- Every organization may read them; they say what the installation offers.
+CREATE POLICY platform_settings_read ON platform_settings FOR SELECT USING (true);
+CREATE POLICY platform_settings_write ON platform_settings FOR ALL
+ USING (app_scope_system()) WITH CHECK (app_scope_system());
+
+-- +goose Down
+DROP TABLE platform_settings;
diff --git a/internal/store/models.go b/internal/store/models.go
index 8b4c96a..939b502 100644
--- a/internal/store/models.go
+++ b/internal/store/models.go
@@ -264,6 +264,12 @@ type Org struct {
ApiTokenMaxDays *int32
}
+type PlatformSetting struct {
+ Key string
+ Value []byte
+ UpdatedAt time.Time
+}
+
type RecoveryCode struct {
UserID uuid.UUID
CodeHash []byte
diff --git a/internal/store/platform_settings.sql.go b/internal/store/platform_settings.sql.go
new file mode 100644
index 0000000..afd6473
--- /dev/null
+++ b/internal/store/platform_settings.sql.go
@@ -0,0 +1,36 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.31.1
+// source: platform_settings.sql
+
+package store
+
+import (
+ "context"
+)
+
+const getPlatformSetting = `-- name: GetPlatformSetting :one
+SELECT value FROM platform_settings WHERE key = $1
+`
+
+func (q *Queries) GetPlatformSetting(ctx context.Context, key string) ([]byte, error) {
+ row := q.db.QueryRow(ctx, getPlatformSetting, key)
+ var value []byte
+ err := row.Scan(&value)
+ return value, err
+}
+
+const setPlatformSetting = `-- name: SetPlatformSetting :exec
+INSERT INTO platform_settings (key, value) VALUES ($1, $2)
+ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = now()
+`
+
+type SetPlatformSettingParams struct {
+ Key string
+ Value []byte
+}
+
+func (q *Queries) SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error {
+ _, err := q.db.Exec(ctx, setPlatformSetting, arg.Key, arg.Value)
+ return err
+}
diff --git a/internal/store/querier.go b/internal/store/querier.go
index 985cbb6..296132d 100644
--- a/internal/store/querier.go
+++ b/internal/store/querier.go
@@ -112,6 +112,7 @@ type Querier interface {
GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error)
GetOrg(ctx context.Context, id uuid.UUID) (Org, error)
GetOrgBySlug(ctx context.Context, slug string) (Org, error)
+ GetPlatformSetting(ctx context.Context, key string) ([]byte, error)
GetRegion(ctx context.Context, id uuid.UUID) (Region, error)
GetRole(ctx context.Context, id uuid.UUID) (Role, error)
GetSSOProvider(ctx context.Context, id uuid.UUID) (SsoProvider, error)
@@ -239,6 +240,7 @@ type Querier interface {
ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error)
ScrubAuditEmail(ctx context.Context, email string) error
SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error
+ SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error
// Changing the domain drops a previous verification.
SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error)
SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error)
diff --git a/internal/store/queries/platform_settings.sql b/internal/store/queries/platform_settings.sql
new file mode 100644
index 0000000..0576a97
--- /dev/null
+++ b/internal/store/queries/platform_settings.sql
@@ -0,0 +1,6 @@
+-- name: GetPlatformSetting :one
+SELECT value FROM platform_settings WHERE key = $1;
+
+-- name: SetPlatformSetting :exec
+INSERT INTO platform_settings (key, value) VALUES ($1, $2)
+ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = now();
diff --git a/internal/web/monitors.templ b/internal/web/monitors.templ
index 7101e77..08b44f9 100644
--- a/internal/web/monitors.templ
+++ b/internal/web/monitors.templ
@@ -492,6 +492,8 @@ type MonitorForm struct {
Matchers []MatcherRow
StaleHours int
DB DBForm
+ // Types are the check types to offer.
+ Types []string
}
// DBForm holds the settings of database checks. The password is never
@@ -588,7 +590,7 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
@regionsBody(v)
+ @checkTypesSection(checkTypes)
@storageSection(storage)
}
}
+
+// CheckTypeOption is a check type in the admin panel.
+type CheckTypeOption struct {
+ Type string
+ Enabled bool
+}
+
+templ checkTypesSection(types []CheckTypeOption) {
+
+ @sectionHeading("admin.check_types")
+ { i18n.T(ctx, "admin.check_types_intro") }
+
+
+}
diff --git a/internal/web/regions_templ.go b/internal/web/regions_templ.go
index 3e2f813..efa5798 100644
--- a/internal/web/regions_templ.go
+++ b/internal/web/regions_templ.go
@@ -696,7 +696,7 @@ func RegionsPage(p Page, me Me, v RegionsView) templ.Component {
})
}
-func AdminPage(p Page, me Me, v RegionsView, storage StorageView) templ.Component {
+func AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@@ -763,6 +763,10 @@ func AdminPage(p Page, me Me, v RegionsView, storage StorageView) templ.Componen
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+ templ_7745c5c3_Err = checkTypesSection(checkTypes).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
templ_7745c5c3_Err = storageSection(storage).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
@@ -777,4 +781,123 @@ func AdminPage(p Page, me Me, v RegionsView, storage StorageView) templ.Componen
})
}
+// CheckTypeOption is a check type in the admin panel.
+type CheckTypeOption struct {
+ Type string
+ Enabled bool
+}
+
+func checkTypesSection(types []CheckTypeOption) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
+ return templ_7745c5c3_CtxErr
+ }
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ ctx = templ.ClearChildren(ctx)
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = sectionHeading("admin.check_types").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var42 string
+ templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "admin.check_types_intro"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 168, Col: 77}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
var _ = templruntime.GeneratedTemplate
--
2.54.1