From 725d0da15d7ee596ec35c0eebcd24b06fc23fb85 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Thu, 29 Aug 2024 21:14:50 +0100 Subject: [PATCH] Add show-failing-only property to the monitor widget --- docs/configuration.md | 12 ++++++++---- internal/assets/static/main.css | 1 + internal/assets/templates/monitor.html | 11 +++++++++++ internal/widget/monitor.go | 11 +++++++++-- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 1b02af4..fed6fa4 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1043,14 +1043,18 @@ You can hover over the "ERROR" text to view more information. #### Properties -| Name | Type | Required | -| ---- | ---- | -------- | -| sites | array | yes | -| style | string | no | +| Name | Type | Required | Default | +| ---- | ---- | -------- | ------- | +| sites | array | yes | | +| show-failing-only | boolean | no | false | +| style | string | no | | ##### `style` To make the widget scale appropriately in a `full` size column, set the style to the experimental `dynamic-columns-experimental` option. +##### `show-failing-only` +Shows only a list of failing sites when set to `true`. + ##### `sites` Properties for each site: diff --git a/internal/assets/static/main.css b/internal/assets/static/main.css index ddad6e0..37db60c 100644 --- a/internal/assets/static/main.css +++ b/internal/assets/static/main.css @@ -1509,4 +1509,5 @@ kbd:active { .margin-bottom-10 { margin-bottom: 1rem; } .margin-bottom-15 { margin-bottom: 1.5rem; } .margin-bottom-auto { margin-bottom: auto; } +.padding-block-5 { padding-block: 0.5rem; } .scale-half { transform: scale(0.5); } diff --git a/internal/assets/templates/monitor.html b/internal/assets/templates/monitor.html index 0333741..bfb2ca9 100644 --- a/internal/assets/templates/monitor.html +++ b/internal/assets/templates/monitor.html @@ -10,13 +10,24 @@ {{ end }} {{ else }} + +{{ if not (and .ShowFailingOnly (not .HasFailing)) }} +{{ else }} +
+

All sites are online

+ + + +
+{{ end }} {{ end }} {{ end }} diff --git a/internal/widget/monitor.go b/internal/widget/monitor.go index 7216e9c..b5a279e 100644 --- a/internal/widget/monitor.go +++ b/internal/widget/monitor.go @@ -53,7 +53,9 @@ type Monitor struct { StatusText string `yaml:"-"` StatusStyle string `yaml:"-"` } `yaml:"sites"` - Style string `yaml:"style"` + Style string `yaml:"style"` + ShowFailingOnly bool `yaml:"show-failing-only"` + HasFailing bool `yaml:"-"` } func (widget *Monitor) Initialize() error { @@ -79,12 +81,17 @@ func (widget *Monitor) Update(ctx context.Context) { return } + widget.HasFailing = false + for i := range widget.Sites { site := &widget.Sites[i] status := &statuses[i] - site.Status = status + if status.Code >= 400 || status.TimedOut || status.Error != nil { + widget.HasFailing = true + } + if !status.TimedOut { site.StatusText = statusCodeToText(status.Code) site.StatusStyle = statusCodeToStyle(status.Code)