forked from nerdalert/nflow-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_flow_config_file.go
56 lines (44 loc) · 1.2 KB
/
read_flow_config_file.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
52
53
54
55
56
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
type ConfigHost struct {
Ip string `json:"ip"`
Name string `json:"name"`
}
type ConfigFlowUser struct {
SrcAddr string `json:"src_addr"`
SrcPort string `json:"src_port"`
DstAddr string `json:"dst_addr"`
DstPort string `json:"dst_port"`
Proto string `json:"proto"`
Hops []string `json:"hops"`
Count int `json:"count"`
}
type ConfigFile struct {
Seed int `json:"seed"`
FlowTimeout int `json:"flow_timeout"`
CollectorIp string `json:"collector_ip"`
CollectorPort int `json:"collector_port"`
Hosts []ConfigHost `json:"hosts"`
Flows []ConfigFlowUser `json:"flows"`
}
func ReadFlowConfigFile(config *ConfigFile, filename string) error {
jsonFile, err := os.Open(filename)
if err != nil {
return fmt.Errorf("failed to open config file %s: %v", filename, err)
}
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
err = json.Unmarshal(byteValue, config)
if err != nil {
return fmt.Errorf("failed to parse config file %s: %v", filename, err)
}
if config.FlowTimeout == 0 {
config.FlowTimeout = 60
}
return nil
}