Skip to content

Commit

Permalink
Fixing interface api (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
i3149 authored Sep 10, 2024
1 parent fa13592 commit 4ae9737
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 33 deletions.
22 changes: 19 additions & 3 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ func (api *KentikApi) GetDevice(cid kt.Cid, did kt.DeviceID) *kt.Device {
return nil
}

func (api *KentikApi) getInterfaces(ctx context.Context, did kt.DeviceID, info ktranslate.KentikCred) ([]kt.Interface, error) {
res, err := api.getDeviceInfo(ctx, fmt.Sprintf(api.config.APIBaseURL+"/api/internal/device/%d/interfaces", did), info.APIEmail, info.APIToken)
if err != nil {
return nil, err
}
interfaces := []kt.Interface{}
err = json.Unmarshal(res, &interfaces)
return interfaces, err
}

func (api *KentikApi) getDevices(ctx context.Context) error {
stime := time.Now()
resDev := map[kt.Cid]kt.Devices{}
Expand All @@ -254,9 +264,15 @@ func (api *KentikApi) getDevices(ctx context.Context) error {
if _, ok := resDev[device.CompanyID]; !ok {
resDev[device.CompanyID] = map[kt.DeviceID]*kt.Device{}
}
device.Interfaces = map[kt.IfaceID]kt.Interface{}
for _, intf := range device.AllInterfaces {
device.Interfaces[intf.SnmpID] = intf
myd.Interfaces = map[kt.IfaceID]kt.Interface{}
interfaces, err := api.getInterfaces(ctx, device.ID, info)
if err != nil {
api.Errorf("Cannot get interfaces for %v: %v", device.Name, err)
} else {
for _, intf := range interfaces {
intfl := intf // Should this be a pointer?
myd.Interfaces[intf.SnmpID] = intfl
}
}
resDev[device.CompanyID][device.ID] = &myd
num++
Expand Down
20 changes: 10 additions & 10 deletions pkg/cat/jchf.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,22 @@ func (kc *KTranslate) flowToJCHF(ctx context.Context, dst *kt.JCHF, src *Flow, c
dst.CustomStr["SamplerAddress"] = d.SendingIps[0].String()
}
if i, ok := d.Interfaces[dst.InputPort]; ok {
dst.InputIntDesc = i.InterfaceDescription
dst.InputIntAlias = i.SnmpAlias
dst.InputIntDesc = i.Description
dst.InputIntAlias = i.Alias
dst.InputInterfaceCapacity = i.SnmpSpeedMbps
dst.InputInterfaceIP = i.InterfaceIP
dst.InputInterfaceIP = i.Address
dst.CustomStr["input_provider"] = i.Provider
dst.CustomStr["input_site_title"] = i.SiteTitle
dst.CustomStr["input_site_country"] = i.SiteCountry
dst.CustomStr["input_network_boundary"] = i.NetworkBoundary
dst.CustomStr["input_connectivity_type"] = i.ConnectivityType
}
if i, ok := d.Interfaces[dst.OutputPort]; ok {
dst.OutputIntDesc = i.InterfaceDescription
dst.OutputIntAlias = i.SnmpAlias
dst.OutputIntDesc = i.Description
dst.OutputIntAlias = i.Alias
dst.OutputInterfaceCapacity = i.SnmpSpeedMbps
dst.OutputInterfaceIP = i.InterfaceIP
dst.OutputInterfaceIP = i.Address
dst.CustomStr["output_provider"] = i.Provider
dst.CustomStr["output_site_title"] = i.SiteTitle
dst.CustomStr["output_site_country"] = i.SiteCountry
dst.CustomStr["output_network_boundary"] = i.NetworkBoundary
dst.CustomStr["output_connectivity_type"] = i.ConnectivityType
}
}

Expand Down
37 changes: 17 additions & 20 deletions pkg/kt/device_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,23 @@ type InterfaceCapacityBPS = uint64
// It corresponds to a row in mn_interface, joined with information
// from mn_device and mn_site.
type Interface struct {
ID int64 `json:"id"`

DeviceID DeviceID `json:"device_id,string"`
DeviceName string `json:"device_name"`
DeviceType string `json:"device_type"`
SiteID int `json:"site_id"`

SnmpID IfaceID `json:"snmp_id,string"`
SnmpSpeedMbps int64 `json:"snmp_speed,string"` // unit? TODO: switch to uint64, rename to SnmpSpeedMbps
SnmpType int `json:"snmp_type"`
SnmpAlias string `json:"snmp_alias"`
InterfaceIP string `json:"interface_ip"`
InterfaceDescription string `json:"interface_description"`
Provider string `json:"provider"`
VrfID int64 `json:"vrf_id"`
Netmask string `json:"interface_ip_netmask"`
Addrs []Addr `json:"secondary_ips"`

SiteTitle string `json:"site_title"`
SiteCountry string `json:"site_country"`
DeviceID DeviceID `json:"device_id,string"`
Address string `json:"interface_ip"`
Netmask string `json:"interface_ip_netmask"`
Description string `json:"interface_description"`

NetworkBoundary string `json:"network_boundary"`
ConnectivityType string `json:"connectivity_type"`
Provider string `json:"provider"`

SnmpID IfaceID `json:"snmp_id,string"`
Alias string `json:"snmp_alias"`
Type uint64 `json:"snmp_type"`
SnmpSpeedMbps int64 `json:"snmp_speed,string"` // unit? TODO: switch to uint64, rename to SnmpSpeedMbps
SnmpType int `json:"snmp_type"`

Addrs []Addr `json:"secondary_ips"`
ExtraInfo map[string]string `json:"extra_info"`
}

type Addr struct {
Expand Down

0 comments on commit 4ae9737

Please sign in to comment.