-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.go
97 lines (80 loc) · 2.61 KB
/
dashboard.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import "fmt"
func showDashboard() {
fmt.Println("\033[2J\033[H")
fmt.Println("------------------------------------------------------------------------------------------------------------")
fmt.Println("\033[1mInstance Sensor Status Last Update\033[0m")
fmt.Println("------------------------------------------------------------------------------------------------------------")
// Local sensors first
for _, sensor := range local.sensors {
printSensorStatus(local.DisplayName, sensor)
}
// Then ordered by remote instances
for _, remote := range local.RemoteInstances {
// todo: Design decision
/*
// Only try to read from connected instances
if !remote.connected {
continue
}
*/
for _, sensor := range remote.sensors {
printSensorStatus(remote.DisplayName, sensor)
}
}
fmt.Println("------------------------------------------------------------------------------------------------------------")
// Remote instances
fmt.Println("\n\n")
fmt.Println("------------------------------------------------------------------------------------------------------------")
fmt.Println("\033[1mRemote Instance Status \033[0m")
fmt.Println("------------------------------------------------------------------------------------------------------------")
for _, remote := range local.RemoteInstances {
printRemoteInstanceStatus(&remote)
}
fmt.Println("------------------------------------------------------------------------------------------------------------")
}
func printSensorStatus(instanceDisplayName string, sensor *Sensor) {
var statusText string
var colorCode string
var lastUpdateTimestamp string
status := sensor.lastUpdateStatus()
switch status {
case SensorStatusOK:
statusText = "OK"
colorCode = "\033[32m"
break
case SensorStatusFAIL:
statusText = "FAIL"
colorCode = "\033[31m"
break
case SensorStatusOLD:
statusText = "OLD"
colorCode = "\033[31m"
break
case SensorStatusSYNC:
colorCode = "\033[93m"
statusText = "SYNC"
}
lastUpdateTimestamp = sensor.lastUpdateTimestamp()
fmt.Printf("%s%-35s %-22s %-4s %s\033[0m\n",
colorCode,
instanceDisplayName,
sensor.DisplayName,
statusText,
lastUpdateTimestamp)
}
func printRemoteInstanceStatus(remote *RemoteInstance) {
var statusText string
var colorCode string
if remote.connected {
statusText = "Connected"
colorCode = "\033[32m"
} else {
statusText = "Not Connected"
colorCode = "\033[31m"
}
fmt.Printf("%s%-35s %-22s\033[0m\n",
colorCode,
remote.DisplayName,
statusText)
}