2018-09-11 05:30:13 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
yaml "gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents the configuration for the exporter
|
|
|
|
type Config struct {
|
|
|
|
Devices []Device `yaml:"devices"`
|
|
|
|
Features struct {
|
2020-04-08 05:06:38 +02:00
|
|
|
BGP bool `yaml:"bgp,omitempty"`
|
|
|
|
DHCP bool `yaml:"dhcp,omitempty"`
|
|
|
|
DHCPL bool `yaml:"dhcpl,omitempty"`
|
|
|
|
DHCPv6 bool `yaml:"dhcpv6,omitempty"`
|
|
|
|
Firmware bool `yaml:"firmware,omitempty"`
|
|
|
|
Health bool `yaml:"health,omitempty"`
|
|
|
|
Routes bool `yaml:"routes,omitempty"`
|
|
|
|
POE bool `yaml:"poe,omitempty"`
|
|
|
|
Pools bool `yaml:"pools,omitempty"`
|
|
|
|
Optics bool `yaml:"optics,omitempty"`
|
|
|
|
W60G bool `yaml:"w60g,omitempty"`
|
|
|
|
WlanSTA bool `yaml:"wlansta,omitempty"`
|
|
|
|
WlanIF bool `yaml:"wlanif,omitempty"`
|
|
|
|
Monitor bool `yaml:"monitor,omitempty"`
|
|
|
|
Ipsec bool `yaml:"ipsec,omitempty"`
|
2018-09-11 05:30:13 +02:00
|
|
|
} `yaml:"features,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Device represents a target device
|
|
|
|
type Device struct {
|
2020-02-04 04:03:45 +01:00
|
|
|
Name string `yaml:"name"`
|
|
|
|
Address string `yaml:"address,omitempty"`
|
|
|
|
Srv SrvRecord `yaml:"srv,omitempty"`
|
|
|
|
User string `yaml:"user"`
|
|
|
|
Password string `yaml:"password"`
|
2020-02-10 19:46:48 +01:00
|
|
|
Port string `yaml:"port"`
|
2018-09-11 05:30:13 +02:00
|
|
|
}
|
|
|
|
|
2020-02-04 04:03:45 +01:00
|
|
|
type SrvRecord struct {
|
|
|
|
Record string `yaml:"record"`
|
|
|
|
Dns DnsServer `yaml:"dns,omitempty"`
|
|
|
|
}
|
|
|
|
type DnsServer struct {
|
|
|
|
Address string `yaml:"address"`
|
|
|
|
Port int `yaml:"port"`
|
|
|
|
}
|
|
|
|
|
2018-09-11 05:30:13 +02:00
|
|
|
// Load reads YAML from reader and unmashals in Config
|
|
|
|
func Load(r io.Reader) (*Config, error) {
|
|
|
|
b, err := ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
c := &Config{}
|
|
|
|
err = yaml.Unmarshal(b, c)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
}
|