Make linter happy
This commit is contained in:
parent
61d159f3c5
commit
ff42378138
|
@ -35,9 +35,7 @@ func (c Config) Prefix() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
|
|
||||||
config = configuration
|
|
||||||
|
|
||||||
con := &Connection{
|
con := &Connection{
|
||||||
client: graphigo.Client{
|
client: graphigo.Client{
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var reInvalidChars = regexp.MustCompile("(?i)[^a-z0-9\\-]")
|
var reInvalidChars = regexp.MustCompile(`(?i)[^a-z0-9\\-]`)
|
||||||
|
|
||||||
func replaceInvalidChars(name string) string {
|
func replaceInvalidChars(name string) string {
|
||||||
return reInvalidChars.ReplaceAllString(name, "_")
|
return reInvalidChars.ReplaceAllString(name, "_")
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"github.com/influxdata/influxdb1-client/models"
|
"github.com/influxdata/influxdb1-client/models"
|
||||||
"github.com/influxdata/influxdb1-client/v2"
|
client "github.com/influxdata/influxdb1-client/v2"
|
||||||
|
|
||||||
"github.com/FreifunkBremen/yanic/database"
|
"github.com/FreifunkBremen/yanic/database"
|
||||||
)
|
)
|
||||||
|
@ -62,8 +62,7 @@ func init() {
|
||||||
database.RegisterAdapter("influxdb", Connect)
|
database.RegisterAdapter("influxdb", Connect)
|
||||||
}
|
}
|
||||||
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
// Make client
|
// Make client
|
||||||
c, err := client.NewHTTPClient(client.HTTPConfig{
|
c, err := client.NewHTTPClient(client.HTTPConfig{
|
||||||
|
|
|
@ -2,6 +2,7 @@ package influxdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -15,7 +16,9 @@ import (
|
||||||
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
||||||
for _, measurement := range []string{MeasurementNode, MeasurementLink} {
|
for _, measurement := range []string{MeasurementNode, MeasurementLink} {
|
||||||
query := fmt.Sprintf("delete from %s where time < now() - %ds", measurement, deleteAfter/time.Second)
|
query := fmt.Sprintf("delete from %s where time < now() - %ds", measurement, deleteAfter/time.Second)
|
||||||
conn.client.Query(client.NewQuery(query, conn.config.Database(), "m"))
|
if _, err := conn.client.Query(client.NewQuery(query, conn.config.Database(), "m")); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -197,6 +200,4 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
|
||||||
|
|
||||||
conn.addPoint(MeasurementDHCP, tags, fields, time)
|
conn.addPoint(MeasurementDHCP, tags, fields, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package logging
|
||||||
*/
|
*/
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -31,8 +32,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
file, err := os.OpenFile(config.Path(), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
file, err := os.OpenFile(config.Path(), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,6 +63,8 @@ func (conn *Connection) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *Connection) log(v ...interface{}) {
|
func (conn *Connection) log(v ...interface{}) {
|
||||||
fmt.Println(v...)
|
_, err := fmt.Fprintf(conn.file, "[%s] %v", time.Now().String(), v)
|
||||||
conn.file.WriteString(fmt.Sprintln("[", time.Now().String(), "]", v))
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
conn, err := net.Dial(config.Type(), config.Address())
|
conn, err := net.Dial(config.Type(), config.Address())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -14,9 +14,11 @@ func TestFilterBlocklist(t *testing.T) {
|
||||||
// invalid config
|
// invalid config
|
||||||
filter, err := build(3)
|
filter, err := build(3)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
assert.Nil(filter)
|
||||||
|
|
||||||
filter, err = build([]interface{}{2, "a"})
|
filter, err = build([]interface{}{2, "a"})
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
assert.Nil(filter)
|
||||||
|
|
||||||
// tests with empty list
|
// tests with empty list
|
||||||
filter, err = build([]interface{}{})
|
filter, err = build([]interface{}{})
|
||||||
|
|
|
@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// invalid config
|
// invalid config
|
||||||
filter, err := build("nope")
|
_, err := build("nope")
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
// delete owner by configuration
|
// delete owner by configuration
|
||||||
filter, _ = build(true)
|
filter, err := build(true)
|
||||||
|
assert.NoError(err)
|
||||||
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
||||||
System: data.System{
|
System: data.System{
|
||||||
SiteCode: "ffhb",
|
SiteCode: "ffhb",
|
||||||
|
|
|
@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// invalid config
|
// invalid config
|
||||||
filter, err := build("nope")
|
_, err := build("nope")
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
// delete owner by configuration
|
// delete owner by configuration
|
||||||
filter, _ = build(true)
|
filter, err := build(true)
|
||||||
|
assert.NoError(err)
|
||||||
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
||||||
System: data.System{
|
System: data.System{
|
||||||
SiteCode: "ffhb",
|
SiteCode: "ffhb",
|
||||||
|
|
|
@ -38,7 +38,7 @@ func New(configs map[string]interface{}) (set Set, errs []error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
f, _ := filters[name]
|
f := filters[name]
|
||||||
if f == nil {
|
if f == nil {
|
||||||
errs = append(errs, fmt.Errorf("unknown filter: %s", name))
|
errs = append(errs, fmt.Errorf("unknown filter: %s", name))
|
||||||
} else if filter, err := f(config); err != nil {
|
} else if filter, err := f(config); err != nil {
|
||||||
|
|
|
@ -12,11 +12,11 @@ func TestFilterHasLocation(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// invalid config
|
// invalid config
|
||||||
filter, err := build(3)
|
_, err := build(3)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
// test to drop nodes without location
|
// test to drop nodes without location
|
||||||
filter, err = build(true)
|
filter, err := build(true)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
// node has location (with 0,0) -> keep it
|
// node has location (with 0,0) -> keep it
|
||||||
|
|
|
@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// invalid config
|
// invalid config
|
||||||
filter, err := build("nope")
|
_, err := build("nope")
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
// delete owner by configuration
|
// delete owner by configuration
|
||||||
filter, _ = build(true)
|
filter, err := build(true)
|
||||||
|
assert.NoError(err)
|
||||||
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
||||||
Owner: &data.Owner{
|
Owner: &data.Owner{
|
||||||
Contact: "blub",
|
Contact: "blub",
|
||||||
|
|
|
@ -12,13 +12,13 @@ func TestFilterSite(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// invalid config
|
// invalid config
|
||||||
filter, err := build("ffhb")
|
_, err := build("ffhb")
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
filter, err = build([]interface{}{3, "ffhb"})
|
_, err = build([]interface{}{3, "ffhb"})
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
filter, err = build([]interface{}{"ffhb"})
|
filter, err := build([]interface{}{"ffhb"})
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
// wronge node
|
// wronge node
|
||||||
|
|
|
@ -9,11 +9,6 @@ import (
|
||||||
"github.com/FreifunkBremen/yanic/runtime"
|
"github.com/FreifunkBremen/yanic/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
testNodeDescription string = "Online\nClients: 42\nModel: TP-Link 841\n" +
|
|
||||||
"Site: mysite\nDomain: domain_42\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTransform(t *testing.T) {
|
func TestTransform(t *testing.T) {
|
||||||
testNodes := createTestNodes()
|
testNodes := createTestNodes()
|
||||||
nodes := transform(testNodes)
|
nodes := transform(testNodes)
|
||||||
|
@ -41,7 +36,7 @@ func TestTransform(t *testing.T) {
|
||||||
nodePoint.Properties["clients"],
|
nodePoint.Properties["clients"],
|
||||||
)
|
)
|
||||||
assert.Equal(
|
assert.Equal(
|
||||||
testNodeDescription,
|
"Online\nClients: 42\nModel: TP-Link 841\nSite: mysite\nDomain: domain_42\n",
|
||||||
nodePoint.Properties["description"],
|
nodePoint.Properties["description"],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
if path := config.Path(); path != "" {
|
if path := config.Path(); path != "" {
|
||||||
return &Output{
|
return &Output{
|
||||||
|
|
|
@ -165,8 +165,6 @@ func TestTransform(t *testing.T) {
|
||||||
assert.Equal("node:b:mac:lan", link.TargetAddress)
|
assert.Equal("node:b:mac:lan", link.TargetAddress)
|
||||||
assert.Equal(float32(0.2), link.SourceTQ)
|
assert.Equal(float32(0.2), link.SourceTQ)
|
||||||
assert.Equal(float32(0), link.TargetTQ)
|
assert.Equal(float32(0), link.TargetTQ)
|
||||||
break
|
|
||||||
|
|
||||||
case "node:a:mac:wifi":
|
case "node:a:mac:wifi":
|
||||||
assert.Equal("wifi", link.Type)
|
assert.Equal("wifi", link.Type)
|
||||||
assert.Equal("node:b:mac:wifi", link.TargetAddress)
|
assert.Equal("node:b:mac:wifi", link.TargetAddress)
|
||||||
|
@ -177,7 +175,6 @@ func TestTransform(t *testing.T) {
|
||||||
assert.Equal("node:c:mac:lan", link.TargetAddress)
|
assert.Equal("node:c:mac:lan", link.TargetAddress)
|
||||||
assert.Equal(float32(0.8), link.SourceTQ)
|
assert.Equal(float32(0.8), link.SourceTQ)
|
||||||
assert.Equal(float32(0.4), link.TargetTQ)
|
assert.Equal(float32(0.4), link.TargetTQ)
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
assert.False(true, "invalid link.SourceAddress found")
|
assert.False(true, "invalid link.SourceAddress found")
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
if path := config.Path(); path != "" {
|
if path := config.Path(); path != "" {
|
||||||
return &Output{
|
return &Output{
|
||||||
|
|
|
@ -45,8 +45,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
builder := nodeFormats[config.Version()]
|
builder := nodeFormats[config.Version()]
|
||||||
if builder == nil {
|
if builder == nil {
|
||||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
if path := config.Path(); path != "" {
|
if path := config.Path(); path != "" {
|
||||||
return &Output{
|
return &Output{
|
||||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
if path := config.Path(); path != "" {
|
if path := config.Path(); path != "" {
|
||||||
return &Output{
|
return &Output{
|
||||||
|
|
|
@ -9,11 +9,6 @@ import (
|
||||||
"github.com/FreifunkBremen/yanic/runtime"
|
"github.com/FreifunkBremen/yanic/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
testNodeDescription string = "Online\nClients: 42\nModel: TP-Link 841\n" +
|
|
||||||
"Site: mysite\nDomain: domain_42\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTransform(t *testing.T) {
|
func TestTransform(t *testing.T) {
|
||||||
testNodes := createTestNodes()
|
testNodes := createTestNodes()
|
||||||
result := transform(testNodes)
|
result := transform(testNodes)
|
||||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||||
var config Config
|
config := Config(configuration)
|
||||||
config = configuration
|
|
||||||
|
|
||||||
if path := config.Path(); path != "" {
|
if path := config.Path(); path != "" {
|
||||||
return &Output{
|
return &Output{
|
||||||
|
|
|
@ -89,7 +89,9 @@ func (coll *Collector) listenUDP(iface InterfaceConfig) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
conn.SetReadBuffer(MaxDataGramSize)
|
if err := conn.SetReadBuffer(MaxDataGramSize); err != nil {
|
||||||
|
log.Println("failed to set read buffer:", err)
|
||||||
|
}
|
||||||
|
|
||||||
raw, err := conn.SyscallConn()
|
raw, err := conn.SyscallConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var linePattern = regexp.MustCompile("^<!-- ....-..-.. ..:..:.. [A-Z]+ / (\\d+) --> <row><v>([^<]+)</v><v>([^<]+)</v></row>")
|
var linePattern = regexp.MustCompile(`^<!-- ....-..-.. ..:..:.. [A-Z]+ / (\\d+) --> <row><v>([^<]+)</v><v>([^<]+)</v></row>`)
|
||||||
|
|
||||||
// Dataset a timestemp with values (node and clients)
|
// Dataset a timestemp with values (node and clients)
|
||||||
type Dataset struct {
|
type Dataset struct {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
|
||||||
now := jsontime.Now()
|
now := jsontime.Now()
|
||||||
|
|
||||||
nodes.Lock()
|
nodes.Lock()
|
||||||
node, _ := nodes.List[nodeID]
|
node := nodes.List[nodeID]
|
||||||
|
|
||||||
if node == nil {
|
if node == nil {
|
||||||
node = &Node{
|
node = &Node{
|
||||||
|
@ -213,7 +213,7 @@ func (nodes *Nodes) readIfaces(nodeinfo *data.Nodeinfo, warning bool) {
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if oldNodeID, _ := nodes.ifaceToNodeID[addr]; oldNodeID != nodeID {
|
if oldNodeID := nodes.ifaceToNodeID[addr]; oldNodeID != nodeID {
|
||||||
if oldNodeID != "" && warning {
|
if oldNodeID != "" && warning {
|
||||||
log.Warnf("override nodeID from %s to %s on MAC address %s", oldNodeID, nodeID, addr)
|
log.Warnf("override nodeID from %s to %s on MAC address %s", oldNodeID, nodeID, addr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ func TestSelectNodes(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.Len(selectedNodes, 1)
|
assert.Len(selectedNodes, 1)
|
||||||
time := jsontime.Time{}
|
time := jsontime.Time{}
|
||||||
time.UnmarshalJSON([]byte("2017-03-10T12:12:01"))
|
assert.NoError(time.UnmarshalJSON([]byte("\"2017-03-10T12:12:01\"")))
|
||||||
assert.Equal(time, selectedNodes[0].Firstseen)
|
assert.Equal(time, selectedNodes[0].Firstseen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue