Skip to content

Commit 862dd7d

Browse files
authored
Merge pull request #66 from inexio/pre-release
Pre release
2 parents 73d05e6 + 53a383a commit 862dd7d

File tree

5 files changed

+139
-23
lines changed

5 files changed

+139
-23
lines changed

config/codecommunicator/junos.go

Lines changed: 134 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,131 @@ func (c *junosCommunicator) GetInterfaces(ctx context.Context) ([]device.Interfa
2020
return nil, err
2121
}
2222

23+
interfacesWithVLANs, err := juniperAddVLANsNonELS(ctx, interfaces)
24+
if err != nil {
25+
log.Ctx(ctx).Debug().Err(err).Msg("getting juniper VLANs for non ELS devices failed, trying for ELS devices")
26+
interfacesWithVLANs, err = juniperAddVLANsELS(ctx, interfaces)
27+
if err != nil {
28+
log.Ctx(ctx).Debug().Err(err).Msg("getting juniper VLANs for ELS devices failed, skipping VLANs")
29+
interfacesWithVLANs = interfaces
30+
}
31+
}
32+
33+
return interfacesWithVLANs, nil
34+
}
35+
36+
func juniperAddVLANsELS(ctx context.Context, interfaces []device.Interface) ([]device.Interface, error) {
2337
con, ok := network.DeviceConnectionFromContext(ctx)
2438
if !ok || con.SNMP == nil {
2539
return nil, errors.New("snmp client is empty")
2640
}
2741

28-
// dot1dBasePortIfIndex
29-
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.2.1.17.1.4.1.2")
42+
// jnxL2aldVlanFdbId
43+
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.48.1.3.1.1.5")
3044
if err != nil {
31-
log.Ctx(ctx).Debug().Err(err).Msg("failed to get dot1dBasePortIfIndex, skipping VLANs")
32-
return interfaces, nil
45+
return nil, errors.Wrap(err, "failed to get jnxL2aldVlanFdbId")
3346
}
3447

35-
portIfIndex := make(map[string]string)
48+
vlanIndexFilterID := make(map[string]string)
3649
for _, response := range res {
37-
ifIndex, err := response.GetValueString()
50+
filterID, err := response.GetValueString()
3851
if err != nil {
3952
return nil, err
4053
}
4154

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

45-
portIfIndex[oidSplit[len(oidSplit)-1]] = ifIndex
58+
vlanIndexFilterID[oidSplit[len(oidSplit)-1]] = filterID
59+
}
60+
61+
// jnxL2aldVlanName
62+
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.48.1.3.1.1.2")
63+
if err != nil {
64+
return nil, errors.Wrap(err, "failed to get jnxL2aldVlanName")
65+
}
66+
67+
filterIDVLAN := make(map[string]device.VLAN)
68+
for _, response := range res {
69+
name, err := response.GetValueString()
70+
if err != nil {
71+
return nil, err
72+
}
73+
74+
oid := response.GetOID()
75+
oidSplit := strings.Split(oid, ".")
76+
filterID := vlanIndexFilterID[oidSplit[len(oidSplit)-1]]
77+
78+
filterIDVLAN[filterID] = device.VLAN{
79+
Name: name,
80+
}
81+
}
82+
83+
portIfIndex, err := juniperGetPortIfIndexMapping(ctx)
84+
if err != nil {
85+
return nil, err
86+
}
87+
88+
// dot1qTpFdbPort
89+
dot1qTpFdbPort := "1.3.6.1.2.1.17.7.1.2.2.1.2"
90+
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, dot1qTpFdbPort)
91+
if err != nil {
92+
return nil, errors.Wrap(err, "failed to get dot1qTpFdbPort")
93+
}
94+
95+
ifIndexFilterIDs := make(map[string][]string)
96+
out:
97+
for _, response := range res {
98+
port, err := response.GetValueString()
99+
if err != nil {
100+
return nil, err
101+
}
102+
103+
oid := strings.TrimPrefix(response.GetOID(), ".")
104+
oidSplit := strings.Split(strings.TrimPrefix(strings.TrimPrefix(oid, dot1qTpFdbPort), "."), ".")
105+
ifIndex := portIfIndex[port]
106+
107+
for _, filterID := range ifIndexFilterIDs[ifIndex] {
108+
if filterID == oidSplit[0] {
109+
continue out
110+
}
111+
}
112+
ifIndexFilterIDs[ifIndex] = append(ifIndexFilterIDs[ifIndex], oidSplit[0])
113+
}
114+
115+
for i, interf := range interfaces {
116+
if interf.IfIndex != nil {
117+
if filterIDs, ok := ifIndexFilterIDs[fmt.Sprint(*interf.IfIndex)]; ok {
118+
for _, filterID := range filterIDs {
119+
if vlan, ok := filterIDVLAN[filterID]; ok {
120+
if interfaces[i].VLAN == nil {
121+
interfaces[i].VLAN = &device.VLANInformation{}
122+
}
123+
interfaces[i].VLAN.VLANs = append(interfaces[i].VLAN.VLANs, vlan)
124+
}
125+
}
126+
}
127+
}
128+
}
129+
130+
return interfaces, nil
131+
}
132+
133+
func juniperAddVLANsNonELS(ctx context.Context, interfaces []device.Interface) ([]device.Interface, error) {
134+
con, ok := network.DeviceConnectionFromContext(ctx)
135+
if !ok || con.SNMP == nil {
136+
return nil, errors.New("snmp client is empty")
46137
}
47138

48139
// jnxExVlanPortStatus
49-
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.40.1.5.1.7.1.3")
140+
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2636.3.40.1.5.1.7.1.3")
50141
if err != nil {
51-
log.Ctx(ctx).Debug().Err(err).Msg("failed to get jnxExVlanPortStatus, skipping VLANs")
52-
return interfaces, nil
142+
return nil, errors.Wrap(err, "failed to get jnxExVlanPortStatus")
143+
}
144+
145+
portIfIndex, err := juniperGetPortIfIndexMapping(ctx)
146+
if err != nil {
147+
return nil, err
53148
}
54149

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

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

110204
return interfaces, nil
111205
}
206+
207+
func juniperGetPortIfIndexMapping(ctx context.Context) (map[string]string, error) {
208+
con, ok := network.DeviceConnectionFromContext(ctx)
209+
if !ok || con.SNMP == nil {
210+
return nil, errors.New("snmp client is empty")
211+
}
212+
213+
// dot1dBasePortIfIndex
214+
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.2.1.17.1.4.1.2")
215+
if err != nil {
216+
return nil, errors.Wrap(err, "failed to get dot1dBasePortIfIndex")
217+
}
218+
219+
portIfIndex := make(map[string]string)
220+
for _, response := range res {
221+
ifIndex, err := response.GetValueString()
222+
if err != nil {
223+
return nil, err
224+
}
225+
226+
oid := response.GetOID()
227+
oidSplit := strings.Split(oid, ".")
228+
229+
portIfIndex[oidSplit[len(oidSplit)-1]] = ifIndex
230+
}
231+
232+
return portIfIndex, nil
233+
}

