Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a light mode #179

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## vXX

* Make the look of tuwat configurable via `style` property.

## v1.3 - 2024-01-08 icinga2 ack

* The `icinga2` adapter now filters all acknowledged issues.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Connectors for

See the [Example Config](./config.example.toml) for configuration.

Available styles:

* `dark` (default)
* `light` - mimics the venerable nagdash

### Dashboards

The main configuration can contain `Rules`, but if multiple rule-sets/dashboards
Expand Down
5 changes: 3 additions & 2 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# golang `text/template` describing where the alert is happening
where = "{{with index .Labels \"Cluster\"}}{{.}}/{{end}}{{first .Labels \"Project\" \"Namespace\" \"Hostname\"}}"
interval = "1m"
#style = "light"


[[rule]]
Expand All @@ -18,8 +19,8 @@ what = "fooo service"
[[example]]
Tag = 'demo'

# The github connector runs out af the box as configured below,
# but keep in mind that github rate limits these requests.
# The GitHub connector runs out of the box as configured below,
# but keep in mind that GitHub rate limits these requests.
#[[github]]
#Repos = ['synyx/tuwat', 'synyx/buchungsstreber']
#Tag = 'gh'
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"path/filepath"
"slices"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -46,6 +47,7 @@ type Config struct {
WhereTemplate *template.Template
Interval time.Duration
Dashboards map[string]*Dashboard
Style string
}

type Dashboard struct {
Expand All @@ -64,6 +66,7 @@ type Rule struct {
type mainConfig struct {
WhereTemplate string `toml:"where"`
Interval string `toml:"interval"`
Style string `toml:"style"`
}

type mainDashboardConfig struct {
Expand Down Expand Up @@ -163,6 +166,11 @@ func NewConfiguration() (config *Config, err error) {
err = nil
}

// validate configuration
if !slices.Contains([]string{"light", "dark"}, cfg.Style) {
return nil, errors.New("configuration error: [main] style must be \"light\" or \"dark\"")
}

return cfg, err
}

Expand All @@ -183,13 +191,16 @@ func (cfg *Config) loadMainConfig(file string) (err error) {
}

rootConfig.Main.Interval = "1m"
rootConfig.Main.Style = "dark"

// Fill configuration

if _, err = toml.DecodeFile(file, &rootConfig); err != nil {
return err
}

cfg.Style = rootConfig.Main.Style

cfg.Logger = rootConfig.Logger

// Add connectors
Expand Down
Empty file added pkg/web/static/css/dark.css
Empty file.
46 changes: 46 additions & 0 deletions pkg/web/static/css/light.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
body {
background-color: #ffffff;
color: #333333;
}

table { border: 1px solid #c6c6c6; background-color: #F0F0F0; border-collapse: separate;
*border-collapse: collapse; -webkit-border-radius: 4px;
-moz-border-radius: 4px; border-radius: 4px; }
th {
background-color: #D8D8D8;
color: #000000;
}

/* Moves the white font further away from the background for better visibility */
summary {
padding-left: 7px;
}

.status.green, .status.green summary, .status.green details {
background-color: #269926;
color: white;
}

.status.red, .status.red summary, .status.red details {
background-color: #FF4040;
color: white;
}

.status.yellow, .status.yellow summary, .status.yellow details {
background-color: #FFDE40;
color: black;
}

.status.grey, .status.grey summary, .status.grey details {
background-color: #444444;
color: white;
}

.tag {
font-size: 0.6em;
color: white;
padding: 4px;
-webkit-border-radius: 0.25em;
background-color: #98999b;
}
.tag_label { color: white; }
1 change: 1 addition & 0 deletions pkg/web/templates/_base.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">

<link rel="stylesheet" href="/static/css/main.css" />
<link rel="stylesheet" href="/static/css/{{.Style}}.css" />
<script type="module" src="/static/js/index.min.js"></script>
<noscript>
<meta http-equiv="refresh" content="60; url=/alerts" />
Expand Down
7 changes: 7 additions & 0 deletions pkg/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type webHandler struct {

aggregator *aggregation.Aggregator
environment string
style string
dashboards map[string]*config.Dashboard
}

Expand All @@ -44,12 +45,14 @@ type webContent struct {
Content any
Dashboards map[string]*config.Dashboard
Dashboard string
Style string
}

func WebHandler(cfg *config.Config, aggregator *aggregation.Aggregator) http.Handler {
handler := &webHandler{
aggregator: aggregator,
environment: cfg.Environment,
style: cfg.Style,
dashboards: cfg.Dashboards,
}

Expand Down Expand Up @@ -148,6 +151,7 @@ func (h *webHandler) baseRenderer(req *http.Request, dashboardName string, patte

data.Version = version.Info.Version
data.Environment = h.environment
data.Style = h.style
data.Dashboards = h.dashboards
data.Dashboard = dashboardName

Expand Down Expand Up @@ -183,6 +187,7 @@ func (h *webHandler) partialRenderer(req *http.Request, dashboardName string, pa

data.Version = version.Info.Version
data.Environment = h.environment
data.Style = h.style
data.Dashboard = dashboardName

err := tmpl.ExecuteTemplate(w, templateDefinition, data)
Expand Down Expand Up @@ -240,6 +245,7 @@ func (h *webHandler) sseRenderer(w http.ResponseWriter, req *http.Request, patte
return func(data webContent) error {
data.Version = version.Info.Version
data.Environment = h.environment
data.Style = h.style

buf := new(bytes.Buffer)

Expand Down Expand Up @@ -298,6 +304,7 @@ func (h *webHandler) wsRenderer(s *websocket.Conn, patterns ...string) wsRenderF

data.Version = version.Info.Version
data.Environment = h.environment
data.Style = h.style

buf := new(bytes.Buffer)

Expand Down