diff --git a/core/unifi/clients.go b/core/unifi/clients.go index a6be75c4..b9bcad71 100644 --- a/core/unifi/clients.go +++ b/core/unifi/clients.go @@ -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:"-"` diff --git a/core/unifi/devices.go b/core/unifi/devices.go index f6e77a65..d877d9c4 100644 --- a/core/unifi/devices.go +++ b/core/unifi/devices.go @@ -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) diff --git a/core/unifi/ids.go b/core/unifi/ids.go index c0ece97c..7bb4232c 100644 --- a/core/unifi/ids.go +++ b/core/unifi/ids.go @@ -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...) } diff --git a/core/unifi/site.go b/core/unifi/site.go index ae0df3a8..2789a8b6 100644 --- a/core/unifi/site.go +++ b/core/unifi/site.go @@ -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"` diff --git a/core/unifi/uap.go b/core/unifi/uap.go index 6e1238a6..172504b8 100644 --- a/core/unifi/uap.go +++ b/core/unifi/uap.go @@ -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 { diff --git a/core/unifi/udm.go b/core/unifi/udm.go index 51382435..172d0908 100644 --- a/core/unifi/udm.go +++ b/core/unifi/udm.go @@ -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"` diff --git a/core/unifi/usg.go b/core/unifi/usg.go index 42321fbc..d7aff5a1 100644 --- a/core/unifi/usg.go +++ b/core/unifi/usg.go @@ -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"` diff --git a/core/unifi/usw.go b/core/unifi/usw.go index d6eca554..242b2053 100644 --- a/core/unifi/usw.go +++ b/core/unifi/usw.go @@ -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"`