-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch.go
More file actions
60 lines (50 loc) · 1.35 KB
/
Copy pathwatch.go
File metadata and controls
60 lines (50 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
)
var (
registeredFuzzers []Fuzzer
sleepSecs *int
)
func registerWatcherFlags() {
sleepSecs = flag.Int("scan-delay", 30, "Seconds to sleep between scans of the fuzzer directories")
}
// Returns the path to every fuzzer to watch
func getFuzzersToWatch() ([]string, error) {
// flag.Args() returns all arguments after --
fuzzers := flag.Args()
if len(fuzzers) > 0 {
return fuzzers, nil
}
// 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) {
// First, create fuzzer instances based on the directory
for _, f := range targets {
tmpFuzzer := CreateFuzzer(f)
registeredFuzzers = append(registeredFuzzers, tmpFuzzer)
}
// Create gauges
InitializeGauges()
}
// 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
time.Sleep(time.Duration(*sleepSecs) * time.Second)
}
}