Only show downed services on startup
This commit is contained in:
parent
b515907d1a
commit
40ab08eb9e
1 changed files with 15 additions and 8 deletions
23
main.go
23
main.go
|
@ -183,10 +183,10 @@ func main() {
|
|||
// timed update
|
||||
|
||||
go func() {
|
||||
// first_time := true
|
||||
first_time := true
|
||||
for {
|
||||
err := routineCheck(5*time.Minute, true)
|
||||
// first_time = false
|
||||
err := routineCheck(5*time.Minute, first_time)
|
||||
first_time = false
|
||||
if err != nil {
|
||||
log.Printf("Error in routineCheck: %v", err)
|
||||
// idea: maybe should delay here
|
||||
|
@ -202,7 +202,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func routineCheck(timeout time.Duration, doNotify bool) error {
|
||||
func routineCheck(timeout time.Duration, onlyShowDown bool) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
|
@ -211,12 +211,19 @@ func routineCheck(timeout time.Duration, doNotify bool) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if doNotify {
|
||||
err = notify(non_duplicates)
|
||||
if err != nil {
|
||||
return err
|
||||
if onlyShowDown {
|
||||
tmp := non_duplicates
|
||||
non_duplicates = []scanner.ServiceStatus{}
|
||||
for _, v := range tmp {
|
||||
if !v.Ok {
|
||||
non_duplicates = append(non_duplicates, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
err = notify(non_duplicates)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// log.Printf("Routine check: %v", data)
|
||||
<-ctx.Done()
|
||||
|
||||
|
|
Loading…
Reference in a new issue