-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
51 lines (43 loc) · 1.11 KB
/
config.go
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
package main
import (
"log"
"time"
)
// Handle the loading and parsing the timing for the config
func readAndParseConfig() {
var err error
// Read Config
log.Println("Loading the configuration file.")
config, err = readConfig(*config_file)
printError(err, "Error reading or parsing config file:", *config_file, "error:", err)
// Parse the interval
if len(config.Interval) > 0 {
queryInterval, err = time.ParseDuration(config.Interval)
printError(err, "Parsing interval error:", err)
} else {
// One time shot deal
oneTime = true
}
//Count the total number of hosts to query
host_count = 0
for _, qryConf := range config.Nxapi {
for range qryConf.Host {
host_count++
}
}
log.Println("Found", host_count, "hosts in the config.")
if host_count == 0 {
log.Fatal("No hosts found, please add hosts for querying")
}
// Figure out the timing
if !oneTime {
queryStep = time.Duration(int64(queryInterval) / int64(host_count))
}
}
// Print error to the screen
func printRespErr(err error, t string, dat []byte) {
if err != nil {
log.Println(t, "=", string(dat))
log.Println("err=", err)
}
}