feat: Alertmanager as a source for monitors
Organizations create receiver URLs for Alertmanager's webhook (token in the path or as bearer). A monitor of type alertmanager is down while an alert matching all its label matchers fires, and goes through the usual evaluation, so confirmations, maintenance, notifications and SLA apply. Results are recorded when the state changes and once per interval; alerts Alertmanager stops repeating end after the monitor's stale period, so a lost resolve cannot hold it down. An overview lists firing alerts with the monitors following them and creates a prefilled monitor for the others. Closes #91 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
16dfba817e
commit
b3e34613a3
19 files changed
+2118
-543
No files matched your search
@@ -489,8 +489,20 @@ type MonitorForm struct {
|
||||
PromMode string
|
||||
PromEmptyOK bool
|
||||
PromVerify bool
|
||||
Matchers []MatcherRow
|
||||
StaleHours int
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -564,15 +576,37 @@ 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", "heartbeat"} {
|
||||
for _, t := range []string{"http", "json", "prometheus", "tcp", "tls", "dns", "icmp", "heartbeat", "alertmanager"} {
|
||||
<option value={ t } selected?={ t == f.Type }>{ i18n.T(ctx, "monitors.type_"+t) }</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<div data-hide-for="heartbeat" hidden?={ f.Type == "heartbeat" }>
|
||||
<div data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) }>
|
||||
@valueField(i18n.T(ctx, "monitors.target"), "target", f.Target, "https://example.com", f.Type != "heartbeat")
|
||||
<p class="-mt-3 mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.target_hint") }</p>
|
||||
</div>
|
||||
@typeFields("alertmanager", f.Type) {
|
||||
<p class="mb-4 text-xs text-muted">
|
||||
{ i18n.T(ctx, "monitors.alertmanager_hint") }
|
||||
<a href="/settings/alertmanager" class="underline underline-offset-2">{ i18n.T(ctx, "alertmanager.title") }</a>
|
||||
</p>
|
||||
<fieldset class="mb-4">
|
||||
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.matchers") }</legend>
|
||||
for i, m := range f.Matchers {
|
||||
<div class="mb-1.5 grid grid-cols-[1fr_4.5rem_1fr] gap-1.5">
|
||||
<input name={ "config.matchers." + strconv.Itoa(i) + ".label" } value={ m.Label } placeholder="alertname" aria-label={ i18n.T(ctx, "monitors.matcher_label") } class="min-w-0 border border-rule bg-transparent px-2 py-1 font-mono text-xs outline-none focus:border-ink"/>
|
||||
<select name={ "config.matchers." + strconv.Itoa(i) + ".op" } aria-label={ i18n.T(ctx, "monitors.assertion_op") } class="border border-rule bg-transparent px-1 py-1 font-mono text-xs">
|
||||
for _, op := range MatcherOps {
|
||||
<option value={ op } selected?={ op == m.Op }>{ op }</option>
|
||||
}
|
||||
</select>
|
||||
<input name={ "config.matchers." + strconv.Itoa(i) + ".value" } value={ m.Value } placeholder="HighErrorRate" aria-label={ i18n.T(ctx, "monitors.assertion_value") } class="min-w-0 border border-rule bg-transparent px-2 py-1 font-mono text-xs outline-none focus:border-ink"/>
|
||||
</div>
|
||||
}
|
||||
<p class="mt-1 text-xs text-muted">{ i18n.T(ctx, "monitors.matchers_hint") }</p>
|
||||
</fieldset>
|
||||
@numberField(i18n.T(ctx, "monitors.stale_hours"), "config.stale_hours", f.StaleHours, 1, 720, i18n.T(ctx, "monitors.stale_hours_hint"))
|
||||
}
|
||||
@typeFields("heartbeat", f.Type) {
|
||||
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "monitors.heartbeat_hint") }</p>
|
||||
@numberField(i18n.T(ctx, "monitors.grace"), "config.grace_seconds", f.GraceSeconds, 0, 86400, i18n.T(ctx, "monitors.grace_hint"))
|
||||
@@ -679,11 +713,11 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
|
||||
</div>
|
||||
<div>
|
||||
@numberField(i18n.T(ctx, "monitors.interval"), "interval_seconds", f.IntervalSeconds, f.MinInterval, 86400, i18n.T(ctx, "monitors.interval_hint", "Min", f.MinInterval))
|
||||
<div data-hide-for="heartbeat" hidden?={ f.Type == "heartbeat" }>
|
||||
<div data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) }>
|
||||
@numberField(i18n.T(ctx, "monitors.timeout"), "timeout_ms", f.TimeoutMS, 100, 60000, "")
|
||||
</div>
|
||||
@numberField(i18n.T(ctx, "monitors.confirmations"), "confirmations", f.Confirmations, 1, 10, i18n.T(ctx, "monitors.confirmations_hint"))
|
||||
<fieldset class="mb-4" data-hide-for="heartbeat" hidden?={ f.Type == "heartbeat" } disabled?={ f.Type == "heartbeat" }>
|
||||
<fieldset class="mb-4" data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) } disabled?={ f.Type == "heartbeat" }>
|
||||
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.regions") }</legend>
|
||||
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "monitors.regions_hint") }</p>
|
||||
for _, r := range f.Regions {
|
||||
@@ -915,3 +949,5 @@ func opKey(op string) string {
|
||||
}
|
||||
return op
|
||||
}
|
||||
|
||||
func passiveType(t string) bool { return t == "heartbeat" || t == "alertmanager" }
|
||||
Reference in new issue
Block a user