package web import ( "context" "strconv" "strings" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" ) // RegionStatus is the latest result of one region. type RegionStatus struct { Name string Status Status Detail string } // MonitorRow is a monitor on the dashboard. type MonitorRow struct { ID string GroupID string Name string Type string Target string Status Status Regions []RegionStatus Latency string Uptime string Bars []Bar } // GroupNode is a monitor group with its monitors and subgroups. type GroupNode struct { ID string Name string Status Status Total int Monitors []MonitorRow Children []GroupNode } // GroupOption is a group in a select; Label is indented by depth. type GroupOption struct { ID string Label string } // DashboardView is the data of the monitor list. Root holds ungrouped // monitors and the top-level groups. type DashboardView struct { Root GroupNode Empty bool CanWrite bool Counts map[Status]int Range string Ranges []RangeOption } // RangeOption is an entry of the range switcher. Disabled ranges are not // yet covered by enough data. type RangeOption struct { Key string Active bool URL string Disabled bool } // SLAEntry is one window of the SLA table. Partial windows are less than // half covered by data. type SLAEntry struct { Label string Value string Partial bool } // RegionHistory is one region's view of a monitor in the selected range. type RegionHistory struct { Name string Uptime string Bars []Bar // Enough is false when the region reported for less than half the range. Enough bool } templ rangeSwitch(opts []RangeOption) { } templ statusDot(s Status) { } templ bars(bs []Bar, height int) { } templ Dashboard(p Page, me Me, v DashboardView) { @consoleShell(p, me) {
{ i18n.T(ctx, "console.monitors.empty") }
} else {{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }
}{ i18n.T(ctx, "groups.manage") }
} } templ monitorList(ms []MonitorRow) { if len(ms) > 0 {← { i18n.T(ctx, "console.monitors.title") }
{ i18n.T(ctx, "monitors.type_"+v.Row.Type) } if v.Row.Target != "" { { " · " + v.Row.Target } } { " · " + v.Interval }
{ i18n.T(ctx, "monitors.by_region_hint") }
| { r.Time } | { r.Region } | @checkerCell(r.Checker) | if r.OK { ● } else { ● } | { r.Latency } | { r.Detail } if r.EvidenceURL != "" { { i18n.T(ctx, "evidence.show") } } |
{ strings.Join(r.Cause, " · ") }
}{ i18n.T(ctx, "incidents.none") }
} else { @incidentList(rows, true) } } } // RegionOption is a selectable region in the monitor form. type RegionOption struct { ID string Name string Own bool Checked bool Live int64 } // MonitorForm is the data of the monitor editor; ID is empty for new ones. type MonitorForm struct { ID string Name string Type string Target string IntervalSeconds int TimeoutMS int Confirmations int Enabled bool GroupID string Groups []GroupOption // TopLevel is set when the monitor may live outside any group. TopLevel bool Regions []RegionOption MinInterval int // Type-specific settings. Method string ExpectStatus string Keyword string KeywordAbsent bool FollowRedirects bool VerifyTLS bool DNSRecord string DNSResolver string DNSExpect string TLSMinDays int TLSServerName string GraceSeconds int // Headers are "Name: value" lines, shared by HTTP and JSON checks. Headers string JSONMethod string JSONBody string JSONExpect string JSONVerify bool Assertions []AssertionRow PromQuery string PromOp string PromThreshold string PromMode string PromEmptyOK bool PromVerify bool 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 // filled in; PasswordSet tells the form one is stored. type DBForm struct { User string Database string TLS string Query string Expect string PasswordSet bool } // MatcherRow is one label matcher of an alertmanager monitor. type MatcherRow struct { Label string Op string Value string } // MatcherOps are Prometheus' label matching operators. var MatcherOps = []string{"=", "!=", "=~", "!~"} // AssertionRow is one condition of a JSON check; unused rows are empty. type AssertionRow struct { Path string Op string Value string } // AssertionOps are offered in the JSON check form. var AssertionOps = []string{"==", "!=", ">", ">=", "<", "<=", "contains", "exists", "absent"} templ headersField(value string) { } templ typeFields(typ, current string) { } templ numberField(label, name string, value, min, max int, hint string) { } templ MonitorEditor(p Page, me Me, f MonitorForm) { @consoleShell(p, me) {if f.ID == "" { ← { i18n.T(ctx, "console.monitors.title") } } else { ← { f.Name } }
{ i18n.T(ctx, "error.email_not_configured") }
}{ i18n.T(ctx, "channels.service_intro") }
← { i18n.T(ctx, "console.monitors.title") }
@settingsHeading("groups.title", "groups.intro") if len(v.Groups) > 0 {{ i18n.T(ctx, "monitors.ping_intro") }
{ "curl -fsS -m 10 --retry 3 " + url + "\n" }{ "curl -fsS -m 10 --retry 3 --data-raw \"$output\" " + url + "/fail" }
{ i18n.T(ctx, "monitors.ping_secret") }
{ i18n.T(ctx, "monitors.db_hint") }
if typ != "redis" { @valueField(i18n.T(ctx, "monitors.db_user"), "config.user", d.User, "", false) } else { @valueField(i18n.T(ctx, "monitors.db_user_redis"), "config.user", d.User, "", false) } @valueField(i18n.T(ctx, "monitors.db_database_"+typ), "config.database", d.Database, "", false) if typ != "redis" && typ != "mongodb" { @valueField(i18n.T(ctx, "monitors.db_expect"), "config.expect", d.Expect, "", false) } }