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

Pre release #66

Merged
merged 7 commits into from
Aug 10, 2021
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
146 changes: 134 additions & 12 deletions config/codecommunicator/junos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,131 @@ func (c *junosCommunicator) GetInterfaces(ctx context.Context) ([]device.Interfa
return nil, err
}

interfacesWithVLANs, err := juniperAddVLANsNonELS(ctx, interfaces)
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("getting juniper VLANs for non ELS devices failed, trying for ELS devices")
interfacesWithVLANs, err = juniperAddVLANsELS(ctx, interfaces)
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("getting juniper VLANs for ELS devices failed, skipping VLANs")
interfacesWithVLANs = interfaces
}
}

return interfacesWithVLANs, nil
}

func juniperAddVLANsELS(ctx context.Context, interfaces []device.Interface) ([]device.Interface, error) {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("snmp client is empty")
}

// dot1dBasePortIfIndex
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.2.1.17.1.4.1.2")
// jnxL2aldVlanFdbId
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.48.1.3.1.1.5")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get dot1dBasePortIfIndex, skipping VLANs")
return interfaces, nil
return nil, errors.Wrap(err, "failed to get jnxL2aldVlanFdbId")
}

portIfIndex := make(map[string]string)
vlanIndexFilterID := make(map[string]string)
for _, response := range res {
ifIndex, err := response.GetValueString()
filterID, err := response.GetValueString()
if err != nil {
return nil, err
}

oid := response.GetOID()
oidSplit := strings.Split(oid, ".")

portIfIndex[oidSplit[len(oidSplit)-1]] = ifIndex
vlanIndexFilterID[oidSplit[len(oidSplit)-1]] = filterID
}

// jnxL2aldVlanName
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.48.1.3.1.1.2")
if err != nil {
return nil, errors.Wrap(err, "failed to get jnxL2aldVlanName")
}

filterIDVLAN := make(map[string]device.VLAN)
for _, response := range res {
name, err := response.GetValueString()
if err != nil {
return nil, err
}

oid := response.GetOID()
oidSplit := strings.Split(oid, ".")
filterID := vlanIndexFilterID[oidSplit[len(oidSplit)-1]]

filterIDVLAN[filterID] = device.VLAN{
Name: name,
}
}

portIfIndex, err := juniperGetPortIfIndexMapping(ctx)
if err != nil {
return nil, err
}

// dot1qTpFdbPort
dot1qTpFdbPort := "1.3.6.1.2.1.17.7.1.2.2.1.2"
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, dot1qTpFdbPort)
if err != nil {
return nil, errors.Wrap(err, "failed to get dot1qTpFdbPort")
}

ifIndexFilterIDs := make(map[string][]string)
out:
for _, response := range res {
port, err := response.GetValueString()
if err != nil {
return nil, err
}

oid := strings.TrimPrefix(response.GetOID(), ".")
oidSplit := strings.Split(strings.TrimPrefix(strings.TrimPrefix(oid, dot1qTpFdbPort), "."), ".")
ifIndex := portIfIndex[port]

for _, filterID := range ifIndexFilterIDs[ifIndex] {
if filterID == oidSplit[0] {
continue out
}
}
ifIndexFilterIDs[ifIndex] = append(ifIndexFilterIDs[ifIndex], oidSplit[0])
}

for i, interf := range interfaces {
if interf.IfIndex != nil {
if filterIDs, ok := ifIndexFilterIDs[fmt.Sprint(*interf.IfIndex)]; ok {
for _, filterID := range filterIDs {
if vlan, ok := filterIDVLAN[filterID]; ok {
if interfaces[i].VLAN == nil {
interfaces[i].VLAN = &device.VLANInformation{}
}
interfaces[i].VLAN.VLANs = append(interfaces[i].VLAN.VLANs, vlan)
}
}
}
}
}

return interfaces, nil
}

func juniperAddVLANsNonELS(ctx context.Context, interfaces []device.Interface) ([]device.Interface, error) {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("snmp client is empty")
}

