extra data for breminale

This commit is contained in:
Martin Geno 2016-06-19 00:01:12 +02:00
parent 5b26b6bf88
commit 4da0b97f38
6 changed files with 61 additions and 41 deletions

View File

@ -32,9 +32,10 @@ func NewAliases(config *models.Config, router *httprouter.Router, prefix string,
func (api *ApiAliases) cleaner() { func (api *ApiAliases) cleaner() {
for key, alias := range api.aliases.List { for key, alias := range api.aliases.List {
if node := api.nodes.List[key]; node != nil { if node := api.nodes.List[key]; node != nil {
//counter for the diffrent attribute
count := 0
if nodeinfo := node.Nodeinfo; nodeinfo != nil { if nodeinfo := node.Nodeinfo; nodeinfo != nil {
//counter for the diffrent attribute count += 3
count := 3
if alias.Hostname == nodeinfo.Hostname { if alias.Hostname == nodeinfo.Hostname {
count -= 1 count -= 1
} }
@ -46,25 +47,31 @@ func (api *ApiAliases) cleaner() {
count -= 1 count -= 1
} }
} }
/* if nodeinfo.Settings != nil {
if alias.Freq24.TxPower == nodeinfo.Freq24.TxPower { if nodeinfo.Settings.Freq24 != nil {
count -= 1 count += 2
if alias.Freq24.TxPower == nodeinfo.Settings.Freq24.TxPower {
count -= 1
}
if alias.Freq24.Channel == nodeinfo.Settings.Freq24.Channel {
count -= 1
}
} }
if alias.Freq24.Channel == nodeinfo.Freq24.Channel { if nodeinfo.Settings.Freq5 != nil {
count -= 1 count += 2
if alias.Freq5.TxPower == nodeinfo.Settings.Freq5.TxPower {
count -= 1
}
if alias.Freq5.Channel == nodeinfo.Settings.Freq5.Channel {
count -= 1
}
} }
if alias.Freq5.TxPower == nodeinfo.Freq5.TxPower {
count -= 1
}
if alias.Freq5.Channel == nodeinfo.Freq5.Channel {
count -= 1
}
*/
//delete element
if count <= 0 {
delete(api.aliases.List, key)
} }
} }
//delete element
if count <= 0 {
delete(api.aliases.List, key)
}
} }
} }
} }

14
data/breminale.go Normal file
View File

@ -0,0 +1,14 @@
package data
type Frequence struct {
TxPower uint32 `json:"txpower"`
Channel uint32 `json:"channel"`
}
type Settings struct {
Freq24 *Frequence `json:"freq24,omitempty"`
Freq5 *Frequence `json:"freq5,omitempty"`
}
type SwitchPort struct {
Speed uint32 `json:"speed"`
}

View File

