Merge pull request #2 from FreifunkBremen/master

Updaten auf upstream
This commit is contained in:
Nils Stinnesbeck 2019-11-23 13:02:40 +01:00 committed by GitHub
commit e351a9d1a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 204 additions and 2 deletions

View File

@ -23,7 +23,7 @@ domains = ["city"]
# name of interface on which this collector is running # name of interface on which this collector is running
ifname = "br-ffhb" ifname = "br-ffhb"
# ip address which is used for sending # ip address which is used for sending
# (optional - without definition used a address of ifname - prefered link local) # (optional - without definition used a address of ifname - preferred link local)
ip_address = "fd2f:5119:f2d::5" ip_address = "fd2f:5119:f2d::5"
# disable sending multicast respondd request # disable sending multicast respondd request
# (for receiving only respondd packages e.g. database respondd) # (for receiving only respondd packages e.g. database respondd)

View File

@ -110,7 +110,7 @@ ifname = "br-ffhb"
{% method %} {% method %}
ip address is the own address which is used for sending. ip address is the own address which is used for sending.
If not set or set with empty string it will take an address of ifname. If not set or set with empty string it will take an address of ifname.
(It preferes the link local address, so at babel mesh-network it should be configurated) (It prefers the link local address, so at babel mesh-network it should be configurated)
{% sample lang="toml" %} {% sample lang="toml" %}
```toml ```toml
ip_address = "fe80::..." ip_address = "fe80::..."
@ -521,6 +521,21 @@ path = "/var/www/html/meshviewer/data/nodelist.json"
``` ```
{% endmethod %} {% endmethod %}
## [[nodes.output.raw]]
{% method %}
This output takes the respondd response as sent by the node and includes it in a JSON document.
{% endmethod %}
### path
{% method %}
The path, where to store raw.json
{% sample lang="toml" %}
```toml
path = "/var/www/html/meshviewer/data/raw.json"
```
{% endmethod %}
## [database] ## [database]

View File

@ -5,4 +5,5 @@ import (
_ "github.com/FreifunkBremen/yanic/output/meshviewer" _ "github.com/FreifunkBremen/yanic/output/meshviewer"
_ "github.com/FreifunkBremen/yanic/output/meshviewer-ffrgb" _ "github.com/FreifunkBremen/yanic/output/meshviewer-ffrgb"
_ "github.com/FreifunkBremen/yanic/output/nodelist" _ "github.com/FreifunkBremen/yanic/output/nodelist"
_ "github.com/FreifunkBremen/yanic/output/raw"
) )

46
output/raw/output.go Normal file
View File

@ -0,0 +1,46 @@
package raw
import (
"errors"
"github.com/FreifunkBremen/yanic/output"
"github.com/FreifunkBremen/yanic/runtime"
)
type Output struct {
output.Output
path string
}
type Config map[string]interface{}
func (c Config) Path() string {
if path, ok := c["path"]; ok {
return path.(string)
}
return ""
}
func init() {
output.RegisterAdapter("raw", Register)
}
func Register(configuration map[string]interface{}) (output.Output, error) {
var config Config
config = configuration
if path := config.Path(); path != "" {
return &Output{
path: path,
}, nil
}
return nil, errors.New("no path given")
}
func (o *Output) Save(nodes *runtime.Nodes) {
nodes.RLock()
defer nodes.RUnlock()
runtime.SaveJSON(transform(nodes), o.path)
}

28
output/raw/output_test.go Normal file
View File

@ -0,0 +1,28 @@
package raw
import (
"os"
"testing"
"github.com/FreifunkBremen/yanic/runtime"
"github.com/stretchr/testify/assert"
)
func TestOutput(t *testing.T) {
assert := assert.New(t)
out, err := Register(map[string]interface{}{})
assert.Error(err)
assert.Nil(out)
out, err = Register(map[string]interface{}{
"path": "/tmp/raw.json",
})
os.Remove("/tmp/raw.json")
assert.NoError(err)
assert.NotNil(out)
out.Save(&runtime.Nodes{})
_, err = os.Stat("/tmp/raw.json")
assert.NoError(err)
}

45
output/raw/raw.go Normal file
View File

@ -0,0 +1,45 @@
package raw
import (
"github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/lib/jsontime"
"github.com/FreifunkBremen/yanic/runtime"
)
// Node struct
type RawNode struct {
Firstseen jsontime.Time `json:"firstseen"`
Lastseen jsontime.Time `json:"lastseen"`
Online bool `json:"online"`
Statistics *data.Statistics `json:"statistics"`
Nodeinfo *data.Nodeinfo `json:"nodeinfo"`
Neighbours *data.Neighbours `json:"neighbours"`
}
type NodeList struct {
Version string `json:"version"`
Timestamp jsontime.Time `json:"updated_at"` // Timestamp of the generation
List []*RawNode `json:"nodes"`
}
func transform(nodes *runtime.Nodes) *NodeList {
nodelist := &NodeList{
Version: "1.0.0",
Timestamp: jsontime.Now(),
}
for _, nodeOrigin := range nodes.List {
if nodeOrigin != nil {
node := &RawNode{
Firstseen: nodeOrigin.Firstseen,
Lastseen: nodeOrigin.Lastseen,
Online: nodeOrigin.Online,
Statistics: nodeOrigin.Statistics,
Nodeinfo: nodeOrigin.Nodeinfo,
Neighbours: nodeOrigin.Neighbours,
}
nodelist.List = append(nodelist.List, node)
}
}
return nodelist
}

67
output/raw/raw_test.go Normal file
View File

@ -0,0 +1,67 @@
package raw
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/FreifunkBremen/yanic/data"
"github.com/FreifunkBremen/yanic/runtime"
)
func TestTransform(t *testing.T) {
nodes := transform(createTestNodes())
assert := assert.New(t)
assert.Len(nodes.List, 3)
}
func createTestNodes() *runtime.Nodes {
nodes := runtime.NewNodes(&runtime.NodesConfig{})
nodeData := &runtime.Node{
Statistics: &data.Statistics{
Clients: data.Clients{
Total: 23,
},
},
Nodeinfo: &data.Nodeinfo{
NodeID: "abcdef012345",
Hardware: data.Hardware{
Model: "TP-Link 841",
},
},
}
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
nodes.AddNode(nodeData)
nodes.AddNode(&runtime.Node{
Statistics: &data.Statistics{
Clients: data.Clients{
Total: 2,
},
},
Nodeinfo: &data.Nodeinfo{
NodeID: "112233445566",
Hardware: data.Hardware{
Model: "TP-Link 841",
},
Location: &data.Location{
Latitude: 23,
Longitude: 2,
},
},
})
nodes.AddNode(&runtime.Node{
Nodeinfo: &data.Nodeinfo{
NodeID: "0xdeadbeef0x",
VPN: true,
Hardware: data.Hardware{
Model: "Xeon Multi-Core",
},
},
})
return nodes
}