Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb03b28df7 |
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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(), "")})
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
@@ -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) {
|
||||
|
||||
+20
-14
@@ -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)
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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;
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
@@ -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) {
|
||||
<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", "postgres", "mysql", "mssql", "mongodb", "redis", "heartbeat", "alertmanager"} {
|
||||
for _, t := range f.Types {
|
||||
<option value={ t } selected?={ t == f.Type }>{ i18n.T(ctx, "monitors.type_"+t) }</option>
|
||||
}
|
||||
</select>
|
||||
|
||||
+144
-142
File diff suppressed because it is too large.
Load diff
@@ -143,7 +143,7 @@ templ RegionsPage(p Page, me Me, v RegionsView) {
|
||||
}
|
||||
}
|
||||
|
||||
templ AdminPage(p Page, me Me, v RegionsView, storage StorageView) {
|
||||
templ AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption) {
|
||||
@consoleShell(p, me) {
|
||||
@settingsHeading("admin.title", "admin.intro")
|
||||
<p class="-mt-4 mb-8 flex gap-4 text-sm">
|
||||
@@ -151,6 +151,32 @@ templ AdminPage(p Page, me Me, v RegionsView, storage StorageView) {
|
||||
<a href="/admin/legal" class="underline underline-offset-2">{ i18n.T(ctx, "legal.platform_title") }</a>
|
||||
</p>
|
||||
@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) {
|
||||
<section class="mt-12 max-w-3xl">
|
||||
@sectionHeading("admin.check_types")
|
||||
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "admin.check_types_intro") }</p>
|
||||
<form data-api="/admin/check-types" data-method="put" data-next="/admin">
|
||||
@formError()
|
||||
<div class="mb-4 grid grid-cols-2 gap-x-6 gap-y-1.5 text-sm sm:grid-cols-3">
|
||||
for _, t := range types {
|
||||
<label class="flex items-center gap-2">
|
||||
<input type="checkbox" name="enabled" value={ t.Type } data-multi checked?={ t.Enabled } class="accent-ink"/>
|
||||
{ i18n.T(ctx, "monitors.type_"+t.Type) }
|
||||
</label>
|
||||
}
|
||||
</div>
|
||||
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
|
||||
</form>
|
||||
</section>
|
||||
}
|
||||
@@ -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, "<section class=\"mt-12 max-w-3xl\">")
|
||||
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, "<p class=\"mb-4 text-sm text-muted\">")
|
||||
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, "</p><form data-api=\"/admin/check-types\" data-method=\"put\" data-next=\"/admin\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "<div class=\"mb-4 grid grid-cols-2 gap-x-6 gap-y-1.5 text-sm sm:grid-cols-3\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, t := range types {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "<label class=\"flex items-center gap-2\"><input type=\"checkbox\" name=\"enabled\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var43 string
|
||||
templ_7745c5c3_Var43, templ_7745c5c3_Err = templruntime.NewAttributeExpression(t.Type).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 174, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var43)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "\" data-multi")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if t.Enabled {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, " checked")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, " class=\"accent-ink\"> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var44 string
|
||||
templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.type_"+t.Type))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 175, Col: 44}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "</label>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "</div><button type=\"submit\" class=\"border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var45 string
|
||||
templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 179, Col: 129}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var45))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "</button></form></section>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
Reference in new issue
Block a user