mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2025-01-06 18:28:10 +01:00
tls default are set when loading yaml config
This commit is contained in:
parent
571009f7bd
commit
f43ad5cd54
@ -1,10 +1,11 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config represents the configuration for the exporter
|
// Config represents the configuration for the exporter
|
||||||
@ -40,9 +41,9 @@ type Device struct {
|
|||||||
Srv SrvRecord `yaml:"srv,omitempty"`
|
Srv SrvRecord `yaml:"srv,omitempty"`
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
Port string `yaml:"port"`
|
Port string `yaml:"port,omitempty"`
|
||||||
EnableTLS bool `yaml:"tls"`
|
EnableTLS bool `yaml:"tls,omitempty"`
|
||||||
InsecureTLS bool `yaml:"insecure"`
|
InsecureTLS bool `yaml:"insecure,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SrvRecord struct {
|
type SrvRecord struct {
|
||||||
@ -54,7 +55,7 @@ type DnsServer struct {
|
|||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load reads YAML from reader and unmashals in Config
|
// Load reads YAML from reader and unmarshalls in Config
|
||||||
func Load(r io.Reader) (*Config, error) {
|
func Load(r io.Reader) (*Config, error) {
|
||||||
b, err := ioutil.ReadAll(r)
|
b, err := ioutil.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,3 +70,15 @@ func Load(r io.Reader) (*Config, error) {
|
|||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Device) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
type inputDevice Device
|
||||||
|
defaults := &inputDevice{Port: "8728", EnableTLS: false, InsecureTLS: false}
|
||||||
|
err := unmarshal(defaults)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("Device unmarshal error")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*d = (Device)(*defaults)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -6,8 +6,8 @@ devices:
|
|||||||
- name: test2
|
- name: test2
|
||||||
address: 192.168.2.1
|
address: 192.168.2.1
|
||||||
user: test
|
user: test
|
||||||
password: 123
|
password: '123'
|
||||||
port: 324
|
port: '324'
|
||||||
tls: true
|
tls: true
|
||||||
insecure: true
|
insecure: true
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ func TestShouldParse(t *testing.T) {
|
|||||||
|
|
||||||
assertDevice("test1", "192.168.1.1", "foo", "bar", c.Devices[0], 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)
|
assertDevice("test2", "192.168.2.1", "test", "123", c.Devices[1], t)
|
||||||
assertDeviceConnection("", false, false, c.Devices[0], t)
|
assertDeviceConnection("8728", false, false, c.Devices[0], t)
|
||||||
assertDeviceConnection("324", true, true, c.Devices[1], t)
|
assertDeviceConnection("324", true, true, c.Devices[1], t)
|
||||||
assertFeature("BGP", c.Features.BGP, t)
|
assertFeature("BGP", c.Features.BGP, t)
|
||||||
assertFeature("Conntrack", c.Features.Conntrack, t)
|
assertFeature("Conntrack", c.Features.Conntrack, t)
|
||||||
|
Loading…
Reference in New Issue
Block a user