Add source parameter

This commit is contained in:
davidnewhall2 2019-12-15 13:41:09 -08:00
parent 7026de1398
commit f287cf6d0c
8 changed files with 19 additions and 8 deletions

View File

@ -19,6 +19,8 @@ func (u *Unifi) GetClients(sites Sites) (Clients, error) {
}
for i, d := range response.Data {
// Add special SourceName value.
response.Data[i].SourceName = u.URL
// Add the special "Site Name" to each client. This becomes a Grafana filter somewhere.
response.Data[i].SiteName = site.Desc + " (" + site.Name + ")"
// Fix name and hostname fields. Sometimes one or the other is blank.
@ -37,6 +39,7 @@ type Clients []*Client
// Client defines all the data a connected-network client contains.
type Client struct {
SourceName string `json:"-"`
Anomalies int64 `json:"anomalies,omitempty"`
ApMac string `json:"ap_mac"`
ApName string `json:"-"`

View File

@ -48,25 +48,25 @@ func (u *Unifi) parseDevices(data []json.RawMessage, siteName string) *Devices {
switch assetType { // Unmarshal again into the correct type..
case "uap":
dev := &UAP{SiteName: siteName}
dev := &UAP{SiteName: siteName, SourceName: u.URL}
if u.unmarshalDevice(assetType, r, dev) == nil {
dev.Name = pick(dev.Name, dev.Mac)
devices.UAPs = append(devices.UAPs, dev)
}
case "ugw", "usg": // in case they ever fix the name in the api.
dev := &USG{SiteName: siteName}
dev := &USG{SiteName: siteName, SourceName: u.URL}
if u.unmarshalDevice(assetType, r, dev) == nil {
dev.Name = pick(dev.Name, dev.Mac)
devices.USGs = append(devices.USGs, dev)
}
case "usw":
dev := &USW{SiteName: siteName}
dev := &USW{SiteName: siteName, SourceName: u.URL}
if u.unmarshalDevice(assetType, r, dev) == nil {
dev.Name = pick(dev.Name, dev.Mac)
devices.USWs = append(devices.USWs, dev)
}
case "udm":
dev := &UDM{SiteName: siteName}
dev := &UDM{SiteName: siteName, SourceName: u.URL}
if u.unmarshalDevice(assetType, r, dev) == nil {
dev.Name = pick(dev.Name, dev.Mac)
devices.UDMs = append(devices.UDMs, dev)

View File

@ -13,6 +13,7 @@ type IDSList []*IDS
// IDS holds an Intrusion Prevention System Event.
type IDS struct {
SourceName string `json:"-"`
ID string `json:"_id"`
Archived FlexBool `json:"archived"`
Timestamp int64 `json:"timestamp"`
@ -94,7 +95,9 @@ func (u *Unifi) GetIDS(sites Sites, from, to time.Time) ([]*IDS, error) {
if err != nil {
return data, err
}
for i := range ids {
ids[i].SourceName = u.URL
}
data = append(data, ids...)
}

View File

@ -15,6 +15,8 @@ func (u *Unifi) GetSites() (Sites, error) {
sites := []string{} // used for debug log only
for i, d := range response.Data {
// Add special SourceName value.
response.Data[i].SourceName = u.URL
// If the human name is missing (description), set it to the cryptic name.
response.Data[i].Desc = pick(d.Desc, d.Name)
// Add the custom site name to each site. used as a Grafana filter somewhere.
@ -32,6 +34,7 @@ type Sites []*Site
// Site represents a site's data.
type Site struct {
SourceName string `json:"-"`
ID string `json:"_id"`
Name string `json:"name"`
Desc string `json:"desc"`

View File

@ -6,10 +6,9 @@ import (
)
// UAP represents all the data from the Ubiquiti Controller for a Unifi Access Point.
// This was auto generated then edited by hand to get all the data types right.
type UAP struct {
/* This was auto generated and then slowly edited by hand
to get all the data types right and graphable.
*/
SourceName string `json:"-"`
ID string `json:"_id"`
Adopted FlexBool `json:"adopted"`
AntennaTable []struct {

View File

@ -3,6 +3,7 @@ package unifi
// UDM represents all the data from the Ubiquiti Controller for a Unifi Dream Machine.
// The UDM shares several structs/type-data with USW and USG.
type UDM struct {
SourceName string `json:"-"`
SiteID string `json:"site_id"`
SiteName string `json:"-"`
Mac string `json:"mac"`

View File

@ -7,6 +7,7 @@ import (
// USG represents all the data from the Ubiquiti Controller for a Unifi Security Gateway.
type USG struct {
SourceName string `json:"-"`
ID string `json:"_id"`
Adopted FlexBool `json:"adopted"`
Cfgversion string `json:"cfgversion"`

View File

@ -7,6 +7,7 @@ import (
// USW represents all the data from the Ubiquiti Controller for a Unifi Switch.
type USW struct {
SourceName string `json:"-"`
SiteName string `json:"-"`
ID string `json:"_id"`
Adopted FlexBool `json:"adopted"`