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) {
|
||||
var config Config
|
||||
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
con := &Connection{
|
||||
client: graphigo.Client{
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
var reInvalidChars = regexp.MustCompile("(?i)[^a-z0-9\\-]")
|
||||
var reInvalidChars = regexp.MustCompile(`(?i)[^a-z0-9\\-]`)
|
||||
|
||||
func replaceInvalidChars(name string) string {
|
||||
return reInvalidChars.ReplaceAllString(name, "_")
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/bdlm/log"
|
||||
"github.com/influxdata/influxdb1-client/models"
|
||||
"github.com/influxdata/influxdb1-client/v2"
|
||||
client "github.com/influxdata/influxdb1-client/v2"
|
||||
|
||||
"github.com/FreifunkBremen/yanic/database"
|
||||
)
|
||||
|
@ -62,8 +62,7 @@ func init() {
|
|||
database.RegisterAdapter("influxdb", Connect)
|
||||
}
|
||||
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
// Make client
|
||||
c, err := client.NewHTTPClient(client.HTTPConfig{
|
||||
|
|
|
@ -2,6 +2,7 @@ package influxdb
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -15,7 +16,9 @@ import (
|
|||
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
||||
for _, measurement := range []string{MeasurementNode, MeasurementLink} {
|
||||
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)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package logging
|
|||
*/
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -31,8 +32,7 @@ func init() {
|
|||
}
|
||||
|
||||
func Connect(configuration map[string]interface{}) (database.Connection, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
file, err := os.OpenFile(config.Path(), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
|
@ -63,6 +63,8 @@ func (conn *Connection) Close() {
|
|||
}
|
||||
|
||||
func (conn *Connection) log(v ...interface{}) {
|
||||
fmt.Println(v...)
|
||||
conn.file.WriteString(fmt.Sprintln("[", time.Now().String(), "]", v))
|
||||
_, err := fmt.Fprintf(conn.file, "[%s] %v", 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) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
conn, err := net.Dial(config.Type(), config.Address())
|
||||
if err != nil {
|
||||
|
|
|
@ -14,9 +14,11 @@ func TestFilterBlocklist(t *testing.T) {
|
|||
// invalid config
|
||||
filter, err := build(3)
|
||||
assert.Error(err)
|
||||
assert.Nil(filter)
|
||||
|
||||
filter, err = build([]interface{}{2, "a"})
|
||||
assert.Error(err)
|
||||
assert.Nil(filter)
|
||||
|
||||
// tests with empty list
|
||||
filter, err = build([]interface{}{})
|
||||
|
|
|
@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
// invalid config
|
||||
filter, err := build("nope")
|
||||
_, err := build("nope")
|
||||
assert.Error(err)
|
||||
|
||||
// delete owner by configuration
|
||||
filter, _ = build(true)
|
||||
filter, err := build(true)
|
||||
assert.NoError(err)
|
||||
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
||||
System: data.System{
|
||||
SiteCode: "ffhb",
|
||||
|
|
|
@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
// invalid config
|
||||
filter, err := build("nope")
|
||||
_, err := build("nope")
|
||||
assert.Error(err)
|
||||
|
||||
// delete owner by configuration
|
||||
filter, _ = build(true)
|
||||
filter, err := build(true)
|
||||
assert.NoError(err)
|
||||
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
||||
System: data.System{
|
||||
SiteCode: "ffhb",
|
||||
|
|
|
@ -38,7 +38,7 @@ func New(configs map[string]interface{}) (set Set, errs []error) {
|
|||
return
|
||||
}
|
||||
|
||||
f, _ := filters[name]
|
||||
f := filters[name]
|
||||
if f == nil {
|
||||
errs = append(errs, fmt.Errorf("unknown filter: %s", name))
|
||||
} else if filter, err := f(config); err != nil {
|
||||
|
|
|
@ -12,11 +12,11 @@ func TestFilterHasLocation(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
// invalid config
|
||||
filter, err := build(3)
|
||||
_, err := build(3)
|
||||
assert.Error(err)
|
||||
|
||||
// test to drop nodes without location
|
||||
filter, err = build(true)
|
||||
filter, err := build(true)
|
||||
assert.NoError(err)
|
||||
|
||||
// node has location (with 0,0) -> keep it
|
||||
|
|
|
@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
// invalid config
|
||||
filter, err := build("nope")
|
||||
_, err := build("nope")
|
||||
assert.Error(err)
|
||||
|
||||
// delete owner by configuration
|
||||
filter, _ = build(true)
|
||||
filter, err := build(true)
|
||||
assert.NoError(err)
|
||||
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
|
||||
Owner: &data.Owner{
|
||||
Contact: "blub",
|
||||
|
|
|
@ -12,13 +12,13 @@ func TestFilterSite(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
// invalid config
|
||||
filter, err := build("ffhb")
|
||||
_, err := build("ffhb")
|
||||
assert.Error(err)
|
||||
|
||||
filter, err = build([]interface{}{3, "ffhb"})
|
||||
_, err = build([]interface{}{3, "ffhb"})
|
||||
assert.Error(err)
|
||||
|
||||
filter, err = build([]interface{}{"ffhb"})
|
||||
filter, err := build([]interface{}{"ffhb"})
|
||||
assert.NoError(err)
|
||||
|
||||
// wronge node
|
||||
|
|
|
@ -9,11 +9,6 @@ import (
|
|||
"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) {
|
||||
testNodes := createTestNodes()
|
||||
nodes := transform(testNodes)
|
||||
|
@ -41,7 +36,7 @@ func TestTransform(t *testing.T) {
|
|||
nodePoint.Properties["clients"],
|
||||
)
|
||||
assert.Equal(
|
||||
testNodeDescription,
|
||||
"Online\nClients: 42\nModel: TP-Link 841\nSite: mysite\nDomain: domain_42\n",
|
||||
nodePoint.Properties["description"],
|
||||
)
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
|||
}
|
||||
|
||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
if path := config.Path(); path != "" {
|
||||
return &Output{
|
||||
|
|
|
@ -165,8 +165,6 @@ func TestTransform(t *testing.T) {
|
|||
assert.Equal("node:b:mac:lan", link.TargetAddress)
|
||||
assert.Equal(float32(0.2), link.SourceTQ)
|
||||
assert.Equal(float32(0), link.TargetTQ)
|
||||
break
|
||||
|
||||
case "node:a:mac:wifi":
|
||||
assert.Equal("wifi", link.Type)
|
||||
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(float32(0.8), link.SourceTQ)
|
||||
assert.Equal(float32(0.4), link.TargetTQ)
|
||||
break
|
||||
default:
|
||||
assert.False(true, "invalid link.SourceAddress found")
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
|||
}
|
||||
|
||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
if path := config.Path(); path != "" {
|
||||
return &Output{
|
||||
|
|
|
@ -45,8 +45,7 @@ func init() {
|
|||
}
|
||||
|
||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
builder := nodeFormats[config.Version()]
|
||||
if builder == nil {
|
||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
|||
}
|
||||
|
||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
if path := config.Path(); path != "" {
|
||||
return &Output{
|
||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
|||
}
|
||||
|
||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
if path := config.Path(); path != "" {
|
||||
return &Output{
|
||||
|
|
|
@ -9,11 +9,6 @@ import (
|
|||
"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) {
|
||||
testNodes := createTestNodes()
|
||||
result := transform(testNodes)
|
||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
|||
}
|
||||
|
||||
func Register(configuration map[string]interface{}) (output.Output, error) {
|
||||
var config Config
|
||||
config = configuration
|
||||
config := Config(configuration)
|
||||
|
||||
if path := config.Path(); path != "" {
|
||||
return &Output{
|
||||
|
|
|
@ -89,7 +89,9 @@ func (coll *Collector) listenUDP(iface InterfaceConfig) {
|
|||
if err != nil {
|
||||
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()
|
||||
if err != nil {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"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)
|
||||
type Dataset struct {
|
||||
|
|
|
@ -56,7 +56,7 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
|
|||
now := jsontime.Now()
|
||||
|
||||
nodes.Lock()
|
||||
node, _ := nodes.List[nodeID]
|
||||
node := nodes.List[nodeID]
|
||||
|
||||
if node == nil {
|
||||
node = &Node{
|
||||
|
@ -213,7 +213,7 @@ func (nodes *Nodes) readIfaces(nodeinfo *data.Nodeinfo, warning bool) {
|
|||
if addr == "" {
|
||||
continue
|
||||
}
|
||||
if oldNodeID, _ := nodes.ifaceToNodeID[addr]; oldNodeID != nodeID {
|
||||
if oldNodeID := nodes.ifaceToNodeID[addr]; oldNodeID != nodeID {
|
||||
if oldNodeID != "" && warning {
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue