/
config.go
60 lines (51 loc) · 1.26 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
52
53
54
55
56
57
58
59
60
package config
import (
"io"
"io/ioutil"
"gopkg.in/yaml.v2"
)
// Config represents the configuration for the exporter
type Config struct {
Targets []string `yaml:"targets"`
Features struct {
Environment bool `yaml:"environment,omitempty"`
BGP bool `yaml:"bgp,omitempty"`
OSPF bool `yaml:"ospf,omitempty"`
ISIS bool `yaml:"isis,omitempty"`
L2Circuit bool `yaml:"l2circuit,omitempty"`
Routes bool `yaml:"routes,omitempty"`
RoutingEngine bool `yaml:"routing_engine,omitempty"`
Interfaces bool `yaml:"interfaces,omitempty"`
InterfaceDiagnostic bool `yaml:"interface_diagnostic,omitempty"`
} `yaml:"features,omitempty"`
}
func New() *Config {
c := &Config{
Targets: make([]string, 0),
}
setDefaultValues(c)
return c
}
// Load loads a config from reader
func Load(reader io.Reader) (*Config, error) {
b, err := ioutil.ReadAll(reader)
if err != nil {
return nil, err
}
c := New()
err = yaml.Unmarshal(b, c)
if err != nil {
return nil, err
}
return c, nil
}
func setDefaultValues(c *Config) {
f := &c.Features
f.BGP = true
f.Environment = true
f.Interfaces = true
f.InterfaceDiagnostic = true
f.OSPF = true
f.Routes = true
f.RoutingEngine = true
}