forked from wtfutil/wtf
/
display.go
57 lines (51 loc) · 917 Bytes
/
display.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package grafana
import "fmt"
func (widget *Widget) content() (string, string, bool) {
title := widget.CommonSettings().Title
var out string
if widget.Err != nil {
return title, widget.Err.Error(), false
} else {
for idx, alert := range widget.Alerts {
out += fmt.Sprintf(` ["%d"][%s]%s - %s[""]`,
idx,
stateColor(alert.State),
stateToEmoji(alert.State),
alert.Name,
)
out += "\n"
}
}
return title, out, false
}
func stateColor(state AlertState) string {
switch state {
case Ok:
return "green"
case Paused:
return "yellow"
case Alerting:
return "red"
case Pending:
return "orange"
case NoData:
return "yellow"
default:
return "white"
}
}
func stateToEmoji(state AlertState) string {
switch state {
case Ok:
return "✔"
case Paused:
return "⏸"
case Alerting:
return "✘"
case Pending:
return "?"
case NoData:
return "?"
}
return ""
}