Run manual diagnostic attachments in the background

This commit is contained in:
ayurishchev committed 2026-11-22 20:50:39 +03:00
1 parent d845a5e4b6
commit 89ac4d5bcd
40 files changed
+1560 -58

No files matched your search

@@ -0,0 +1,131 @@
{{define "diagnostics_page"}}
<!doctype html>
<html lang="ru">
<head>{{template "html_head" .}}<script src="/static/diagnostics.js" defer></script></head>
<body>
<div class="bg-grid"></div>
<input type="checkbox" id="nav-toggle" class="nav-toggle">
<div class="shell">
{{template "sidebar_nav" .}}
<div>
{{template "topbar_mobile" .}}
<main class="main">
<div id="error-banner">{{template "banner_inner" .Banner}}</div>
<div class="topbar"><h1>Диагностика</h1></div>
{{template "diagnostics_form" .}}
{{template "diagnostics_operation" .Operation}}
<div id="diagnostics-action-result" aria-live="polite"></div>
{{template "diagnostics_holds" .}}
</main>
</div>
</div>
</body>
</html>
{{end}}
{{define "diagnostics_form"}}
<div class="panel">
<div class="panel-body">
<form id="diagnostics-attach" hx-post="/diagnostics/operations" hx-target="#diagnostics-operation" hx-swap="outerHTML"
hx-disabled-elt="#diagnostics-submit" hx-indicator="#diagnostics-sending">
<input type="hidden" id="diagnostics-key" name="operation_id" value="{{.OperationKey}}">
<div class="field-row">
<div class="field" style="flex: 1 1 320px;">
<label for="diag-addresses">Адреса (по одному на строку или через запятую)</label>
<textarea id="diag-addresses" name="addresses" rows="2" placeholder="203.0.113.10&#10;203.0.113.11" required></textarea>
</div>
<div class="field">
<label for="diag-validator">Валидатор</label>
{{template "diagnostics_validators" .}}
</div>
<div class="field">
<label for="diag-note">Заметка</label>
<input type="text" id="diag-note" name="note">
</div>
<button id="diagnostics-submit" type="submit" class="btn btn-primary"{{if .Operation.Poll}} disabled{{end}}>Привязать</button>
<span id="diagnostics-sending" class="htmx-indicator" role="status">Отправляем запрос…</span>
<span id="diagnostics-connection" role="status" hidden><span></span> <a hidden>Проверить статус</a></span>
</div>
</form>
<p class="muted" style="margin-top:8px">На время диагностики валидатор не берёт задания. Команды (traceroute, curl, tcpdump)
выполняются вручную по SSH на валидаторе. После работы адрес нужно отвязать. Если выбран конкретный валидатор, а адресов
несколько, он назначается первому адресу, остальные уходят на любые свободные.</p>
</div>
</div>
{{end}}
{{define "diagnostics_validators"}}
<select id="diag-validator" name="validator_id" hx-get="/diagnostics/validators"
hx-trigger="diagnostics-changed from:body" hx-swap="outerHTML">
<option value="">любой свободный</option>
{{range .FreeValidators}}<option value="{{.ValidatorID}}">{{.ValidatorID}} ({{.OSPortID}})</option>{{end}}
</select>
{{end}}
{{define "diagnostics_operation"}}
<section id="diagnostics-operation" aria-live="polite"
{{if .Poll}}data-pending="true" hx-get="/diagnostics/operations/{{.ID}}"
hx-trigger="{{if .Immediate}}load, {{end}}every 1s" hx-swap="outerHTML"{{end}}>
{{if .Message}}<p role="status">{{.Message}}{{if .RetryID}} <a href="/diagnostics?operation={{.RetryID}}">Проверить статус</a>{{end}}</p>{{end}}
{{if and .Poll (not .Items) (not .Message)}}<p role="status">Проверяем статус операции…</p>{{end}}
{{template "diagnostics_results" .Items}}
</section>
{{if .NextKey}}<input type="hidden" id="diagnostics-key" name="operation_id" value="{{.NextKey}}" hx-swap-oob="outerHTML">{{end}}
{{end}}
{{define "diagnostics_results"}}
{{if .}}
<h2 class="section-title">Результат операции</h2>
<div class="panel">
<div class="table-scroll">
<table>
<thead><tr><th>Адрес</th><th>Результат</th></tr></thead>
<tbody>
{{range .}}
<tr>
<td class="mono" data-label="Адрес">{{.Address}}</td>
<td data-label="Результат">{{if eq .Status "queued"}}<span class="pill">В очереди</span>{{else if eq .Status "running"}}<span class="pill">Привязываем…</span> {{.Reason}}{{else if eq .Status "attached"}}<span class="pill pill-success">привязан к {{.ValidatorID}}</span>{{else if eq .Status "detached"}}<span class="pill pill-success">отвязан</span>{{else}}<span class="pill pill-danger">отказ</span> {{.Reason}}{{end}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
{{end}}
{{end}}
{{define "diagnostics_holds"}}
<div id="diagnostics-wrap" hx-get="/diagnostics/holds" hx-trigger="diagnostics-changed from:body"
hx-swap="outerHTML">
<h2 class="section-title">Удерживаемые адреса</h2>
{{if .Rows}}
<form id="diag-list" hx-post="/diagnostics/detach" hx-target="#diagnostics-action-result" hx-swap="innerHTML" hx-confirm="Отвязать выбранные адреса?">
<div class="actions" style="margin-bottom:8px">
<button type="submit" class="btn btn-ghost btn-sm">Отвязать выбранные</button>
<button type="button" class="btn btn-danger-ghost btn-sm" hx-post="/diagnostics/detach" hx-vals='{"all":"1"}' hx-target="#diagnostics-action-result" hx-swap="innerHTML" hx-confirm="Отвязать все адреса ({{len .Rows}})?">Отвязать все</button>
</div>
<div class="panel">
<div class="table-scroll">
<table>
<thead><tr><th><input type="checkbox" aria-label="Выбрать все" onclick="this.closest('table').querySelectorAll('input[name=addresses]').forEach(cb => cb.checked = this.checked)"></th><th>Адрес</th><th>Валидатор</th><th>fip_id</th><th>С какого времени</th><th>Заметка</th><th></th></tr></thead>
<tbody>
{{range .Rows}}
<tr>
<td data-label=""><input type="checkbox" name="addresses" value="{{.Address}}"></td>
<td class="mono" data-label="Адрес">{{.Address}}</td>
<td class="mono" data-label="Валидатор">{{.ValidatorID}}</td>
<td class="mono" data-label="fip_id">{{.FIPID}}</td>
<td data-label="С какого времени">{{fmtTime .CreatedAt}} ({{.Duration}})</td>
<td data-label="Заметка">{{if .Note}}{{.Note}}{{else}}—{{end}}</td>
<td data-label=""><button type="button" class="btn btn-danger-ghost btn-sm" hx-post="/diagnostics/detach" hx-vals='{"addresses":"{{.Address}}"}' hx-target="#diagnostics-action-result" hx-swap="innerHTML" hx-confirm="Отвязать {{.Address}}?">Отвязать</button></td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
</form>
{{else}}<p class="muted">Удерживаемых адресов нет.</p>{{end}}
</div>
{{end}}
+3 -3
View File
@@ -57,14 +57,14 @@
{{else}}<p class="muted">Проверок пока нет.</p>{{end}}
<h2 class="section-title">События</h2>
{{if .Detail.Events}}
{{if .Events}}
<div class="panel">
<div class="table-scroll">
<table>
<thead><tr><th>Время</th><th>Тип</th><th>Источник</th><th>Данные</th></tr></thead>
<tbody>
{{range .Detail.Events}}
<tr><td class="num" data-label="Время">{{fmtTime .OccurredAt}}</td><td data-label="Тип">{{.EventType}}</td><td data-label="Источник">{{.SourceType}} {{.SourceID}}</td><td data-label="Данные">{{.Payload}}</td></tr>
{{range .Events}}
<tr><td class="num" data-label="Время">{{fmtTime .OccurredAt}}</td><td data-label="Тип">{{.EventType}}</td><td data-label="Источник">{{.SourceType}} {{.SourceID}}</td><td data-label="Данные">{{with .Trace}}<div>цель {{.Target}}{{if .Host}} ({{.Host}}){{end}} · IP {{.IP}} · {{.Status}} · {{.DurationMS}} мс{{if .Error}} · ошибка: {{.Error}}{{end}}</div>{{if .Output}}<pre class="trace-output">{{.Output}}</pre>{{end}}{{else}}{{.Payload}}{{end}}</td></tr>
{{end}}
</tbody>
</table>
+4
View File
@@ -75,6 +75,10 @@
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 20V10M10 20V4M16 20v-7M22 20H2"/></svg>
Аналитика
</a>
<a class="nav-link{{if eq .ActiveNav "diagnostics"}} active{{end}}" {{if eq .ActiveNav "diagnostics"}}aria-current="page"{{end}} href="/diagnostics">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>
Диагностика
</a>
<div class="nav-group-title">Настройка</div>
<a class="nav-link{{if eq .ActiveNav "validators"}} active{{end}}" {{if eq .ActiveNav "validators"}}aria-current="page"{{end}} href="/validators">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="3" width="16" height="7" rx="1.5"/><rect x="4" y="14" width="16" height="7" rx="1.5"/><circle cx="8" cy="6.5" r="1"/><circle cx="8" cy="17.5" r="1"/></svg>
@@ -15,6 +15,9 @@
{{with .Status.ResultsByOverall}}{{if or (index . "pass") (index . "partial") (index . "fail") (index . "cancelled")}}
<p class="muted" id="overview-results" style="margin-top:8px">Итоги проверок: pass {{index . "pass"}} · partial {{index . "partial"}} · fail {{index . "fail"}} · cancelled {{index . "cancelled"}}</p>
{{end}}{{end}}
{{if .Diagnostics}}
<p class="muted" id="overview-diagnostics" style="margin-top:8px">На диагностике: <a href="/diagnostics">{{.Diagnostics}}</a></p>
{{end}}
{{with .Scan}}
<p class="muted" id="overview-scan" style="margin-top:8px">Сканирование: {{.StateLabel}}{{if .DryRun}} (пробное){{end}} · прочитано страниц {{.Pages}}, найдено адресов {{.Discovered}}, свободных {{.Free}}{{if .Handled}}, обработано {{.Handled}}{{end}} · <a href="/ips">подробнее</a></p>
{{end}}
+1 -1
View File
@@ -67,7 +67,7 @@
<td data-label="Heartbeat">{{fmtTime .LastHeartbeatAt}}</td>
<td data-label="">
<div class="actions">
<button class="btn btn-danger-ghost btn-sm" hx-delete="/validators/{{.ValidatorID}}" hx-target="#validators-table-wrap" hx-swap="innerHTML" hx-confirm="Удалить валидатор {{.ValidatorID}}?">Удалить</button>
{{if eq .State "diagnostic"}}<a class="btn btn-ghost btn-sm" href="/diagnostics">Диагностика</a>{{else}}<button class="btn btn-danger-ghost btn-sm" hx-delete="/validators/{{.ValidatorID}}" hx-target="#validators-table-wrap" hx-swap="innerHTML" hx-confirm="Удалить валидатор {{.ValidatorID}}?">Удалить</button>{{end}}
</div>
</td>
</tr>