diff --git a/api/aliases.go b/api/aliases.go index 2079139..b8d1fc3 100644 --- a/api/aliases.go +++ b/api/aliases.go @@ -32,9 +32,10 @@ func NewAliases(config *models.Config, router *httprouter.Router, prefix string, func (api *ApiAliases) cleaner() { for key, alias := range api.aliases.List { if node := api.nodes.List[key]; node != nil { + //counter for the diffrent attribute + count := 0 if nodeinfo := node.Nodeinfo; nodeinfo != nil { - //counter for the diffrent attribute - count := 3 + count += 3 if alias.Hostname == nodeinfo.Hostname { count -= 1 } @@ -46,25 +47,31 @@ func (api *ApiAliases) cleaner() { count -= 1 } } - /* - if alias.Freq24.TxPower == nodeinfo.Freq24.TxPower { - count -= 1 + if nodeinfo.Settings != nil { + if nodeinfo.Settings.Freq24 != nil { + 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 { - count -= 1 + if nodeinfo.Settings.Freq5 != nil { + 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) + } } } } diff --git a/data/breminale.go b/data/breminale.go new file mode 100644 index 0000000..b937304 --- /dev/null +++ b/data/breminale.go @@ -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"` +} diff --git a/data/nodeinfo.go b/data/nodeinfo.go index 2dcaf4b..3a4b2fc 100644 --- a/data/nodeinfo.go +++ b/data/nodeinfo.go @@ -10,6 +10,7 @@ type NodeInfo struct { Software Software `json:"software"` Hardware Hardware `json:"hardware"` VPN bool `json:"vpn"` + Settings *Settings `json:"settings,omitempty"` } type BatInterface struct { Interfaces struct { @@ -20,10 +21,10 @@ type BatInterface struct { } type Network struct { - Mac string `json:"mac"` - Addresses []string `json:"addresses"` - Mesh map[string]*BatInterface `json:"mesh"` - MeshInterfaces []string `json:"mesh_interfaces"` + Mac string `json:"mac"` + Addresses []string `json:"addresses"` + Mesh map[string]*BatInterface `json:"mesh"` + MeshInterfaces []string `json:"mesh_interfaces"` } type Owner struct { diff --git a/data/statistics.go b/data/statistics.go index 4b033bc..b7cd57c 100644 --- a/data/statistics.go +++ b/data/statistics.go @@ -8,16 +8,16 @@ package data type Statistics struct { NodeId string `json:"node_id"` Clients Clients `json:"clients"` - RootFsUsage float64 `json:"rootfs_usage,omitempty""` - LoadAverage float64 `json:"loadavg,omitempty""` - Memory Memory `json:"memory,omitempty""` - Uptime float64 `json:"uptime,omitempty""` - Idletime float64 `json:"idletime,omitempty""` - Gateway string `json:"gateway,omitempty""` + RootFsUsage float64 `json:"rootfs_usage,omitempty"` + LoadAverage float64 `json:"loadavg,omitempty"` + Memory Memory `json:"memory,omitempty"` + Uptime float64 `json:"uptime,omitempty"` + Idletime float64 `json:"idletime,omitempty"` + Gateway string `json:"gateway,omitempty"` Processes struct { Total uint32 `json:"total"` Running uint32 `json:"running"` - } `json:"processes,omitempty""` + } `json:"processes,omitempty"` MeshVpn *MeshVPN `json:"mesh_vpn,omitempty"` Traffic struct { Tx *Traffic `json:"tx"` @@ -25,7 +25,8 @@ type Statistics struct { Forward *Traffic `json:"forward"` MgmtTx *Traffic `json:"mgmt_tx"` MgmtRx *Traffic `json:"mgmt_rx"` - } `json:"traffic,omitempty""` + } `json:"traffic,omitempty"` + Switch map[string]*SwitchPort `json:"switch,omitempty"` } type MeshVPNPeerLink struct { diff --git a/models/aliases.go b/models/aliases.go index 2f5abe6..3e3fa7d 100644 --- a/models/aliases.go +++ b/models/aliases.go @@ -11,14 +11,10 @@ import ( ) type Alias struct { - Hostname string `json:"hostname,omitempty"` - Location *data.Location `json:"location,omitempty"` - Freq24 *Frequence `json:"freq24,omitempty"` - Freq5 *Frequence `json:"freq5,omitempty"` -} -type Frequence struct { - TxPower int `json:"txpower,omitempty"` - Channel int `json:"channel,omitempty"` + Hostname string `json:"hostname,omitempty"` + Location *data.Location `json:"location,omitempty"` + Freq24 *data.Frequence `json:"freq24,omitempty"` + Freq5 *data.Frequence `json:"freq5,omitempty"` } // Nodes struct: cache DB of Node's structs diff --git a/models/ansible.go b/models/ansible.go index 8dd6bcd..b5a600a 100644 --- a/models/ansible.go +++ b/models/ansible.go @@ -9,16 +9,17 @@ type Ansible struct { type AnsibleHostVars struct { Address string `json:"ansible_ssh_host"` Hostname string `json:"node_name,omitempty"` - Channel24 int `json:"radio24_channel,omitempty"` - TxPower24 int `json:"radio24_txpower,omitempty"` - Channel5 int `json:"radio5_channel,omitempty"` - TxPower5 int `json:"radio5_txpower,omitempty"` + Channel24 uint32 `json:"radio24_channel,omitempty"` + TxPower24 uint32 `json:"radio24_txpower,omitempty"` + Channel5 uint32 `json:"radio5_channel,omitempty"` + TxPower5 uint32 `json:"radio5_txpower,omitempty"` GeoLatitude float64 `json:"geo_latitude,omitempty"` GeoLongitude float64 `json:"geo_longitude,omitempty"` } func GenerateAnsible(nodes *Nodes, aliases map[string]*Alias) *Ansible { ansible := &Ansible{Nodes: make([]string, 0)} + ansible.Meta.HostVars = make(map[string]*AnsibleHostVars) for nodeid, alias := range aliases { if node := nodes.List[nodeid]; node != nil {