Skip to content

Commit

Permalink
move sleep to result handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Teymur committed Mar 10, 2024
1 parent 9cfc53a commit b33e083
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func main() {
timeout = config.Exporter.DefaultProbeTimeout
}
targetLogger := logger.With(slog.String("target",target))
resultHandler := func(result bool, err error) {
resultHandler := func(result bool, err error, interval int) {
if result {
targetLogger.Info("OK")
probeResult.WithLabelValues(target, module, address).Set(1)
Expand All @@ -105,25 +105,23 @@ func main() {
}
probeResult.WithLabelValues(target, module, address).Set(0)
}
time.Sleep(time.Duration(interval) * time.Second)
}
switch module {
case "tcp":
for {
result,err := modules.ProbeTCP(address,timeout)
resultHandler(result,err)
time.Sleep(time.Duration(interval) * time.Second)
resultHandler(result,err,interval)
}
case "http":
for {
result,err := modules.ProbeHTTP(address,timeout)
resultHandler(result,err)
time.Sleep(time.Duration(interval) * time.Second)
resultHandler(result,err,interval)
}
case "icmp":
for {
result,err := modules.ProbeICMP(address)
resultHandler(result,err)
time.Sleep(time.Duration(interval) * time.Second)
resultHandler(result,err,interval)
}
default:
targetLogger.Error("Unknown module")
Expand Down

0 comments on commit b33e083

Please sign in to comment.