diff --git a/chart/values.yaml b/chart/values.yaml index 47267c5..dcb5665 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -24,8 +24,6 @@ configuration: ui: # The title of the page title: Status Page - # The header text to display - header: Status Page imagePullSecrets: [] nameOverride: "" diff --git a/internal/config/config.go b/internal/config/config.go index eaea0d8..d1b7b35 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,8 +24,7 @@ type Service struct { } type UI struct { - PageTitle string `yaml:"title"` - HeaderText string `yaml:"header"` + PageTitle string `yaml:"title"` } type Config struct { @@ -84,9 +83,6 @@ func setDefaults(conf *Config) { if conf.UI.PageTitle == "" { conf.UI.PageTitle = "PromPage" } - if conf.UI.HeaderText == "" { - conf.UI.HeaderText = "Status Page" - } } func (c *Config) Validate() error { diff --git a/internal/http/status.go b/internal/http/status.go index 7a7f094..6f3b4c6 100644 --- a/internal/http/status.go +++ b/internal/http/status.go @@ -14,21 +14,32 @@ import ( "github.com/labstack/echo/v4" ) +var ( + OutageNone = "None" + OutagePartial = "Partial" + OutageFull = "Full" +) + func NewStatusPageHandler(app *app.App, cache *ResultCache) echo.HandlerFunc { tmpl := template.Must(template.ParseFS(views.Views, "index.html")) return func(c echo.Context) error { res, t := cache.Get() age := time.Since(t) + op := operational(res) data := struct { - Config config.Config - Results []collector.Result - Age time.Duration + Config config.Config + Results []collector.Result + Age time.Duration + Outage string + BannerClasses string }{ - Config: *app.Config, - Results: res, - Age: age.Round(time.Second), + Config: *app.Config, + Results: res, + Age: age.Round(time.Second), + Outage: op, + BannerClasses: bannerClasses(op), } var buf bytes.Buffer if err := tmpl.Execute(&buf, data); err != nil { @@ -39,3 +50,34 @@ func NewStatusPageHandler(app *app.App, cache *ResultCache) echo.HandlerFunc { return c.HTML(http.StatusOK, buf.String()) } } + +func operational(res []collector.Result) string { + passing := 0 + for _, r := range res { + if r.Status { + passing++ + } + } + + switch passing { + case 0: + return OutageFull + case len(res): + return OutageNone + default: + return OutagePartial + } +} + +func bannerClasses(outage string) string { + switch outage { + case OutageNone: + return "bg-lime-600 text-white" + case OutageFull: + return "bg-red-500 text-white" + case OutagePartial: + fallthrough + default: + return "bg-orange-400" + } +} diff --git a/internal/resources/static/up.svg b/internal/resources/static/up.svg index 9e960e3..7966b40 100644 --- a/internal/resources/static/up.svg +++ b/internal/resources/static/up.svg @@ -1,9 +1,16 @@ - - - - - - - - + + + + + + + + + + + + + + + diff --git a/internal/resources/views/index.html b/internal/resources/views/index.html index ff31244..34bef94 100644 --- a/internal/resources/views/index.html +++ b/internal/resources/views/index.html @@ -9,7 +9,13 @@ {{/* Main content */}}
-

{{ .Config.UI.HeaderText }}

+
+ {{- if eq .Outage "None" }} + All Systems Operational + {{- else }} + {{ .Outage }} Systems Outage + {{- end }} +
{{- range .Results }} diff --git a/tailwind.config.js b/tailwind.config.js index 10b3f01..1edc9fe 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,6 +1,12 @@ /** @type {import('tailwindcss').Config} */ module.exports = { content: ["internal/resources/views/*.html"], + safelist: [ + 'bg-lime-600', + 'bg-red-500', + 'bg-orange-400', + 'text-white' + ], theme: { extend: { colors: {