@ -10,6 +10,7 @@ type NodeInfo struct {
Software Software `json:"software"` Software Software `json:"software"`
Hardware Hardware `json:"hardware"` Hardware Hardware `json:"hardware"`
VPN bool `json:"vpn"` VPN bool `json:"vpn"`
Settings *Settings `json:"settings,omitempty"`
} }
type BatInterface struct { type BatInterface struct {
Interfaces struct { Interfaces struct {
@ -20,10 +21,10 @@ type BatInterface struct {
} }
type Network struct { type Network struct {
Mac string `json:"mac"` Mac string `json:"mac"`
Addresses []string `json:"addresses"` Addresses []string `json:"addresses"`
Mesh map[string]*BatInterface `json:"mesh"` Mesh map[string]*BatInterface `json:"mesh"`
MeshInterfaces []string `json:"mesh_interfaces"` MeshInterfaces []string `json:"mesh_interfaces"`
} }
type Owner struct { type Owner struct {

View File

@ -8,16 +8,16 @@ package data
type Statistics struct { type Statistics struct {
NodeId string `json:"node_id"` NodeId string `json:"node_id"`
Clients Clients `json:"clients"` Clients Clients `json:"clients"`
RootFsUsage float64 `json:"rootfs_usage,omitempty""` RootFsUsage float64 `json:"rootfs_usage,omitempty"`
LoadAverage float64 `json:"loadavg,omitempty""` LoadAverage float64 `json:"loadavg,omitempty"`
Memory Memory `json:"memory,omitempty""` Memory Memory `json:"memory,omitempty"`
Uptime float64 `json:"uptime,omitempty""` Uptime float64 `json:"uptime,omitempty"`
Idletime float64 `json:"idletime,omitempty""` Idletime float64 `json:"idletime,omitempty"`
Gateway string `json:"gateway,omitempty""` Gateway string `json:"gateway,omitempty"`
Processes struct { Processes struct {
Total uint32 `json:"total"` Total uint32 `json:"total"`
Running uint32 `json:"running"` Running uint32 `json:"running"`
} `json:"processes,omitempty""` } `json:"processes,omitempty"`
MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"` MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"`
Traffic struct { Traffic struct {
Tx *Traffic `json:"tx"` Tx *Traffic `json:"tx"`
@ -25,7 +25,8 @@ type Statistics struct {
Forward *Traffic `json:"forward"` Forward *Traffic `json:"forward"`
MgmtTx *Traffic `json:"mgmt_tx"` MgmtTx *Traffic `json:"mgmt_tx"`
MgmtRx *Traffic `json:"mgmt_rx"` MgmtRx *Traffic `json:"mgmt_rx"`
} `json:"traffic,omitempty""` } `json:"traffic,omitempty"`
Switch map[string]*SwitchPort `json:"switch,omitempty"`
} }
type MeshVPNPeerLink struct { type MeshVPNPeerLink struct {

View File

@ -11,14 +11,10 @@ import (
) )
type Alias struct { type Alias struct {
Hostname string `json:"hostname,omitempty"` Hostname string `json:"hostname,omitempty"`
Location *data.Location `json:"location,omitempty"` Location *data.Location `json:"location,omitempty"`
Freq24 *Frequence `json:"freq24,omitempty"` Freq24 *data.Frequence `json:"freq24,omitempty"`
Freq5 *Frequence `json:"freq5,omitempty"` Freq5 *data.Frequence `json:"freq5,omitempty"`
}
type Frequence struct {
TxPower int `json:"txpower,omitempty"`
Channel int `json:"channel,omitempty"`
} }
// Nodes struct: cache DB of Node's structs // Nodes struct: cache DB of Node's structs

View File

@ -9,16 +9,17 @@ type Ansible struct {
type AnsibleHostVars struct { type AnsibleHostVars struct {
Address string `json:"ansible_ssh_host"` Address string `json:"ansible_ssh_host"`
Hostname string `json:"node_name,omitempty"` Hostname string `json:"node_name,omitempty"`
Channel24 int `json:"radio24_channel,omitempty"` Channel24 uint32 `json:"radio24_channel,omitempty"`
TxPower24 int `json:"radio24_txpower,omitempty"` TxPower24 uint32 `json:"radio24_txpower,omitempty"`
Channel5 int `json:"radio5_channel,omitempty"` Channel5 uint32 `json:"radio5_channel,omitempty"`
TxPower5 int `json:"radio5_txpower,omitempty"` TxPower5 uint32 `json:"radio5_txpower,omitempty"`
GeoLatitude float64 `json:"geo_latitude,omitempty"` GeoLatitude float64 `json:"geo_latitude,omitempty"`
GeoLongitude float64 `json:"geo_longitude,omitempty"` GeoLongitude float64 `json:"geo_longitude,omitempty"`
} }
func GenerateAnsible(nodes *Nodes, aliases map[string]*Alias) *Ansible { func GenerateAnsible(nodes *Nodes, aliases map[string]*Alias) *Ansible {
ansible := &Ansible{Nodes: make([]string, 0)} ansible := &Ansible{Nodes: make([]string, 0)}
ansible.Meta.HostVars = make(map[string]*AnsibleHostVars)
for nodeid, alias := range aliases { for nodeid, alias := range aliases {
if node := nodes.List[nodeid]; node != nil { if node := nodes.List[nodeid]; node != nil {