diff --git a/docs/configuration.md b/docs/configuration.md index 44f0b90..7bc11d8 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1220,6 +1220,7 @@ Properties for each site: | title | string | yes | | | url | string | yes | | | check-url | string | no | | +| error-url | string | no | | | icon | string | no | | | allow-insecure | boolean | no | false | | same-tab | boolean | no | false | @@ -1237,6 +1238,10 @@ The public facing URL of a monitored service, the user will be redirected here. The URL which will be requested and its response will determine the status of the site. If not specified, the `url` property is used. +`error-url` + +If the monitored service returns an error, the user will be redirected here. If not specified, the `url` property is used. + `icon` Optional URL to an image which will be used as the icon for the site. Can be an external URL or internal via [server configured assets](#assets-path). You can also directly use [Simple Icons](https://simpleicons.org/) via a `si:` prefix or [Dashboard Icons](https://github.com/walkxcode/dashboard-icons) via a `di:` prefix: diff --git a/internal/glance/widget-monitor.go b/internal/glance/widget-monitor.go index 0890902..76f0d45 100644 --- a/internal/glance/widget-monitor.go +++ b/internal/glance/widget-monitor.go @@ -20,6 +20,8 @@ type monitorWidget struct { Sites []struct { *SiteStatusRequest `yaml:",inline"` Status *siteStatus `yaml:"-"` + URL string `yaml:"-"` + ErrorURL string `yaml:"error-url"` Title string `yaml:"title"` Icon customIconField `yaml:"icon"` SameTab bool `yaml:"same-tab"` @@ -58,10 +60,16 @@ func (widget *monitorWidget) update(ctx context.Context) { status := &statuses[i] site.Status = status - if !slices.Contains(site.AltStatusCodes, status.Code) && (status.Code >= 400 || status.TimedOut || status.Error != nil) { + if !slices.Contains(site.AltStatusCodes, status.Code) && (status.Code >= 400 || status.Error != nil) { widget.HasFailing = true } + if status.Error != nil && site.ErrorURL != "" { + site.URL = site.ErrorURL + } else { + site.URL = site.DefaultURL + } + site.StatusText = statusCodeToText(status.Code, site.AltStatusCodes) site.StatusStyle = statusCodeToStyle(status.Code, site.AltStatusCodes) } @@ -88,12 +96,12 @@ func statusCodeToText(status int, altStatusCodes []int) string { if status == 401 { return "Unauthorized" } - if status >= 400 { - return "Client Error" - } if status >= 500 { return "Server Error" } + if status >= 400 { + return "Client Error" + } return strconv.Itoa(status) } @@ -107,7 +115,7 @@ func statusCodeToStyle(status int, altStatusCodes []int) string { } type SiteStatusRequest struct { - URL string `yaml:"url"` + DefaultURL string `yaml:"url"` CheckURL string `yaml:"check-url"` AllowInsecure bool `yaml:"allow-insecure"` } @@ -124,7 +132,7 @@ func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (siteStatus, error) { if statusRequest.CheckURL != "" { url = statusRequest.CheckURL } else { - url = statusRequest.URL + url = statusRequest.DefaultURL } request, err := http.NewRequest(http.MethodGet, url, nil) if err != nil {