News features and improvements (#8)

* 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
This commit is contained in:
Daniel Czerwonk
2018-03-21 02:28:10 +01:00
committed by Steve Brunton
parent c37abb638f
commit f2866a3a2f
340 changed files with 25181 additions and 3416 deletions

5
vendor/gopkg.in/routeros.v2/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,5 @@
.vscode
.idea
*.exe
*.out
*.test

View File

@@ -12,6 +12,7 @@ import (
"io"
"net"
"sync"
"time"
"gopkg.in/routeros.v2/proto"
)
@@ -48,6 +49,15 @@ func Dial(address, username, password string) (*Client, error) {
return newClientAndLogin(conn, address, username, password)
}
// Dial connects and logs in to a RouterOS device.
func DialTimeout(address, username, password string, timeout time.Duration) (*Client, error) {
conn, err := net.DialTimeout("tcp", address, timeout)
if err != nil {
return nil, err
}
return newClientAndLogin(conn, address, username, password)
}
// DialTLS connects and logs in to a RouterOS device using TLS.
func DialTLS(address, username, password string, tlsConfig *tls.Config) (*Client, error) {
conn, err := tls.Dial("tcp", address, tlsConfig)
@@ -57,6 +67,18 @@ func DialTLS(address, username, password string, tlsConfig *tls.Config) (*Client
return newClientAndLogin(conn, address, username, password)
}
// DialTLSTimeout connects and logs in to a RouterOS device using TLS with timeout.
func DialTLSTimeout(address, username, password string, tlsConfig *tls.Config, timeout time.Duration) (*Client, error) {
dialer := new(net.Dialer)
dialer.Timeout = timeout
conn, err := tls.DialWithDialer(dialer, "tcp", address, tlsConfig)
if err != nil {
return nil, err
}
return newClientAndLogin(conn, address, username, password)
}
func newClientAndLogin(rwc io.ReadWriteCloser, address, username, password string) (*Client, error) {
c, err := NewClient(rwc)
if err != nil {

View File

@@ -2,7 +2,9 @@ package routeros
import (
"flag"
"strings"
"testing"
"time"
)
var (
@@ -104,6 +106,30 @@ func TestDialTLSInvalidPort(t *testing.T) {
}
}
func TestDialTimeout(t *testing.T) {
c, err := DialTimeout("127.0.0.2:8729", "x", "x", time.Second)
if err == nil {
c.Close()
t.Fatalf("DialTimeout succeeded; want error")
}
if !strings.Contains(err.Error(), "i/o timeout") {
t.Fatalf("DialTimeout: Timeout expected in err. Has: %s", err)
}
}
func TestDialTLSTimeout(t *testing.T) {
c, err := DialTLSTimeout("127.0.0.2:8729", "x", "x", nil, time.Second)
if err == nil {
c.Close()
t.Fatalf("DialTLSTimeout succeeded; want error")
}
if !strings.Contains(err.Error(), "i/o timeout") {
t.Fatalf("DialTLSTimeout: Timeout expected in err. Has: %s", err)
}
}
func TestInvalidLogin(t *testing.T) {
if *routerosAddress == "" {
t.Skip("Flag -routeros.address not set")