Only show downed services on startup

This commit is contained in:
Locria Cyber 2023-10-07 13:51:03 +00:00
parent b515907d1a
commit 40ab08eb9e
Signed by: iacore
GPG key ID: F8C16E5157A63006

23
main.go
View file

@ -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()