// jnxExVlanPortStatus
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.40.1.5.1.7.1.3")
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.40.1.5.1.7.1.3")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get jnxExVlanPortStatus, skipping VLANs")
return interfaces, nil
return nil, errors.Wrap(err, "failed to get jnxExVlanPortStatus")
}

portIfIndex, err := juniperGetPortIfIndexMapping(ctx)
if err != nil {
return nil, err
}

vlanIndexVLAN := make(map[string]device.VLAN)
Expand All @@ -73,8 +168,7 @@ func (c *junosCommunicator) GetInterfaces(ctx context.Context) ([]device.Interfa
// jnxExVlanName
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.40.1.5.1.5.1.2")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get jnxExVlanName, skipping VLANs")
return interfaces, nil
return nil, errors.Wrap(err, "failed to get jnxExVlanName")
}

for _, response := range res {
Expand Down Expand Up @@ -109,3 +203,31 @@ func (c *junosCommunicator) GetInterfaces(ctx context.Context) ([]device.Interfa

return interfaces, nil
}

func juniperGetPortIfIndexMapping(ctx context.Context) (map[string]string, error) {
con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("snmp client is empty")
}

// dot1dBasePortIfIndex
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.2.1.17.1.4.1.2")
if err != nil {
return nil, errors.Wrap(err, "failed to get dot1dBasePortIfIndex")
}

portIfIndex := make(map[string]string)
for _, response := range res {
ifIndex, err := response.GetValueString()
if err != nil {
return nil, err
}

oid := response.GetOID()
oidSplit := strings.Split(oid, ".")

portIfIndex[oidSplit[len(oidSplit)-1]] = ifIndex
}

return portIfIndex, nil
}
2 changes: 1 addition & 1 deletion doc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
package doc

// Version specifies the current version.
const Version = "v0.3.4"
const Version = "v0.3.5"
3 changes: 1 addition & 2 deletions internal/communicator/deviceclass/group_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *deviceClassOIDs) readOID(ctx context.Context) (map[int]interface{}, err
res, err := reader.readOID(ctx)
if err != nil {
if tholaerr.IsNotFoundError(err) || tholaerr.IsComponentNotFoundError(err) {
log.Ctx(ctx).Debug().Err(err).Msgf("value %s", label)
log.Ctx(ctx).Debug().Err(err).Msgf("failed to get value '%s'", label)
continue
}
return nil, errors.Wrapf(err, "failed to get value '%s'", label)
Expand Down Expand Up @@ -141,7 +141,6 @@ func (d *deviceClassOID) readOID(ctx context.Context) (map[int]interface{}, erro
snmpResponse, err := con.SNMP.SnmpClient.SNMPWalk(ctx, string(d.OID))
if err != nil {
if tholaerr.IsNotFoundError(err) {
log.Ctx(ctx).Debug().Err(err).Msgf("oid %s not found on device", d.OID)
return nil, err
}
log.Ctx(ctx).Debug().Err(err).Msg("failed to get oid value of interface")
Expand Down
8 changes: 0 additions & 8 deletions internal/request/check_interface_metrics_request_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,12 @@ func addCheckInterfacePerformanceData(interfaces []device.Interface, r *monitori
if err != nil {
return err
}
err = r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("interface_maxspeed_in", *i.SAP.Inbound).SetLabel(*i.IfDescr))
if err != nil {
return err
}
}
if i.SAP.Outbound != nil {
err := r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("traffic_counter_out", *i.SAP.Outbound).SetUnit("c").SetLabel(*i.IfDescr))
if err != nil {
return err
}
err = r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("interface_maxspeed_out", *i.SAP.Outbound).SetLabel(*i.IfDescr))
if err != nil {
return err
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/request/get_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func GetCommunicator(ctx context.Context, baseRequest BaseRequest) (communicator
log.Ctx(ctx).Debug().Msg("no device properties found in cache")
invalidCache = true
} else {
logger := log.Ctx(ctx).With().Str("device_class", deviceProperties.Class).Logger()
ctx := logger.WithContext(ctx)

log.Ctx(ctx).Debug().Msg("found device properties in cache, starting to validate")
res, err := create.MatchDeviceClass(ctx, deviceProperties.Class)
if err != nil {
Expand Down