feat(console): sort the monitor list and put monitors in an order of one's own
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m49s
ci / test (pull_request) Successful in 14m39s
ci / build (pull_request) Canceled after 14m22s
ci / image (pull_request) Canceled after 0s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m49s
ci / test (pull_request) Successful in 14m39s
ci / build (pull_request) Canceled after 14m22s
ci / image (pull_request) Canceled after 0s
The monitor list gets a sort switcher: the organization's own order, by default, or by name, status (problems first), uptime (worst first) or latency (slowest first). The choice is remembered in a cookie; paging follows it. "Arrange monitors" shows the whole tree with each group's monitors to drag, or move with up and down, into the order wanted; every change is saved at once through PUT /api/v1/org/monitors/order, which needs write access to every monitor given and is audited. Monitors without a position follow the positioned ones, by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
ca852c8299
commit
b0d4bcc002
16 files changed
+3389
-2653
No files matched your search
@@ -90,6 +90,9 @@ var endpoints = []endpoint{
|
||||
{method: "POST", path: "/api/v1/org/monitors", tag: "Monitors", summary: "Create a monitor",
|
||||
description: "`type` is one of http, json, prometheus, tcp, tls, dns, icmp, postgres, mysql, mssql, mongodb, redis, mqtt, kafka, rabbitmq, grpc, smtp, radius, snmp, steam, minecraft, docker, heartbeat or alertmanager (GET /api/v1/org/check-types lists those offered); `config` depends on it (see HTTPConfig, JSONConfig, PrometheusConfig, DNSConfig, TLSConfig, DBConfig, BrokerConfig, GRPCConfig, SMTPConfig, RADIUSConfig, SNMPConfig, GameConfig, DockerConfig, HeartbeatConfig, AlertmanagerConfig). Passwords, RADIUS secrets and SNMP communities are stored encrypted and never returned: `secrets_set` names those set, and an update that leaves one empty keeps it. Heartbeat and alertmanager monitors take neither target nor regions; heartbeats return their `ping_url`. Omit `alert_group_ids` to assign the default alert group; an empty array disables notifications.",
|
||||
perm: "monitors.write", req: monitorRequest{}, status: http.StatusCreated, resp: monitorView{}},
|
||||
{method: "PUT", path: "/api/v1/org/monitors/order", tag: "Monitors", summary: "Put monitors in the organization's own order", perm: "monitors.write",
|
||||
description: "Positions follow the order of monitor_ids, usually the monitors of one group; the monitor list sorted by its own order shows positioned monitors first, the rest by name. Needs write access to every monitor given.",
|
||||
req: monitorOrderRequest{}},
|
||||
{method: "PUT", path: "/api/v1/org/monitors/:id", tag: "Monitors", summary: "Change a monitor", perm: "monitors.write",
|
||||
description: "Omitting alert_group_ids preserves existing assignments; an empty array removes all alert groups.",
|
||||
req: monitorRequest{}, resp: monitorView{}},
|
||||
|
||||
@@ -64,6 +64,7 @@ var auditActions = map[string]string{
|
||||
"PUT /api/v1/org/policy": "org.policy_update",
|
||||
"POST /api/v1/org/monitors": "monitor.create",
|
||||
"PUT /api/v1/org/monitors/:id": "monitor.update",
|
||||
"PUT /api/v1/org/monitors/order": "monitor.order",
|
||||
"DELETE /api/v1/org/monitors/:id": "monitor.delete",
|
||||
"POST /api/v1/org/alertmanager/receivers": "alertmanager.receiver_create",
|
||||
"DELETE /api/v1/org/alertmanager/receivers/:id": "alertmanager.receiver_delete",
|
||||
|
||||
+85
-15
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -79,10 +80,10 @@ func (s *Server) dashboard(c *gin.Context) {
|
||||
}
|
||||
v.Root = buildGroupNodes(data.tree, data.rows)
|
||||
v.Empty = len(data.rows) == 0 && len(v.Root.Children) == 0
|
||||
v.CanWrite = writableAnywhere(p, data.tree)
|
||||
if !s.dashboardPage(c, &v, data) {
|
||||
return
|
||||
}
|
||||
v.CanWrite = writableAnywhere(p, data.tree)
|
||||
v.Range = data.rng.Key
|
||||
var earliest time.Time
|
||||
for _, m := range data.byID {
|
||||
@@ -113,14 +114,64 @@ const groupMonitorsShown = 50
|
||||
// ungrouped names the pseudo-group of monitors outside any group.
|
||||
const ungrouped = "none"
|
||||
|
||||
func monitorKey(m web.MonitorRow) cursor {
|
||||
id, _ := uuid.Parse(m.ID)
|
||||
return cursor{S: strings.ToLower(m.Name), ID: id}
|
||||
// monitorSort is an order of the monitor list: the organization's own,
|
||||
// or by name, status (problems first), uptime (worst first) or latency
|
||||
// (slowest first). Monitors without a position or data come last.
|
||||
type monitorSort string
|
||||
|
||||
var monitorSorts = []monitorSort{"custom", "name", "status", "uptime", "latency"}
|
||||
|
||||
const sortCookie = "monitor_sort"
|
||||
|
||||
// sortOf returns the order asked for, remembering it in a cookie, or the
|
||||
// one remembered, or the organization's own.
|
||||
func sortOf(c *gin.Context) monitorSort {
|
||||
if q := monitorSort(c.Query("sort")); slices.Contains(monitorSorts, q) {
|
||||
c.SetSameSite(http.SameSiteLaxMode)
|
||||
c.SetCookie(sortCookie, string(q), 365*24*3600, "/", "", c.Request.TLS != nil, true)
|
||||
return q
|
||||
}
|
||||
if v, err := c.Cookie(sortCookie); err == nil && slices.Contains(monitorSorts, monitorSort(v)) {
|
||||
return monitorSort(v)
|
||||
}
|
||||
return "custom"
|
||||
}
|
||||
|
||||
func sortMonitors(ms []web.MonitorRow) {
|
||||
// key orders m by o as a string, so pages can continue after it.
|
||||
func (o monitorSort) key(m web.MonitorRow) cursor {
|
||||
id, _ := uuid.Parse(m.ID)
|
||||
name := strings.ToLower(m.Name)
|
||||
var k string
|
||||
switch o {
|
||||
case "name":
|
||||
k = name
|
||||
case "status":
|
||||
k = fmt.Sprintf("%d|%s", statusRank[m.Status], name)
|
||||
case "uptime":
|
||||
if m.Ratio < 0 {
|
||||
k = "1|" + name
|
||||
} else {
|
||||
k = fmt.Sprintf("0|%.9f|%s", m.Ratio, name)
|
||||
}
|
||||
case "latency":
|
||||
if m.LatencyMS < 0 {
|
||||
k = "1|" + name
|
||||
} else {
|
||||
k = fmt.Sprintf("0|%010d|%s", math.MaxInt32-m.LatencyMS, name)
|
||||
}
|
||||
default:
|
||||
if m.Position < 0 {
|
||||
k = "1|" + name
|
||||
} else {
|
||||
k = fmt.Sprintf("0|%010d|%s", m.Position, name)
|
||||
}
|
||||
}
|
||||
return cursor{S: k, ID: id}
|
||||
}
|
||||
|
||||
func (o monitorSort) sort(ms []web.MonitorRow) {
|
||||
slices.SortFunc(ms, func(a, b web.MonitorRow) int {
|
||||
ka, kb := monitorKey(a), monitorKey(b)
|
||||
ka, kb := o.key(a), o.key(b)
|
||||
if c := strings.Compare(ka.S, kb.S); c != 0 {
|
||||
return c
|
||||
}
|
||||
@@ -135,7 +186,7 @@ var dashboardStatuses = []web.Status{web.StatusUp, web.StatusDegraded, web.Statu
|
||||
// value is empty, keeping the search and range but not the page.
|
||||
func dashboardURL(c *gin.Context, key, value string) string {
|
||||
q := url.Values{}
|
||||
for _, k := range []string{"q", "range", "status"} {
|
||||
for _, k := range []string{"q", "range", "status", "arrange"} {
|
||||
if v := c.Query(k); v != "" {
|
||||
q.Set(k, v)
|
||||
}
|
||||
@@ -176,6 +227,20 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
order := sortOf(c)
|
||||
v.Sort = string(order)
|
||||
for _, o := range monitorSorts {
|
||||
v.Sorts = append(v.Sorts, web.SortOption{Key: string(o), Active: o == order, URL: dashboardURL(c, "sort", string(o))})
|
||||
}
|
||||
// Arranging by hand shows the whole tree in the organization's order.
|
||||
arranging := order == "custom" && v.CanWrite && c.Query("q") == "" && c.Query("status") == "" && c.Query("group") == ""
|
||||
v.Arrange = arranging && c.Query("arrange") == "1"
|
||||
if arranging {
|
||||
v.ArrangeURL = dashboardURL(c, "arrange", "1")
|
||||
if v.Arrange {
|
||||
v.ArrangeURL = dashboardURL(c, "arrange", "")
|
||||
}
|
||||
}
|
||||
link := func(group string) string {
|
||||
q := url.Values{"group": {group}}
|
||||
if r := c.Query("range"); r != "" {
|
||||
@@ -185,8 +250,8 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
||||
}
|
||||
var capNode func(n *web.GroupNode)
|
||||
capNode = func(n *web.GroupNode) {
|
||||
sortMonitors(n.Monitors)
|
||||
if len(n.Monitors) > groupMonitorsShown {
|
||||
order.sort(n.Monitors)
|
||||
if len(n.Monitors) > groupMonitorsShown && !v.Arrange {
|
||||
n.More = len(n.Monitors) - groupMonitorsShown
|
||||
n.Monitors = n.Monitors[:groupMonitorsShown]
|
||||
n.MoreURL = link(cmp.Or(n.ID, ungrouped))
|
||||
@@ -213,8 +278,8 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
||||
hits = append(hits, m)
|
||||
}
|
||||
}
|
||||
sortMonitors(hits)
|
||||
v.Results, info = pageSlice(hits, pg, monitorKey)
|
||||
order.sort(hits)
|
||||
v.Results, info = pageSlice(hits, pg, order.key)
|
||||
case group != "":
|
||||
var focus web.GroupNode
|
||||
found := false
|
||||
@@ -239,8 +304,8 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
||||
c.Redirect(http.StatusSeeOther, "/")
|
||||
return false
|
||||
}
|
||||
sortMonitors(focus.Monitors)
|
||||
focus.Monitors, info = pageSlice(focus.Monitors, pg, monitorKey)
|
||||
order.sort(focus.Monitors)
|
||||
focus.Monitors, info = pageSlice(focus.Monitors, pg, order.key)
|
||||
for i := range focus.Children {
|
||||
capNode(&focus.Children[i])
|
||||
}
|
||||
@@ -448,7 +513,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
||||
continue
|
||||
}
|
||||
d.byID[m.ID] = m
|
||||
row := web.MonitorRow{ID: m.ID.String(), Name: m.Name, Type: m.Type, Target: m.Target, Latency: "–", Uptime: "–"}
|
||||
row := web.MonitorRow{ID: m.ID.String(), Name: m.Name, Type: m.Type, Target: m.Target, Latency: "–", Uptime: "–", Position: -1, LatencyMS: -1}
|
||||
if m.Position != nil {
|
||||
row.Position = int(*m.Position)
|
||||
}
|
||||
keys := idStrings(regionsOf[m.ID])
|
||||
if check.Passive(check.Type(m.Type)) {
|
||||
// The target of a heartbeat is its secret ping token.
|
||||
@@ -509,8 +577,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
||||
sum += l
|
||||
}
|
||||
row.Latency = fmt.Sprintf("%d ms", sum/int32(len(latencies)))
|
||||
row.LatencyMS = int(sum / int32(len(latencies)))
|
||||
}
|
||||
row.Uptime = web.SLAText(d.slaFor(m, rng.Window))
|
||||
row.Ratio = d.slaFor(m, rng.Window)
|
||||
row.Uptime = web.SLAText(row.Ratio)
|
||||
row.Bars = web.UptimeBars(d.buckets[m.ID], now, rng.Bucket, rng.Bars(), rng.Layout)
|
||||
d.rows = append(d.rows, row)
|
||||
}
|
||||
|
||||
@@ -83,3 +83,69 @@ func TestPageEditorOffersAddAndRemoveAll(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMonitorOrder(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
_, region := e.platformChecker(t, uniq("eu-"))
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("ord")+".test", uniq("ord-"))
|
||||
ids := map[string]string{}
|
||||
for _, n := range []string{"Alpha", "Bravo", "Charlie"} {
|
||||
_, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": n, "type": "http", "target": "https://" + strings.ToLower(n) + ".test", "interval_seconds": 60, "regions": []string{region}})
|
||||
ids[n] = m["id"].(string)
|
||||
}
|
||||
order := func(html string, names ...string) bool {
|
||||
last := -1
|
||||
for _, n := range names {
|
||||
i := strings.Index(html, ">"+n+"<")
|
||||
if i < last || i < 0 {
|
||||
return false
|
||||
}
|
||||
last = i
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Without an order of its own, by name.
|
||||
if _, _, html := owner.page("/"); !order(html, "Alpha", "Bravo", "Charlie") {
|
||||
t.Error("monitors without positions are not by name")
|
||||
}
|
||||
st, body := owner.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Charlie"], ids["Alpha"]}})
|
||||
if st != http.StatusNoContent {
|
||||
t.Fatalf("order = %d %v", st, body)
|
||||
}
|
||||
// Positioned ones first, in their order; the rest after, by name.
|
||||
_, _, html := owner.page("/")
|
||||
if !order(html, "Charlie", "Alpha", "Bravo") {
|
||||
t.Error("the list does not follow the organization's order")
|
||||
}
|
||||
if !strings.Contains(html, "?arrange=1") || !strings.Contains(html, "?sort=name") {
|
||||
t.Error("the dashboard offers neither arranging nor sorting")
|
||||
}
|
||||
if _, _, arr := owner.page("/?arrange=1"); !strings.Contains(arr, `data-sortable="/org/monitors/order"`) || !strings.Contains(arr, `data-sort-id="`+ids["Charlie"]+`"`) {
|
||||
t.Error("arranging does not show the sortable list")
|
||||
}
|
||||
|
||||
// Sorting by name is remembered until changed.
|
||||
if _, _, byName := owner.page("/?sort=name"); !order(byName, "Alpha", "Bravo", "Charlie") {
|
||||
t.Error("?sort=name does not sort by name")
|
||||
}
|
||||
if _, _, again := owner.page("/"); !order(again, "Alpha", "Bravo", "Charlie") || strings.Contains(again, "?arrange=1") {
|
||||
t.Error("the sort order is not remembered, or arranging is offered outside the own order")
|
||||
}
|
||||
owner.page("/?sort=custom")
|
||||
|
||||
// Unknown and duplicate monitors are refused, and nothing changes.
|
||||
st, body = owner.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Bravo"], "00000000-0000-0000-0000-000000000001"}})
|
||||
expect(t, "unknown monitor", st, body, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||
st, body = owner.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Bravo"], ids["Bravo"]}})
|
||||
expect(t, "duplicate monitor", st, body, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||
if _, _, html := owner.page("/"); !order(html, "Charlie", "Alpha", "Bravo") {
|
||||
t.Error("a refused order changed the list")
|
||||
}
|
||||
// Another organization cannot touch them.
|
||||
other := e.browser(t)
|
||||
other.signup("x@"+uniq("ord")+".test", uniq("ord-"))
|
||||
st, body = other.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Alpha"]}})
|
||||
expect(t, "another organization's monitor", st, body, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
)
|
||||
|
||||
type monitorOrderRequest struct {
|
||||
// MonitorIDs in the order wanted; usually the monitors of one group.
|
||||
MonitorIDs []uuid.UUID `json:"monitor_ids" binding:"required,min=1,max=1000"`
|
||||
}
|
||||
|
||||
// orderMonitors stores the organization's own order of the monitors given,
|
||||
// which the monitor list follows when sorted by its own order. It needs
|
||||
// write access to every one of them.
|
||||
func (s *Server) orderMonitors(c *gin.Context) {
|
||||
var req monitorOrderRequest
|
||||
if !bind(c, &req) {
|
||||
return
|
||||
}
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
t, err := s.loadGroupTree(ctx, p.scope())
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
errDenied := errors.New("denied")
|
||||
seen := map[uuid.UUID]bool{}
|
||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||
for i, id := range req.MonitorIDs {
|
||||
if seen[id] {
|
||||
return pgx.ErrNoRows
|
||||
}
|
||||
seen[id] = true
|
||||
m, err := q.GetMonitor(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !canInGroup(p, authz.MonitorsWrite, t, m.GroupID) {
|
||||
return errDenied
|
||||
}
|
||||
if _, err := q.SetMonitorPosition(ctx, store.SetMonitorPositionParams{ID: id, Position: new(int32(i))}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
switch {
|
||||
case errors.Is(err, errDenied):
|
||||
fail(c, http.StatusForbidden, "forbidden")
|
||||
case errors.Is(err, pgx.ErrNoRows):
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||
case err != nil:
|
||||
internalError(c, err)
|
||||
default:
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,7 @@ func (s *Server) Mount(r gin.IRouter) {
|
||||
// scoped to a group grant access below that group only.
|
||||
org.GET("/monitors", s.listMonitors)
|
||||
org.POST("/monitors", s.createMonitor)
|
||||
org.PUT("/monitors/order", s.orderMonitors)
|
||||
org.PUT("/monitors/:id", s.updateMonitor)
|
||||
org.DELETE("/monitors/:id", s.deleteMonitor)
|
||||
org.GET("/monitors/:id/evidence", s.listEvidence)
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
"audit.action.member.role_unassign": "Rolle entzogen",
|
||||
"audit.action.monitor.create": "Monitor erstellt",
|
||||
"audit.action.monitor.delete": "Monitor gelöscht",
|
||||
"audit.action.monitor.order": "Monitore angeordnet",
|
||||
"audit.action.monitor.update": "Monitor geändert",
|
||||
"audit.action.org.check_types_update": "Check-Typen geändert",
|
||||
"audit.action.org.create": "Organisation angelegt",
|
||||
@@ -1021,6 +1022,9 @@
|
||||
"monitors.alertmanager_hint": "Ausgefallen, solange ein Alert feuert, der alle Matcher erfüllt. Alerts kommen über einen Empfänger:",
|
||||
"monitors.all": "Alle Monitore",
|
||||
"monitors.all_results": "Alle Ergebnisse",
|
||||
"monitors.arrange": "Monitore anordnen",
|
||||
"monitors.arrange_done": "Anordnen beenden",
|
||||
"monitors.arrange_hint": "Zieh die Monitore oder verschieb sie mit ↑ und ↓ in die gewünschte Reihenfolge innerhalb ihrer Gruppe. Jede Änderung wird sofort gespeichert und gilt für alle in der Organisation.",
|
||||
"monitors.assertion_op": "Operator",
|
||||
"monitors.assertion_path": "Pfad",
|
||||
"monitors.assertion_value": "Wert",
|
||||
@@ -1099,6 +1103,8 @@
|
||||
"monitors.minecraft_edition": "Edition",
|
||||
"monitors.minecraft_hint": "Ziel ist host:port (Java meist 25565, Bedrock 19132). Pingt den Server wie die Serverliste im Spiel.",
|
||||
"monitors.minecraft_java": "Java Edition",
|
||||
"monitors.move_down": "{{.Name}} nach unten",
|
||||
"monitors.move_up": "{{.Name}} nach oben",
|
||||
"monitors.new": "Neuer Monitor",
|
||||
"monitors.no_data_since": "keine Daten seit {{.Time}}",
|
||||
"monitors.no_match": "Kein Monitor gefunden.",
|
||||
@@ -1154,6 +1160,12 @@
|
||||
"monitors.snmp_oid": "OID",
|
||||
"monitors.snmp_value": "Wert",
|
||||
"monitors.snmp_version": "Version",
|
||||
"monitors.sort": "Sortierung",
|
||||
"monitors.sort_custom": "eigene Reihenfolge",
|
||||
"monitors.sort_latency": "Latenz",
|
||||
"monitors.sort_name": "Name",
|
||||
"monitors.sort_status": "Status",
|
||||
"monitors.sort_uptime": "Uptime",
|
||||
"monitors.stale_hours": "Verfällt nach (Stunden)",
|
||||
"monitors.stale_hours_hint": "Ein feuernder Alert, den Alertmanager nicht mehr wiederholt, gilt nach dieser Zeit als beendet. Halte sie über repeat_interval.",
|
||||
"monitors.steam_hint": "Ziel ist host:port des Query-Ports (meist der Spielport, z. B. 27015). Fragt den Server wie der Steam-Serverbrowser nach seinen Infos (A2S); funktioniert für Source- und die meisten Steam-Spiele.",
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
"audit.action.member.role_unassign": "Role removed",
|
||||
"audit.action.monitor.create": "Monitor created",
|
||||
"audit.action.monitor.delete": "Monitor deleted",
|
||||
"audit.action.monitor.order": "Monitors put in order",
|
||||
"audit.action.monitor.update": "Monitor changed",
|
||||
"audit.action.org.check_types_update": "Check types changed",
|
||||
"audit.action.org.create": "Organization created",
|
||||
@@ -1021,6 +1022,9 @@
|
||||
"monitors.alertmanager_hint": "Down while an alert matching all matchers fires. Alerts arrive through a receiver:",
|
||||
"monitors.all": "All monitors",
|
||||
"monitors.all_results": "All results",
|
||||
"monitors.arrange": "Arrange monitors",
|
||||
"monitors.arrange_done": "Done arranging",
|
||||
"monitors.arrange_hint": "Drag the monitors, or move them with ↑ and ↓, into the order you want within each group. Every change is saved at once and is the same for everybody in the organization.",
|
||||
"monitors.assertion_op": "Operator",
|
||||
"monitors.assertion_path": "Path",
|
||||
"monitors.assertion_value": "Value",
|
||||
@@ -1099,6 +1103,8 @@
|
||||
"monitors.minecraft_edition": "Edition",
|
||||
"monitors.minecraft_hint": "Target is host:port (Java usually 25565, Bedrock 19132). Pings the server like the in-game server list.",
|
||||
"monitors.minecraft_java": "Java Edition",
|
||||
"monitors.move_down": "Move {{.Name}} down",
|
||||
"monitors.move_up": "Move {{.Name}} up",
|
||||
"monitors.new": "New monitor",
|
||||
"monitors.no_data_since": "no data since {{.Time}}",
|
||||
"monitors.no_match": "No monitor matches.",
|
||||
@@ -1154,6 +1160,12 @@
|
||||
"monitors.snmp_oid": "OID",
|
||||
"monitors.snmp_value": "Value",
|
||||
"monitors.snmp_version": "Version",
|
||||
"monitors.sort": "Sort order",
|
||||
"monitors.sort_custom": "own order",
|
||||
"monitors.sort_latency": "latency",
|
||||
"monitors.sort_name": "name",
|
||||
"monitors.sort_status": "status",
|
||||
"monitors.sort_uptime": "uptime",
|
||||
"monitors.stale_hours": "Stale after (hours)",
|
||||
"monitors.stale_hours_hint": "A firing alert Alertmanager stops repeating counts as over after this time. Keep it above repeat_interval.",
|
||||
"monitors.steam_hint": "Target is host:port of the query port (usually the game port, e.g. 27015). Asks the server for its info like the Steam server browser (A2S); works for Source and most Steam games.",
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- +goose Up
|
||||
-- The organization's own order of its monitors on the monitor list, within
|
||||
-- each group; NULL sorts after positioned monitors, by name.
|
||||
ALTER TABLE monitors ADD COLUMN position integer;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE monitors DROP COLUMN position;
|
||||
@@ -257,6 +257,7 @@ type Monitor struct {
|
||||
UpdatedAt time.Time
|
||||
Confirmations int32
|
||||
GroupID *uuid.UUID
|
||||
Position *int32
|
||||
}
|
||||
|
||||
type MonitorAlertGroup struct {
|
||||
|
||||
@@ -58,7 +58,7 @@ func (q *Queries) AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow
|
||||
const createMonitor = `-- name: CreateMonitor :one
|
||||
INSERT INTO monitors (org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, confirmations, group_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position
|
||||
`
|
||||
|
||||
type CreateMonitorParams struct {
|
||||
@@ -102,6 +102,7 @@ func (q *Queries) CreateMonitor(ctx context.Context, arg CreateMonitorParams) (M
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
&i.Position,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -128,7 +129,7 @@ func (q *Queries) DeleteMonitorRegions(ctx context.Context, monitorID uuid.UUID)
|
||||
}
|
||||
|
||||
const getMonitor = `-- name: GetMonitor :one
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors WHERE id = $1
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position FROM monitors WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error) {
|
||||
@@ -148,6 +149,7 @@ func (q *Queries) GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error)
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
&i.Position,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -190,7 +192,7 @@ func (q *Queries) ListEnabledMonitorsForSchedule(ctx context.Context) ([]ListEna
|
||||
}
|
||||
|
||||
const listMonitors = `-- name: ListMonitors :many
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors ORDER BY name
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position FROM monitors ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
||||
@@ -216,6 +218,7 @@ func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
&i.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -228,7 +231,7 @@ func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
||||
}
|
||||
|
||||
const listMonitorsPage = `-- name: ListMonitorsPage :many
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position FROM monitors
|
||||
WHERE true
|
||||
AND ($1::text IS NULL OR (name, id) > ($1, $2::uuid))
|
||||
AND ($3::text IS NULL OR (name, id) < ($3, $4::uuid))
|
||||
@@ -277,6 +280,7 @@ func (q *Queries) ListMonitorsPage(ctx context.Context, arg ListMonitorsPagePara
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
&i.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -313,7 +317,7 @@ func (q *Queries) MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uu
|
||||
}
|
||||
|
||||
const monitorsForJobs = `-- name: MonitorsForJobs :many
|
||||
SELECT m.id, m.org_id, m.name, m.type, m.target, m.interval_seconds, m.timeout_ms, m.config, m.enabled, m.created_at, m.updated_at, m.confirmations, m.group_id FROM monitors m
|
||||
SELECT m.id, m.org_id, m.name, m.type, m.target, m.interval_seconds, m.timeout_ms, m.config, m.enabled, m.created_at, m.updated_at, m.confirmations, m.group_id, m.position FROM monitors m
|
||||
JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = $1
|
||||
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
|
||||
WHERE m.id = ANY ($2::uuid[]) AND m.enabled
|
||||
@@ -352,6 +356,7 @@ func (q *Queries) MonitorsForJobs(ctx context.Context, arg MonitorsForJobsParams
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
&i.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -419,11 +424,28 @@ func (q *Queries) MonitorsForResults(ctx context.Context, arg MonitorsForResults
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setMonitorPosition = `-- name: SetMonitorPosition :execrows
|
||||
UPDATE monitors SET position = $1 WHERE id = $2
|
||||
`
|
||||
|
||||
type SetMonitorPositionParams struct {
|
||||
Position *int32
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) SetMonitorPosition(ctx context.Context, arg SetMonitorPositionParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setMonitorPosition, arg.Position, arg.ID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateMonitor = `-- name: UpdateMonitor :one
|
||||
UPDATE monitors SET name = $2, type = $3, target = $4, interval_seconds = $5,
|
||||
timeout_ms = $6, config = $7, enabled = $8, confirmations = $9, group_id = $10, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position
|
||||
`
|
||||
|
||||
type UpdateMonitorParams struct {
|
||||
@@ -467,6 +489,7 @@ func (q *Queries) UpdateMonitor(ctx context.Context, arg UpdateMonitorParams) (M
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
&i.Position,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -358,6 +358,7 @@ type Querier interface {
|
||||
ServablePages(ctx context.Context, agentOrg *uuid.UUID) ([]ServablePagesRow, error)
|
||||
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
|
||||
SetIncidentTitle(ctx context.Context, arg SetIncidentTitleParams) (int64, error)
|
||||
SetMonitorPosition(ctx context.Context, arg SetMonitorPositionParams) (int64, error)
|
||||
SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error
|
||||
SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error)
|
||||
SetOwner(ctx context.Context, arg SetOwnerParams) (int64, error)
|
||||
|
||||
@@ -72,3 +72,6 @@ ORDER BY
|
||||
CASE WHEN sqlc.narg(before_s)::text IS NULL THEN id END,
|
||||
name DESC, id DESC
|
||||
LIMIT sqlc.arg(max_rows);
|
||||
|
||||
-- name: SetMonitorPosition :execrows
|
||||
UPDATE monitors SET position = sqlc.arg(position) WHERE id = sqlc.arg(id);
|
||||
@@ -178,6 +178,43 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Saves the order of a list of monitors being arranged.
|
||||
const saveOrder = async (list) => {
|
||||
const ids = [...list.querySelectorAll(":scope > [data-sort-id]")].map((li) => li.dataset.sortId);
|
||||
try {
|
||||
await api.put(list.dataset.sortable, { monitor_ids: ids });
|
||||
} catch (err) {
|
||||
alert(message(err));
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
let dragged = null;
|
||||
document.addEventListener("dragstart", (ev) => {
|
||||
const item = ev.target.closest?.("[data-sortable] > [data-sort-id]");
|
||||
if (!item) return;
|
||||
dragged = item;
|
||||
ev.dataTransfer.effectAllowed = "move";
|
||||
item.style.opacity = "0.5";
|
||||
});
|
||||
document.addEventListener("dragover", (ev) => {
|
||||
const over = ev.target.closest?.("[data-sortable] > [data-sort-id]");
|
||||
if (!dragged || !over || over === dragged || over.parentElement !== dragged.parentElement) return;
|
||||
ev.preventDefault();
|
||||
const box = over.getBoundingClientRect();
|
||||
if (ev.clientY < box.top + box.height / 2) over.before(dragged);
|
||||
else over.after(dragged);
|
||||
});
|
||||
document.addEventListener("drop", (ev) => {
|
||||
if (dragged) ev.preventDefault();
|
||||
});
|
||||
document.addEventListener("dragend", async () => {
|
||||
if (!dragged) return;
|
||||
const list = dragged.parentElement;
|
||||
dragged.style.opacity = "";
|
||||
dragged = null;
|
||||
await saveOrder(list);
|
||||
});
|
||||
|
||||
document.addEventListener("click", async (ev) => {
|
||||
const navToggle = ev.target.closest("[data-nav-toggle]");
|
||||
if (navToggle) {
|
||||
@@ -186,6 +223,18 @@
|
||||
navToggle.setAttribute("aria-expanded", String(open));
|
||||
return;
|
||||
}
|
||||
// Moves a monitor up or down while arranging the monitor list.
|
||||
const move = ev.target.closest("[data-sort-move]");
|
||||
if (move) {
|
||||
const item = move.closest("[data-sort-id]");
|
||||
const other = move.dataset.sortMove === "up" ? item.previousElementSibling : item.nextElementSibling;
|
||||
if (!other) return;
|
||||
if (move.dataset.sortMove === "up") other.before(item);
|
||||
else other.after(item);
|
||||
move.focus();
|
||||
await saveOrder(item.closest("[data-sortable]"));
|
||||
return;
|
||||
}
|
||||
// Ticks or clears every checkbox named by data-check-all in its form.
|
||||
const checkAll = ev.target.closest("[data-check-all]");
|
||||
if (checkAll) {
|
||||
|
||||
@@ -31,6 +31,11 @@ type MonitorRow struct {
|
||||
// Unchecked is set when no region has reported recently: nobody is
|
||||
// checking the monitor.
|
||||
Unchecked bool
|
||||
// Position is the organization's own order, -1 when not set; Ratio
|
||||
// the uptime in the range, -1 without data; LatencyMS -1 without data.
|
||||
Position int
|
||||
Ratio float64
|
||||
LatencyMS int
|
||||
}
|
||||
|
||||
// GroupNode is a monitor group with its monitors and subgroups.
|
||||
@@ -72,6 +77,13 @@ type DashboardView struct {
|
||||
Filter Status
|
||||
// AllURL leaves the status filter, keeping the search and range.
|
||||
AllURL string
|
||||
// Sorts switch the order of the list; Sort is the active one.
|
||||
Sorts []SortOption
|
||||
Sort string
|
||||
// Arrange shows the tree for putting monitors in order by hand;
|
||||
// ArrangeURL turns it on or off, empty when not offered.
|
||||
Arrange bool
|
||||
ArrangeURL string
|
||||
Range string
|
||||
Ranges []RangeOption
|
||||
// Unchecked counts the monitors no region has reported for recently.
|
||||
@@ -80,6 +92,13 @@ type DashboardView struct {
|
||||
DeadRegions []DeadRegion
|
||||
}
|
||||
|
||||
// SortOption is an entry of the sort switcher.
|
||||
type SortOption struct {
|
||||
Key string
|
||||
URL string
|
||||
Active bool
|
||||
}
|
||||
|
||||
// StatusFilter is one status count; URL shows only its monitors, or all
|
||||
// again when it is the active filter.
|
||||
type StatusFilter struct {
|
||||
@@ -179,6 +198,7 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
||||
<h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
|
||||
<div class="flex flex-wrap items-center gap-x-5 gap-y-3 font-mono text-xs text-muted">
|
||||
@rangeSwitch(v.Ranges)
|
||||
@sortSwitch(v.Sorts)
|
||||
<nav class="flex flex-wrap items-center gap-x-1 gap-y-2" aria-label={ i18n.T(ctx, "monitors.filter_label") }>
|
||||
for _, f := range v.Filters {
|
||||
<a
|
||||
@@ -266,17 +286,31 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
||||
<span class="font-medium">{ v.Focus }</span>
|
||||
</p>
|
||||
}
|
||||
if v.Arrange {
|
||||
<p class="mb-3 border-l-2 border-ink pl-3 text-sm">{ i18n.T(ctx, "monitors.arrange_hint") }</p>
|
||||
}
|
||||
<div class="border-t border-rule">
|
||||
@monitorList(v.Root.Monitors)
|
||||
@treeList(v.Root.Monitors, v.Arrange)
|
||||
@moreLink(v.Root)
|
||||
for _, g := range v.Root.Children {
|
||||
@groupBlock(g)
|
||||
@groupBlock(g, v.Arrange)
|
||||
}
|
||||
</div>
|
||||
@pager(v.Pager, "previous", "next")
|
||||
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
|
||||
}
|
||||
<p class="mt-8 text-sm"><a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a></p>
|
||||
<p class="mt-8 flex flex-wrap gap-x-6 gap-y-2 text-sm">
|
||||
<a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a>
|
||||
if v.ArrangeURL != "" {
|
||||
<a href={ templ.SafeURL(v.ArrangeURL) } class="text-muted hover:text-ink">
|
||||
if v.Arrange {
|
||||
{ i18n.T(ctx, "monitors.arrange_done") }
|
||||
} else {
|
||||
{ i18n.T(ctx, "monitors.arrange") }
|
||||
}
|
||||
</a>
|
||||
}
|
||||
</p>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +350,7 @@ templ moreLink(g GroupNode) {
|
||||
|
||||
// groupBlock renders a group and, recursively, its subgroups. <details>
|
||||
// makes groups collapsible without JavaScript.
|
||||
templ groupBlock(g GroupNode) {
|
||||
templ groupBlock(g GroupNode, arrange bool) {
|
||||
<details open class="border-b border-rule">
|
||||
<summary class="flex cursor-pointer items-center gap-2.5 py-2.5 text-sm font-medium select-none hover:bg-rule/30">
|
||||
@statusDot(g.Status)
|
||||
@@ -324,10 +358,10 @@ templ groupBlock(g GroupNode) {
|
||||
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(g.Total) }</span>
|
||||
</summary>
|
||||
<div class="ml-4 border-l border-rule pl-4">
|
||||
@monitorList(g.Monitors)
|
||||
@treeList(g.Monitors, arrange)
|
||||
@moreLink(g)
|
||||
for _, c := range g.Children {
|
||||
@groupBlock(c)
|
||||
@groupBlock(c, arrange)
|
||||
}
|
||||
</div>
|
||||
</details>
|
||||
@@ -1639,3 +1673,43 @@ func filterTitle(ctx context.Context, f StatusFilter) string {
|
||||
}
|
||||
return i18n.T(ctx, "monitors.filter_show", "Status", i18n.T(ctx, "status."+string(f.Status)), "Count", f.Count)
|
||||
}
|
||||
|
||||
templ sortSwitch(opts []SortOption) {
|
||||
<nav class="flex min-w-0 max-w-full overflow-x-auto border border-rule font-mono text-xs" aria-label={ i18n.T(ctx, "monitors.sort") }>
|
||||
for _, o := range opts {
|
||||
if o.Active {
|
||||
<span class="whitespace-nowrap bg-ink px-2 py-1 text-paper" aria-current="true">{ i18n.T(ctx, "monitors.sort_"+o.Key) }</span>
|
||||
} else {
|
||||
<a href={ templ.SafeURL(o.URL) } class="whitespace-nowrap px-2 py-1 text-muted hover:text-ink">{ i18n.T(ctx, "monitors.sort_"+o.Key) }</a>
|
||||
}
|
||||
}
|
||||
</nav>
|
||||
}
|
||||
|
||||
// treeList is a group's own monitors, as links or, while arranging, as
|
||||
// rows to put in order.
|
||||
templ treeList(ms []MonitorRow, arrange bool) {
|
||||
if arrange {
|
||||
@arrangeList(ms)
|
||||
} else {
|
||||
@monitorList(ms)
|
||||
}
|
||||
}
|
||||
|
||||
// arrangeList lets monitors be dragged or moved up and down; every change
|
||||
// is saved at once.
|
||||
templ arrangeList(ms []MonitorRow) {
|
||||
if len(ms) > 0 {
|
||||
<ul data-sortable="/org/monitors/order" class="divide-y divide-rule border-b border-rule text-sm">
|
||||
for _, m := range ms {
|
||||
<li data-sort-id={ m.ID } draggable="true" class="flex cursor-move items-center gap-3 py-2.5">
|
||||
<span class="select-none text-muted" aria-hidden="true">⠿</span>
|
||||
@statusDot(m.Status)
|
||||
<span class="min-w-0 flex-1 truncate">{ m.Name }</span>
|
||||
<button type="button" data-sort-move="up" class="px-1.5 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.move_up", "Name", m.Name) } title={ i18n.T(ctx, "monitors.move_up", "Name", m.Name) }>↑</button>
|
||||
<button type="button" data-sort-move="down" class="px-1.5 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.move_down", "Name", m.Name) } title={ i18n.T(ctx, "monitors.move_down", "Name", m.Name) }>↓</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
}
|
||||
+2973
-2626
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user