feat(console): install instructions for new agents, outdated agents #136

Merged
Sebi merged 1 commits from feat/agent-console into main 2026-11-23 18:37:09 +00:00
8 changed files with 931 additions and 456 deletions

No files matched your search

+21
View File
@@ -22,6 +22,7 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/schedule"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
)
// AgentTokenPrefix marks agent tokens, distinct from user API tokens.
@@ -148,6 +149,26 @@ func (s *Server) agentUpdate(c *gin.Context) {
c.JSON(http.StatusOK, u)
}
// installView is what the console shows to install a new agent.
func (s *Server) installView() web.InstallView {
v := web.InstallView{
ScriptURL: strings.TrimSuffix(s.cfg.PublicURL, "/") + "/install.sh",
APIURL: strings.TrimSuffix(s.cfg.PublicURL, "/"),
Image: s.cfg.AgentImage,
Channel: agentdeploy.Channel(buildinfo.Version),
Compose: map[string]string{},
}
if buildinfo.Version != "dev" {
v.Release = buildinfo.Version
}
for _, kind := range []string{"checker", "statuspage"} {
if c, err := agentdeploy.Compose(kind); err == nil {
v.Compose[kind] = string(c)
}
}
return v
}
// installScript serves the script that installs a checker or status page
// server with Docker Compose, pointed at this platform.
func (s *Server) installScript(c *gin.Context) {
+3 -2
View File
@@ -628,7 +628,7 @@ func (s *Server) adminOrgsPage(c *gin.Context) {
}
func (s *Server) buildRegionsView(ctx context.Context, regions []store.Region, agents []store.ListAgentsRow, apiBase, next string, manageable func(store.Region) bool) (web.RegionsView, error) {
v := web.RegionsView{APIBase: apiBase, Next: next}
v := web.RegionsView{APIBase: apiBase, Next: next, Install: s.installView()}
never := i18n.T(ctx, "tokens.never")
for _, r := range regions {
n, err := s.sched.Instances(ctx, r.ID.String())
@@ -646,7 +646,8 @@ func (s *Server) buildRegionsView(ctx context.Context, regions []store.Region, a
if a.LastSeenAt != nil {
seen = a.LastSeenAt.Format(time.DateTime)
}
wa := web.Agent{ID: a.ID.String(), Kind: a.Kind, Name: a.Name, Region: deref(a.RegionName), Prefix: a.Prefix, LastSeen: seen}
wa := web.Agent{ID: a.ID.String(), Kind: a.Kind, Name: a.Name, Region: deref(a.RegionName), Prefix: a.Prefix, LastSeen: seen, Release: deref(a.Release)}
wa.Outdated = v.Install.Release != "" && wa.Release != "" && wa.Release != "dev" && wa.Release != v.Install.Release
if a.Kind == "checker" && a.OrgID != nil {
wa.AllowPrivate = &a.AllowPrivate
}
+47
View File
@@ -4,11 +4,15 @@ import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/google/uuid"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo"
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
)
@@ -153,3 +157,46 @@ func (b *browser) userIDSelf() uuid.UUID {
_, me := b.do("GET", "/api/v1/me", nil)
return uuid.MustParse(me["id"].(string))
}
func TestAgentInstallConsole(t *testing.T) {
e := newEnvWith(t, func(c *config.API) { c.PublicURL = "https://uptime.example.com" })
owner := e.browser(t)
owner.signup("o@"+uniq("inst")+".test", uniq("inst-"))
st, body := owner.do("POST", "/api/v1/org/agents", map[string]any{"kind": "statuspage", "name": "pages"})
if st != http.StatusCreated {
t.Fatalf("create agent = %d %v", st, body)
}
tok := body["token"].(string)
old := buildinfo.Version
buildinfo.Version = "v1.4.2"
t.Cleanup(func() { buildinfo.Version = old })
_, _, html := owner.page("/settings/regions")
for _, want := range []string{
"curl -fsSL https://uptime.example.com/install.sh | sudo sh -s -- {kind} --token {token}{manual}",
`data-channel="latest"`, "Update automatically", "}-statuspage:${UPTIME_AGENT_TAG",
"The platform runs v1.4.2.",
} {
if !strings.Contains(html, want) {
t.Errorf("the page lacks %q", want)
}
}
if strings.Contains(html, ">· outdated<") {
t.Error("an agent that never reported is marked outdated")
}
client := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "v1.4.1").WithHTTPClient(e.srv.Client())
if _, err := client.Hello(context.Background()); err != nil {
t.Fatal(err)
}
if _, _, html := owner.page("/settings/regions"); !strings.Contains(html, "v1.4.1") || !strings.Contains(html, "outdated") {
t.Error("an agent behind the platform is not marked outdated")
}
current := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "v1.4.2").WithHTTPClient(e.srv.Client())
if _, err := current.Hello(context.Background()); err != nil {
t.Fatal(err)
}
if _, _, html := owner.page("/settings/regions"); strings.Contains(html, "· outdated") {
t.Error("an agent on the platform's release is marked outdated")
}
}
+10
View File
@@ -10,11 +10,21 @@
"agents.allow_private_hint": "Nur für Checker. Ausschalten, wenn der Checker in einem Netz läuft, in das Monitore nicht hineinschauen sollen.",
"agents.allow_private_short": "private Adressen",
"agents.create": "Agent anlegen",
"agents.install_auto": "Automatisch aktualisieren",
"agents.install_auto_hint": "Nutzt das selbstaktualisierende Image: Der Agent folgt von allein der Version dieser Plattform, mit signierten Downloads und Rollback. Ohne aktualisierst du den Agent selbst.",
"agents.install_compose": "Oder mit Docker Compose",
"agents.install_compose_hint": "Lege beide Dateien in ein Verzeichnis und führe dort docker compose up -d aus.",
"agents.install_heading": "So installierst du ihn",
"agents.install_oneliner": "Auf einem Linux-Host mit Docker",
"agents.install_statuspage_hint": "Ergänze --host status.example.com für den Hostnamen, unter dem die Seiten erreichbar sind, und --tls --email du@example.com für HTTPS mit Let's Encrypt. --help listet alle Optionen.",
"agents.kind": "Art",
"agents.kind_checker": "Checker",
"agents.kind_statuspage": "Statuspage-Server",
"agents.list": "Agents",
"agents.no_region": "– (nur für Statuspage-Server)",
"agents.outdated": "veraltet",
"agents.outdated_hint": "Hinter der Version der Plattform. Selbstaktualisierende Agents holen von allein auf; beim normalen Image dort, wo er installiert ist, docker compose pull && docker compose up -d ausführen.",
"agents.platform_release": "Die Plattform läuft mit {{.Release}}.",
"agents.region": "Region",
"agents.revoke_confirm": "Diesen Agent widerrufen? Seine Instanzen hören sofort auf zu arbeiten.",
"agents.token_now": "Kopiere den Token jetzt und setze ihn als UPTIME_AGENT_TOKEN. Er wird nicht erneut angezeigt. Beliebig viele Instanzen können ihn teilen.",
+10
View File
@@ -10,11 +10,21 @@
"agents.allow_private_hint": "Checkers only. Switch off if the checker runs in a network monitors must not look into.",
"agents.allow_private_short": "private addresses",
"agents.create": "Create agent",
"agents.install_auto": "Update automatically",
"agents.install_auto_hint": "Uses the self-updating image: the agent follows this platform's release by itself, with signed downloads and rollback. Without it, you update the agent yourself.",
"agents.install_compose": "Or with Docker Compose",
"agents.install_compose_hint": "Put both files in one directory and run docker compose up -d there.",
"agents.install_heading": "Install it",
"agents.install_oneliner": "On a Linux host with Docker",
"agents.install_statuspage_hint": "Add --host status.example.com for the host name that serves pages, and --tls --email you@example.com for HTTPS with Let's Encrypt. --help lists all options.",
"agents.kind": "Kind",
"agents.kind_checker": "Checker",
"agents.kind_statuspage": "Status page server",
"agents.list": "Agents",
"agents.no_region": "– (status page servers only)",
"agents.outdated": "outdated",
"agents.outdated_hint": "Behind the platform's release. Self-updating agents catch up by themselves; for the plain image run docker compose pull && docker compose up -d where it is installed.",
"agents.platform_release": "The platform runs {{.Release}}.",
"agents.region": "Region",
"agents.revoke_confirm": "Revoke this agent? Its instances stop working immediately.",
"agents.token_now": "Copy the token now and set it as UPTIME_AGENT_TOKEN. It will not be shown again. Any number of instances may share it.",
+27
View File
@@ -85,6 +85,32 @@
return out;
};
// fillInstall completes the install instructions of a new agent with its
// token and kind; the checkbox picks the self-updating image or not.
const fillInstall = (form, token) => {
const box = form.querySelector("[data-install]");
if (!box) return;
const kind = form.elements.kind?.value || "checker";
const auto = box.querySelector("[data-install-auto]");
const render = () => {
const channel = box.dataset.channel;
const values = {
token,
kind,
manual: auto.checked ? "" : " --manual-updates",
tag: auto.checked ? `${channel}-autoupdate` : channel,
};
for (const el of box.querySelectorAll("[data-install-fill]")) {
el.textContent = el.dataset.installFill.replace(/\{(\w+)\}/g, (m, k) => values[k] ?? m);
}
for (const el of box.querySelectorAll("[data-install-kind]")) {
el.hidden = el.dataset.installKind !== kind;
}
};
auto.onchange = render;
render();
};
document.addEventListener("submit", async (ev) => {
const form = ev.target.closest("form[data-api]");
if (!form) return;
@@ -117,6 +143,7 @@
input.value = shown;
out.hidden = false;
input.select();
fillInstall(form, shown);
if (form.dataset.refreshTarget) {
// Keep the one-time secret visible while refreshing the channel list
// and group choices. A successful create must not be submitted twice.
+63 -1
View File
@@ -25,6 +25,27 @@ type Agent struct {
// AllowPrivate is set for an organization's checkers: whether they
// may check private addresses.
AllowPrivate *bool
// Release is what the agent last reported; Outdated marks agents
// behind the platform's release.
Release string
Outdated bool
}
// InstallView fills the install instructions shown with a new agent's
// token.
type InstallView struct {
// ScriptURL is the platform's install script.
ScriptURL string
// APIURL goes into UPTIME_API_URL.
APIURL string
// Image is the image name without -checker or -statuspage.
Image string
// Channel is the image tag following the platform: latest, beta or edge.
Channel string
// Compose holds the Compose file per agent kind.
Compose map[string]string
// Release is the platform's release.
Release string
}
// RegionsView is the data of the org regions page and the admin panel.
@@ -38,6 +59,7 @@ type RegionsView struct {
Next string
// OwnRegions are the regions agents can be created in.
OwnRegions []Region
Install InstallView
}
templ regionsBody(v RegionsView) {
@@ -117,6 +139,7 @@ templ regionsBody(v RegionsView) {
<div data-link-output hidden class="mt-6 border border-ink p-4">
<p class="mb-2 text-sm">{ i18n.T(ctx, "agents.token_now") }</p>
<input data-link readonly class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-xs"/>
@agentInstall(v.Install)
</div>
</form>
</section>
@@ -124,6 +147,9 @@ templ regionsBody(v RegionsView) {
if len(v.Agents) > 0 {
<section>
@sectionHeading("agents.list")
if v.Install.Release != "" {
<p class="mb-3 text-xs text-muted">{ i18n.T(ctx, "agents.platform_release", "Release", v.Install.Release) }</p>
}
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, a := range v.Agents {
<li class="flex items-center justify-between gap-4 py-2">
@@ -133,7 +159,15 @@ templ regionsBody(v RegionsView) {
if a.Region != "" {
<span class="text-muted">· { a.Region }</span>
}
<span class="block font-mono text-xs text-muted">{ a.Prefix }… · { a.LastSeen }</span>
<span class="block font-mono text-xs text-muted">
{ a.Prefix }… · { a.LastSeen }
if a.Release != "" {
· { a.Release }
}
if a.Outdated {
<span class="text-degraded" title={ i18n.T(ctx, "agents.outdated_hint") }>· { i18n.T(ctx, "agents.outdated") }</span>
}
</span>
</span>
if a.AllowPrivate != nil {
<form data-api={ v.APIBase + "/agents/" + a.ID } data-method="patch" data-autosave class="ml-auto">
@@ -383,3 +417,31 @@ templ AdminOrgsPage(p Page, me Me, v OrgsView) {
@orgsSection(v)
}
}
// agentInstall shows how to run the agent just created; the script fills
// in the token, the kind chosen and whether it updates itself.
templ agentInstall(in InstallView) {
<div data-install data-channel={ in.Channel } class="mt-6 border-t border-rule pt-4">
<h3 class="mb-2 text-sm font-medium">{ i18n.T(ctx, "agents.install_heading") }</h3>
<label class="mb-1 flex items-center gap-2 text-sm">
<input type="checkbox" data-install-auto checked class="accent-ink"/>
{ i18n.T(ctx, "agents.install_auto") }
</label>
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "agents.install_auto_hint") }</p>
<p class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "agents.install_oneliner") }</p>
<pre data-install-fill={ "curl -fsSL " + in.ScriptURL + " | sudo sh -s -- {kind} --token {token}{manual}" } class="mb-1 overflow-x-auto whitespace-pre-wrap break-all border border-rule p-2 font-mono text-xs"></pre>
<p data-install-kind="statuspage" class="mb-4 text-xs text-muted">{ i18n.T(ctx, "agents.install_statuspage_hint") }</p>
<details class="mt-4">
<summary class="cursor-pointer text-sm">{ i18n.T(ctx, "agents.install_compose") }</summary>
for _, kind := range []string{"checker", "statuspage"} {
<div data-install-kind={ kind } class="mt-3">
<p class="mb-1 font-mono text-xs text-muted">compose.yaml</p>
<pre class="mb-3 max-h-64 overflow-auto border border-rule p-2 font-mono text-xs">{ in.Compose[kind] }</pre>
<p class="mb-1 font-mono text-xs text-muted">.env</p>
<pre data-install-fill={ "UPTIME_API_URL=" + in.APIURL + "\nUPTIME_AGENT_TOKEN={token}\nUPTIME_AGENT_IMAGE=" + in.Image + "\nUPTIME_AGENT_TAG={tag}" } class="overflow-x-auto border border-rule p-2 font-mono text-xs"></pre>
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "agents.install_compose_hint") }</p>
</div>
}
</details>
</div>
}
File diff suppressed because it is too large. Load diff