More features (#9)
* added config file implementation, refactoring * add gitignore * improved test * preperations for more metrics * added resource metrics * added first bgp metrics * added asn as label for bgp metrics * added prefix and message counts to bgp metrics * simplified * Update README.md * added yaml dependency * fixed go routine call * added timeout * clean up * added TLS support * set default api port for TLS * added routes metric * added missing log information * added type collectorContext to reduce the count of parameters for better readability * added DHCP and DHCPv6 metrics * filter for active dhcp leases only * added pool metrics * enable/disable feature in config file * refactoring * clean up * comment fix
This commit is contained in:
committed by
Steve Brunton
parent
f2866a3a2f
commit
d170b0a4d2
@@ -7,10 +7,19 @@ import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Config represents the configuration for the exporter
|
||||
type Config struct {
|
||||
Devices []Device `yaml:"devices"`
|
||||
Devices []Device `yaml:"devices"`
|
||||
Features struct {
|
||||
BGP bool `yaml:"bgp,omitempty"`
|
||||
DHCP bool `yaml:"dhcp,omitempty"`
|
||||
DHCPv6 bool `yaml:"dhcpv6,omitempty"`
|
||||
Routes bool `yaml:"routes,omitempty"`
|
||||
Pools bool `yaml:"pools,omitempty"`
|
||||
} `yaml:"features,omitempty"`
|
||||
}
|
||||
|
||||
// Device represents a target device
|
||||
type Device struct {
|
||||
Name string `yaml:"name"`
|
||||
Address string `yaml:"address"`
|
||||
@@ -18,6 +27,7 @@ type Device struct {
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
|
||||
// Load reads YAML from reader and unmashals in Config
|
||||
func Load(r io.Reader) (*Config, error) {
|
||||
b, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
|
||||
@@ -17,8 +17,13 @@ func TestShouldParse(t *testing.T) {
|
||||
t.Fatalf("expected 2 devices, got %v", len(c.Devices))
|
||||
}
|
||||
|
||||
assertConfig("test1", "192.168.1.1", "foo", "bar", c.Devices[0], t)
|
||||
assertConfig("test2", "192.168.2.1", "test", "123", c.Devices[1], t)
|
||||
assertDevice("test1", "192.168.1.1", "foo", "bar", c.Devices[0], t)
|
||||
assertDevice("test2", "192.168.2.1", "test", "123", c.Devices[1], t)
|
||||
assertFeature("BGP", c.Features.BGP, t)
|
||||
assertFeature("DHCP", c.Features.DHCP, t)
|
||||
assertFeature("DHCPv6", c.Features.DHCPv6, t)
|
||||
assertFeature("Pools", c.Features.Pools, t)
|
||||
assertFeature("Routes", c.Features.Routes, t)
|
||||
}
|
||||
|
||||
func loadTestFile(t *testing.T) []byte {
|
||||
@@ -30,7 +35,7 @@ func loadTestFile(t *testing.T) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
func assertConfig(name, address, user, password string, c Device, t *testing.T) {
|
||||
func assertDevice(name, address, user, password string, c Device, t *testing.T) {
|
||||
if c.Name != name {
|
||||
t.Fatalf("expected name %s, got %s", name, c.Name)
|
||||
}
|
||||
@@ -47,3 +52,9 @@ func assertConfig(name, address, user, password string, c Device, t *testing.T)
|
||||
t.Fatalf("expected password %s, got %s", password, c.Password)
|
||||
}
|
||||
}
|
||||
|
||||
func assertFeature(name string, v bool, t *testing.T) {
|
||||
if !v {
|
||||
t.Fatalf("exprected feature %s to be enabled", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,11 @@ devices:
|
||||
- name: test2
|
||||
address: 192.168.2.1
|
||||
user: test
|
||||
password: 123
|
||||
password: 123
|
||||
|
||||
features:
|
||||
bgp: true
|
||||
dhcp: true
|
||||
dhcpv6: true
|
||||
routes: true
|
||||
pools: true
|
||||
Reference in New Issue
Block a user