add uptimes, rx/tx per client, controller id
This commit is contained in:
parent
a8423e36aa
commit
ad37984924
|
|
@ -93,7 +93,7 @@ func (u *InputUnifi) pollController(c *Controller) (*poller.Metrics, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m := &Metrics{TS: time.Now(), Sites: sites}
|
m := &Metrics{TS: time.Now(), Sites: sites}
|
||||||
defer updateWeb(m)
|
defer updateWeb(c, m)
|
||||||
|
|
||||||
if c.SaveDPI != nil && *c.SaveDPI {
|
if c.SaveDPI != nil && *c.SaveDPI {
|
||||||
if m.SitesDPI, err = c.Unifi.GetSiteDPI(sites); err != nil {
|
if m.SitesDPI, err = c.Unifi.GetSiteDPI(sites); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,5 @@ require (
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/unifi-poller/poller v0.0.8-0.20200628131550-26430cac16c1
|
github.com/unifi-poller/poller v0.0.8-0.20200628131550-26430cac16c1
|
||||||
github.com/unifi-poller/unifi v0.0.6-0.20200628213309-a22ea217874f
|
github.com/unifi-poller/unifi v0.0.6-0.20200628213309-a22ea217874f
|
||||||
github.com/unifi-poller/webserver v0.0.0-20200628214116-5bead091e113
|
github.com/unifi-poller/webserver v0.0.0-20200704065911-79e4fe954ce1
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,8 @@ github.com/unifi-poller/unifi v0.0.6-0.20200628213309-a22ea217874f h1:5aLy4Ac0vF
|
||||||
github.com/unifi-poller/unifi v0.0.6-0.20200628213309-a22ea217874f/go.mod h1:uqBaNCon8FTw6nwGsAYHz/HwBgEYepS0XB5XW+OdBts=
|
github.com/unifi-poller/unifi v0.0.6-0.20200628213309-a22ea217874f/go.mod h1:uqBaNCon8FTw6nwGsAYHz/HwBgEYepS0XB5XW+OdBts=
|
||||||
github.com/unifi-poller/webserver v0.0.0-20200628214116-5bead091e113 h1:W4mnKUc+JtKLiajAv1Np+9KHBTR+TC2o0NA1H4IGzjo=
|
github.com/unifi-poller/webserver v0.0.0-20200628214116-5bead091e113 h1:W4mnKUc+JtKLiajAv1Np+9KHBTR+TC2o0NA1H4IGzjo=
|
||||||
github.com/unifi-poller/webserver v0.0.0-20200628214116-5bead091e113/go.mod h1:08IX30eb93+VbhiFqgMBXQD52+djPwivBcx5C8fH92M=
|
github.com/unifi-poller/webserver v0.0.0-20200628214116-5bead091e113/go.mod h1:08IX30eb93+VbhiFqgMBXQD52+djPwivBcx5C8fH92M=
|
||||||
|
github.com/unifi-poller/webserver v0.0.0-20200704065911-79e4fe954ce1 h1:xjUOu//OP3dOc1X0K9d86WCoG4ezlrMWoeJOTHxECk0=
|
||||||
|
github.com/unifi-poller/webserver v0.0.0-20200704065911-79e4fe954ce1/go.mod h1:08IX30eb93+VbhiFqgMBXQD52+djPwivBcx5C8fH92M=
|
||||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ type Controller struct {
|
||||||
URL string `json:"url" toml:"url" xml:"url" yaml:"url"`
|
URL string `json:"url" toml:"url" xml:"url" yaml:"url"`
|
||||||
Sites []string `json:"sites" toml:"sites" xml:"site" yaml:"sites"`
|
Sites []string `json:"sites" toml:"sites" xml:"site" yaml:"sites"`
|
||||||
Unifi *unifi.Unifi `json:"-" toml:"-" xml:"-" yaml:"-"`
|
Unifi *unifi.Unifi `json:"-" toml:"-" xml:"-" yaml:"-"`
|
||||||
|
ID string `json:"id,omitempty"` // this is an output, not an input.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config contains our configuration data.
|
// Config contains our configuration data.
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ import (
|
||||||
|
|
||||||
/* This code reformats our data to be displayed on the built-in web interface. */
|
/* This code reformats our data to be displayed on the built-in web interface. */
|
||||||
|
|
||||||
func updateWeb(metrics *Metrics) {
|
func updateWeb(c *Controller, metrics *Metrics) {
|
||||||
webserver.UpdateInput(&webserver.Input{
|
webserver.UpdateInput(&webserver.Input{
|
||||||
Name: PluginName, // Forgetting this leads to 3 hours of head scratching.
|
Name: PluginName, // Forgetting this leads to 3 hours of head scratching.
|
||||||
Sites: formatSites(metrics.Sites),
|
Sites: formatSites(c, metrics.Sites),
|
||||||
Clients: formatClients(metrics.Clients),
|
Clients: formatClients(c, metrics.Clients),
|
||||||
Devices: formatDevices(metrics.Devices),
|
Devices: formatDevices(c, metrics.Devices),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +31,13 @@ func formatConfig(config *Config) *Config {
|
||||||
|
|
||||||
func formatControllers(controllers []*Controller) []*Controller {
|
func formatControllers(controllers []*Controller) []*Controller {
|
||||||
fixed := []*Controller{}
|
fixed := []*Controller{}
|
||||||
|
|
||||||
for _, c := range controllers {
|
for _, c := range controllers {
|
||||||
|
id := ""
|
||||||
|
if c.Unifi != nil {
|
||||||
|
id = c.Unifi.UUID
|
||||||
|
}
|
||||||
|
|
||||||
fixed = append(fixed, &Controller{
|
fixed = append(fixed, &Controller{
|
||||||
VerifySSL: c.VerifySSL,
|
VerifySSL: c.VerifySSL,
|
||||||
SaveAnomal: c.SaveAnomal,
|
SaveAnomal: c.SaveAnomal,
|
||||||
|
|
@ -45,26 +51,28 @@ func formatControllers(controllers []*Controller) []*Controller {
|
||||||
Pass: strconv.FormatBool(c.Pass != ""),
|
Pass: strconv.FormatBool(c.Pass != ""),
|
||||||
URL: c.URL,
|
URL: c.URL,
|
||||||
Sites: c.Sites,
|
Sites: c.Sites,
|
||||||
|
ID: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return fixed
|
return fixed
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatSites(sites []*unifi.Site) (s webserver.Sites) {
|
func formatSites(c *Controller, sites []*unifi.Site) (s webserver.Sites) {
|
||||||
for _, site := range sites {
|
for _, site := range sites {
|
||||||
s = append(s, &webserver.Site{
|
s = append(s, &webserver.Site{
|
||||||
ID: site.ID,
|
ID: site.ID,
|
||||||
Name: site.Name,
|
Name: site.Name,
|
||||||
Desc: site.Desc,
|
Desc: site.Desc,
|
||||||
Source: site.SourceName,
|
Source: site.SourceName,
|
||||||
|
Controller: c.Unifi.UUID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatClients(clients []*unifi.Client) (c webserver.Clients) {
|
func formatClients(c *Controller, clients []*unifi.Client) (d webserver.Clients) {
|
||||||
for _, client := range clients {
|
for _, client := range clients {
|
||||||
clientType, deviceMAC := "unknown", "unknown"
|
clientType, deviceMAC := "unknown", "unknown"
|
||||||
if client.ApMac != "" {
|
if client.ApMac != "" {
|
||||||
|
|
@ -79,76 +87,91 @@ func formatClients(clients []*unifi.Client) (c webserver.Clients) {
|
||||||
deviceMAC = client.GwMac
|
deviceMAC = client.GwMac
|
||||||
}
|
}
|
||||||
|
|
||||||
c = append(c, &webserver.Client{
|
d = append(d, &webserver.Client{
|
||||||
Name: client.Name,
|
Name: client.Name,
|
||||||
SiteID: client.SiteID,
|
SiteID: client.SiteID,
|
||||||
Source: client.SourceName,
|
Source: client.SourceName,
|
||||||
MAC: client.Mac,
|
Controller: c.Unifi.UUID,
|
||||||
IP: client.IP,
|
MAC: client.Mac,
|
||||||
Type: clientType,
|
IP: client.IP,
|
||||||
DeviceMAC: deviceMAC,
|
Type: clientType,
|
||||||
Since: time.Unix(client.FirstSeen, 0),
|
DeviceMAC: deviceMAC,
|
||||||
Last: time.Unix(client.LastSeen, 0),
|
Rx: client.RxBytes,
|
||||||
|
Tx: client.TxBytes,
|
||||||
|
Since: time.Unix(client.FirstSeen, 0),
|
||||||
|
Last: time.Unix(client.LastSeen, 0),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatDevices(devices *unifi.Devices) (d webserver.Devices) {
|
func formatDevices(c *Controller, devices *unifi.Devices) (d webserver.Devices) { // nolint: funlen
|
||||||
for _, device := range devices.UAPs {
|
for _, device := range devices.UAPs {
|
||||||
d = append(d, &webserver.Device{
|
d = append(d, &webserver.Device{
|
||||||
Name: device.Name,
|
Name: device.Name,
|
||||||
SiteID: device.SiteID,
|
SiteID: device.SiteID,
|
||||||
Source: device.SourceName,
|
Source: device.SourceName,
|
||||||
MAC: device.Mac,
|
Controller: c.Unifi.UUID,
|
||||||
IP: device.IP,
|
MAC: device.Mac,
|
||||||
Type: device.Type,
|
IP: device.IP,
|
||||||
Model: device.Model,
|
Type: device.Type,
|
||||||
Version: device.Version,
|
Model: device.Model,
|
||||||
Config: nil,
|
Version: device.Version,
|
||||||
|
Uptime: int(device.Uptime.Val),
|
||||||
|
Clients: int(device.NumSta.Val),
|
||||||
|
Config: nil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, device := range devices.UDMs {
|
for _, device := range devices.UDMs {
|
||||||
d = append(d, &webserver.Device{
|
d = append(d, &webserver.Device{
|
||||||
Name: device.Name,
|
Name: device.Name,
|
||||||
SiteID: device.SiteID,
|
SiteID: device.SiteID,
|
||||||
Source: device.SourceName,
|
Source: device.SourceName,
|
||||||
MAC: device.Mac,
|
Controller: c.Unifi.UUID,
|
||||||
IP: device.IP,
|
MAC: device.Mac,
|
||||||
Type: device.Type,
|
IP: device.IP,
|
||||||
Model: device.Model,
|
Type: device.Type,
|
||||||
Version: device.Version,
|
Model: device.Model,
|
||||||
Config: nil,
|
Version: device.Version,
|
||||||
|
Uptime: int(device.Uptime.Val),
|
||||||
|
Clients: int(device.NumSta.Val),
|
||||||
|
Config: nil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, device := range devices.USWs {
|
for _, device := range devices.USWs {
|
||||||
d = append(d, &webserver.Device{
|
d = append(d, &webserver.Device{
|
||||||
Name: device.Name,
|
Name: device.Name,
|
||||||
SiteID: device.SiteID,
|
SiteID: device.SiteID,
|
||||||
Source: device.SourceName,
|
Source: device.SourceName,
|
||||||
MAC: device.Mac,
|
Controller: c.Unifi.UUID,
|
||||||
IP: device.IP,
|
MAC: device.Mac,
|
||||||
Type: device.Type,
|
IP: device.IP,
|
||||||
Model: device.Model,
|
Type: device.Type,
|
||||||
Version: device.Version,
|
Model: device.Model,
|
||||||
Config: nil,
|
Version: device.Version,
|
||||||
|
Uptime: int(device.Uptime.Val),
|
||||||
|
Clients: int(device.NumSta.Val),
|
||||||
|
Config: nil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, device := range devices.USGs {
|
for _, device := range devices.USGs {
|
||||||
d = append(d, &webserver.Device{
|
d = append(d, &webserver.Device{
|
||||||
Name: device.Name,
|
Name: device.Name,
|
||||||
SiteID: device.SiteID,
|
SiteID: device.SiteID,
|
||||||
Source: device.SourceName,
|
Source: device.SourceName,
|
||||||
MAC: device.Mac,
|
Controller: c.Unifi.UUID,
|
||||||
IP: device.IP,
|
MAC: device.Mac,
|
||||||
Type: device.Type,
|
IP: device.IP,
|
||||||
Model: device.Model,
|
Type: device.Type,
|
||||||
Version: device.Version,
|
Model: device.Model,
|
||||||
Config: nil,
|
Version: device.Version,
|
||||||
|
Uptime: int(device.Uptime.Val),
|
||||||
|
Clients: int(device.NumSta.Val),
|
||||||
|
Config: nil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue