mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
UptimeRobot: option to show offline monitors first
This commit is contained in:
parent
dd4899a07c
commit
b8c9f96db2
@ -17,6 +17,7 @@ type Settings struct {
|
||||
|
||||
apiKey string `help:"An UptimeRobot API key."`
|
||||
uptimePeriods string `help:"The periods over which to display uptime (in days, dash-separated)." optional:"true"`
|
||||
offlineFirst bool `help:"Display offline monitors at the top." optional:"true"`
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||
@ -26,6 +27,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
|
||||
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_UPTIMEROBOT_APIKEY")),
|
||||
uptimePeriods: ymlConfig.UString("uptimePeriods", "30"),
|
||||
offlineFirst: ymlConfig.UBool("offlineFirst", false),
|
||||
}
|
||||
|
||||
cfg.ModuleSecret(name, globalConfig, &settings.apiKey).
|
||||
|
@ -47,6 +47,22 @@ func (widget *Widget) Refresh() {
|
||||
}
|
||||
|
||||
monitors, err := widget.getMonitors()
|
||||
|
||||
if widget.settings.offlineFirst {
|
||||
var tmp Monitor
|
||||
var next int
|
||||
for i := 0; i < len(monitors); i++ {
|
||||
if monitors[i].State != 2 {
|
||||
tmp = monitors[i]
|
||||
for j := i; j > next; j-- {
|
||||
monitors[j] = monitors[j-1]
|
||||
}
|
||||
monitors[next] = tmp
|
||||
next++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
widget.monitors = monitors
|
||||
widget.err = err
|
||||
widget.SetItemCount(len(monitors))
|
||||
|
Loading…
x
Reference in New Issue
Block a user