Skip to content

Commit 961991f

Browse files
authored
Merge pull request #61 from inexio/pre-release
Pre release
2 parents dd6573e + c95a447 commit 961991f

File tree

11 files changed

+48
-13
lines changed

11 files changed

+48
-13
lines changed

cmd/check_interface_metrics.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func init() {
1313
checkInterfaceMetricsCMD.Flags().Bool("print-interfaces", false, "Print interfaces to plugin output")
1414
checkInterfaceMetricsCMD.Flags().StringSlice("ifType-filter", []string{}, "Filter out interfaces which ifType equals the given types")
1515
checkInterfaceMetricsCMD.Flags().StringSlice("ifName-filter", []string{}, "Filter out interfaces which ifName matches the given regex")
16+
checkInterfaceMetricsCMD.Flags().StringSlice("ifDescr-filter", []string{}, "Filter out interfaces which ifDescription matches the given regex")
1617
}
1718

1819
var checkInterfaceMetricsCMD = &cobra.Command{
@@ -32,11 +33,16 @@ var checkInterfaceMetricsCMD = &cobra.Command{
3233
if err != nil {
3334
log.Fatal().Err(err).Msg("ifName-filter needs to be a string")
3435
}
36+
ifDescrFilter, err := cmd.Flags().GetStringSlice("ifDescr-filter")
37+
if err != nil {
38+
log.Fatal().Err(err).Msg("ifDescr-filter needs to be a string")
39+
}
3540
r := request.CheckInterfaceMetricsRequest{
3641
CheckDeviceRequest: getCheckDeviceRequest(args[0]),
3742
PrintInterfaces: printInterfaces,
3843
IfTypeFilter: ifTypeFilter,
3944
IfNameFilter: ifNameFilter,
45+
IfDescrFilter: ifDescrFilter,
4046
}
4147
handleRequest(&r)
4248
},

config/device-classes/generic/routeros.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ match:
66
- type: SysObjectID
77
match_mode: startsWith
88
values:
9-
- .1.3.6.1.4.1.14988.1
9+
- .1.3.6.1.4.1.14988.
1010
- type: HttpGetBody
1111
uri: "/"
1212
match_mode: contains

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.3"
31+
const Version = "v0.3.4"

internal/communicator/communicator/communicator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type Communicator interface {
2121
// Match checks if the device matches the device class
2222
Match(ctx context.Context) (bool, error)
2323

24+
// UpdateConnection updates the device connection with class specific values
25+
UpdateConnection(ctx context.Context) error
26+
2427
// GetIdentifyProperties returns the identify properties of a device like vendor, model...
2528
GetIdentifyProperties(ctx context.Context) (device.Properties, error)
2629

internal/communicator/communicator/network_device_communicator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func (c *networkDeviceCommunicator) Match(ctx context.Context) (bool, error) {
3939
return c.deviceClassCommunicator.Match(ctx)
4040
}
4141

42+
func (c *networkDeviceCommunicator) UpdateConnection(ctx context.Context) error {
43+
return c.deviceClassCommunicator.UpdateConnection(ctx)
44+
}
45+
4246
func (c *networkDeviceCommunicator) GetIdentifyProperties(ctx context.Context) (device.Properties, error) {
4347
dev := device.Device{
4448
Class: c.GetIdentifier(),

internal/communicator/deviceclass/device_class.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,6 @@ func (d *deviceClass) matchDevice(ctx context.Context) (bool, error) {
382382
return d.match.check(ctx)
383383
}
384384

385-
// getSNMPMaxRepetitions returns the maximum snmp repetitions.
386-
func (d *deviceClass) getSNMPMaxRepetitions() (uint32, error) {
387-
if d.config.snmp.MaxRepetitions != 0 {
388-
return d.config.snmp.MaxRepetitions, nil
389-
}
390-
return 0, tholaerr.NewNotFoundError("max_repetitions not found")
391-
}
392-
393385
// getAvailableComponents returns the available components.
394386
func (d *deviceClass) getAvailableComponents() map[component.Component]bool {
395387
return d.config.components

internal/communicator/deviceclass/device_class_communicator.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ func (o *deviceClassCommunicator) Match(ctx context.Context) (bool, error) {
4949
return o.matchDevice(ctx)
5050
}
5151

52+
func (o *deviceClassCommunicator) UpdateConnection(ctx context.Context) error {
53+
if conn, ok := network.DeviceConnectionFromContext(ctx); ok {
54+
if conn.SNMP != nil && conn.SNMP.SnmpClient != nil {
55+
conn.SNMP.SnmpClient.SetMaxRepetitions(o.deviceClass.config.snmp.MaxRepetitions)
56+
}
57+
}
58+
return nil
59+
}
60+
5261
func (o *deviceClassCommunicator) GetIdentifyProperties(ctx context.Context) (device.Properties, error) {
5362
dev := device.Device{
5463
Class: o.GetIdentifier(),

internal/network/snmp_client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"github.com/gosnmp/gosnmp"
99
"github.com/inexio/thola/internal/tholaerr"
10-
"github.com/inexio/thola/internal/utility"
1110
"github.com/pkg/errors"
1211
"github.com/rs/zerolog/log"
1312
"golang.org/x/text/encoding/charmap"
@@ -527,8 +526,11 @@ func (s *SNMPClient) GetVersion() string {
527526
}
528527

529528
// GetMaxRepetitions returns the max repetitions.
530-
func (s *SNMPClient) GetMaxRepetitions() uint8 {
531-
return utility.IfThenElse(s.client.MaxRepetitions == 0, gosnmp.Default.MaxRepetitions, s.client.MaxRepetitions).(uint8)
529+
func (s *SNMPClient) GetMaxRepetitions() uint32 {
530+
if s.client.MaxRepetitions == 0 {
531+
return gosnmp.Default.MaxRepetitions
532+
}
533+
return s.client.MaxRepetitions
532534
}
533535

534536
// SetMaxRepetitions sets the maximum repetitions.

internal/request/check_interface_metrics_request.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ type CheckInterfaceMetricsRequest struct {
99
PrintInterfaces bool `yaml:"print_interfaces" json:"print_interfaces" xml:"print_interfaces"`
1010
IfTypeFilter []string `yaml:"ifType_filter" json:"ifType_filter" xml:"ifType_filter"`
1111
IfNameFilter []string `yaml:"ifName_filter" json:"ifName_filter" xml:"ifName_filter"`
12+
IfDescrFilter []string `yaml:"ifDescr_filter" json:"ifDescr_filter" xml:"ifDescr_filter"`
1213
CheckDeviceRequest
1314
}

internal/request/check_interface_metrics_request_process.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ out:
103103
}
104104
}
105105
}
106+
for _, filter := range r.IfDescrFilter {
107+
if interf.IfDescr != nil {
108+
matched, err := regexp.MatchString(filter, *interf.IfDescr)
109+
if err != nil {
110+
return nil, errors.Wrap(err, "ifDescr filter regex match failed")
111+
}
112+
if matched {
113+
filterIndices = append(filterIndices, i)
114+
continue out
115+
}
116+
}
117+
}
106118
}
107119

108120
readInterfacesResponse.Interfaces = filterInterfaces(readInterfacesResponse.Interfaces, filterIndices, 0)

0 commit comments

Comments
 (0)