afl-prom/watch.go

61 lines
1.3 KiB
Go
Raw Normal View History

2020-06-07 21:33:48 +00:00
package main
import (
2020-06-09 16:01:46 +00:00
"flag"
2020-06-07 21:33:48 +00:00
"fmt"
"log"
"os"
"time"
)
var (
registeredFuzzers []Fuzzer
2020-06-09 16:01:46 +00:00
sleepSecs *int
2020-06-07 21:33:48 +00:00
)
2020-06-09 16:01:46 +00:00
func registerWatcherFlags() {
sleepSecs = flag.Int("scan-delay", 30, "Seconds to sleep between scans of the fuzzer directories")
}
2020-06-07 21:33:48 +00:00
// Returns the path to every fuzzer to watch
func getFuzzersToWatch() ([]string, error) {
2020-06-09 16:01:46 +00:00
// flag.Args() returns all arguments after --
fuzzers := flag.Args()
if len(fuzzers) > 0 {
return fuzzers, nil
2020-06-07 21:33:48 +00:00
}
// Wrong usage - construct a helpful error message
return []string{}, fmt.Errorf("Please give at least one fuzzer directory to watch.\n%s [options...] -- /path/to/fuzzer1 /path/to/fuzzer2", os.Args[0])
}
// Registers the given paths as fuzzer directories which should be monitored
func registerFuzzers(targets []string) {
2020-06-09 08:07:43 +00:00
// First, create fuzzer instances based on the directory
2020-06-07 21:33:48 +00:00
for _, f := range targets {
2020-06-09 08:07:43 +00:00
tmpFuzzer := CreateFuzzer(f)
2020-06-07 21:33:48 +00:00
registeredFuzzers = append(registeredFuzzers, tmpFuzzer)
}
2020-06-09 08:07:43 +00:00
// Create gauges
InitializeGauges()
2020-06-07 21:33:48 +00:00
}
// Watch over the fuzzer(s)
func watchFuzzers() {
// Loop forever
for {
// Loop over every registered fuzzer
for _, f := range registeredFuzzers {
parseErr := f.ParseStatsFile()
if parseErr != nil {
log.Printf("Encountered error while parsing %s: %s", f, parseErr.Error())
}
}
// and sleep
2020-06-09 16:01:46 +00:00
time.Sleep(time.Duration(*sleepSecs) * time.Second)
2020-06-07 21:33:48 +00:00
}
}