doc/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
package doc
2929

3030
// Version specifies the current version.
31-
const Version = "v0.3.4"
31+
const Version = "v0.3.5"

internal/communicator/deviceclass/group_properties.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (d *deviceClassOIDs) readOID(ctx context.Context) (map[int]interface{}, err
7979
res, err := reader.readOID(ctx)
8080
if err != nil {
8181
if tholaerr.IsNotFoundError(err) || tholaerr.IsComponentNotFoundError(err) {
82-
log.Ctx(ctx).Debug().Err(err).Msgf("value %s", label)
82+
log.Ctx(ctx).Debug().Err(err).Msgf("failed to get value '%s'", label)
8383
continue
8484
}
8585
return nil, errors.Wrapf(err, "failed to get value '%s'", label)
@@ -141,7 +141,6 @@ func (d *deviceClassOID) readOID(ctx context.Context) (map[int]interface{}, erro
141141
snmpResponse, err := con.SNMP.SnmpClient.SNMPWalk(ctx, string(d.OID))
142142
if err != nil {
143143
if tholaerr.IsNotFoundError(err) {
144-
log.Ctx(ctx).Debug().Err(err).Msgf("oid %s not found on device", d.OID)
145144
return nil, err
146145
}
147146
log.Ctx(ctx).Debug().Err(err).Msg("failed to get oid value of interface")

internal/request/check_interface_metrics_request_process.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,20 +556,12 @@ func addCheckInterfacePerformanceData(interfaces []device.Interface, r *monitori
556556
if err != nil {
557557
return err
558558
}
559-
err = r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("interface_maxspeed_in", *i.SAP.Inbound).SetLabel(*i.IfDescr))
560-
if err != nil {
561-
return err
562-
}
563559
}
564560
if i.SAP.Outbound != nil {
565561
err := r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("traffic_counter_out", *i.SAP.Outbound).SetUnit("c").SetLabel(*i.IfDescr))
566562
if err != nil {
567563
return err
568564
}
569-
err = r.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("interface_maxspeed_out", *i.SAP.Outbound).SetLabel(*i.IfDescr))
570-
if err != nil {
571-
return err
572-
}
573565
}
574566
}
575567
}

internal/request/get_communicator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func GetCommunicator(ctx context.Context, baseRequest BaseRequest) (communicator
2929
log.Ctx(ctx).Debug().Msg("no device properties found in cache")
3030
invalidCache = true
3131
} else {
32+
logger := log.Ctx(ctx).With().Str("device_class", deviceProperties.Class).Logger()
33+
ctx := logger.WithContext(ctx)
34+
3235
log.Ctx(ctx).Debug().Msg("found device properties in cache, starting to validate")
3336
res, err := create.MatchDeviceClass(ctx, deviceProperties.Class)
3437
if err != nil {

0 commit comments

Comments
 (0)