Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing interface api #747

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading