Skip to content

Commit

Permalink
Change vocab from instances to indices / index
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien Coavoux <sebastien.coavoux@azoplee.com>
  • Loading branch information
sebastien-coavoux committed Jun 2, 2022
1 parent 390502b commit 1ee3577
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
26 changes: 13 additions & 13 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
continue
}

allowedList = filterAllowedInstances(logger, filter, pdus, allowedList)
allowedList = filterAllowedIndices(logger, filter, pdus, allowedList)

// Update config to get only instance and not walk them
// Update config to get only index and not walk them
newWalk = updateWalkConfig(newWalk, filter, logger)

// Only Keep instance not involved in filters
// Only Keep indices not involved in filters
newCfg := updateGetConfig(newGet, filter, logger)

// We now add each instance from filter to the get list
newCfg = addAllowedInstances(filter, allowedList, logger, newCfg)
// We now add each index from filter to the get list
newCfg = addAllowedIndices(filter, allowedList, logger, newCfg)

newGet = newCfg
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
return results, nil
}

func filterAllowedInstances(logger log.Logger, filter config.DynamicFilter, pdus []gosnmp.SnmpPDU, allowedList []string) []string {
func filterAllowedIndices(logger log.Logger, filter config.DynamicFilter, pdus []gosnmp.SnmpPDU, allowedList []string) []string {
level.Debug(logger).Log("msg", "Evaluating rule for oid", "oid", filter.Oid)
for _, pdu := range pdus {
found := false
Expand All @@ -276,9 +276,9 @@ func filterAllowedInstances(logger log.Logger, filter config.DynamicFilter, pdus
}
if found {
pduArray := strings.Split(pdu.Name, ".")
instance := pduArray[len(pduArray)-1]
level.Debug(logger).Log("msg", "Caching instance", "instance", instance)
allowedList = append(allowedList, instance)
index := pduArray[len(pduArray)-1]
level.Debug(logger).Log("msg", "Caching index", "index", index)
allowedList = append(allowedList, index)
}
}
return allowedList
Expand Down Expand Up @@ -324,11 +324,11 @@ func updateGetConfig(getConfig []string, filter config.DynamicFilter, logger log
return newCfg
}

func addAllowedInstances(filter config.DynamicFilter, allowedList []string, logger log.Logger, newCfg []string) []string {
func addAllowedIndices(filter config.DynamicFilter, allowedList []string, logger log.Logger, newCfg []string) []string {
for _, targetOid := range filter.Targets {
for _, instance := range allowedList {
level.Debug(logger).Log("msg", "Adding get configuration", "oid", targetOid+"."+instance)
newCfg = append(newCfg, targetOid+"."+instance)
for _, index := range allowedList {
level.Debug(logger).Log("msg", "Adding get configuration", "oid", targetOid+"."+index)
newCfg = append(newCfg, targetOid+"."+index)
}
}
return newCfg
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ type Filters struct {
}

type StaticFilter struct {
Targets []string `yaml:"targets,omitempty"`
Instances []string `yaml:"instances,omitempty"`
Targets []string `yaml:"targets,omitempty"`
Indices []string `yaml:"indices,omitempty"`
}
type DynamicFilter struct {
Oid string `yaml:"oid"`
Expand Down
12 changes: 6 additions & 6 deletions generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,23 @@ modules:
# EnumAsStateSet: An enum with a time series per state. Good for variable low-cardinality enums.
# Bits: An RFC 2578 BITS construct, which produces a StateSet with a time series per bit.

filters: # Define filters to collect only a subset of OID table instances
static: # static filters are handled in the generator. They will convert walks to multiple gets with the specified instances
filters: # Define filters to collect only a subset of OID table indices
static: # static filters are handled in the generator. They will convert walks to multiple gets with the specified indices
# in the resulting snmp.yml output.
# the instance filter will reduce a walk of a table to only the defined instances to get
# the index filter will reduce a walk of a table to only the defined indices to get
# If one of the target OIDs is used in a lookup, the filter will apply ALL tables using this lookup
# For a network switch, this could be used to collect a subset of interfaces such as uplinks
# For a router, this could be used to collect all real ports but not vlans and other virtual interfaces
# Specifying ifAlias or ifName if they are used in lookups with ifIndex will apply to the filter to
# all the OIDs that depend on the lookup, such as ifSpeed, ifInHcOctets, etc.
# This feature applies to any table(s) OIDs using a common instance
# This feature applies to any table(s) OIDs using a common index
- targets:
- bsnDot11EssSsid
instances: ["2","3","4"] # List of interface instances to get
indices: ["2","3","4"] # List of interface indices to get

dynamic: # dynamic filters are handed by the snmp exporter. The generator will simply pass on the configuration in the snmp.yml.
# The exporter will do a snmp walk of the oid and will restrict snmp walk made on the targets
# to the instance matching the value in the values list.
# to the index matching the value in the values list.
# This would be typically used to specify a filter for interfaces with a certain name in ifAlias, ifSpeed or admin status.
# For example, only get interfaces that a gig and faster, or get interfaces that are named Up or interfaces that are admin Up
- oid: 1.3.6.1.2.1.2.2.1.7
Expand Down
12 changes: 6 additions & 6 deletions generator/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
if ok {
oid = n.Oid
}
filterMap[oid] = filter.Instances
filterMap[oid] = filter.Indices
}
}

Expand Down Expand Up @@ -447,11 +447,11 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
needToWalk[indexNode.Oid] = struct{}{}
}
// we apply the same filter to metric.Oid if the lookup oid is filtered
instances, found := filterMap[indexNode.Oid]
indices, found := filterMap[indexNode.Oid]
if found {
delete(needToWalk, metric.Oid)
for _, instance := range instances {
needToWalk[metric.Oid+"."+instance+"."] = struct{}{}
for _, index := range indices {
needToWalk[metric.Oid+"."+index+"."] = struct{}{}
}
}
if lookup.DropSourceIndexes {
Expand Down Expand Up @@ -516,8 +516,8 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
oid = n.Oid
}
delete(needToWalk, oid)
for _, instance := range filter.Instances {
needToWalk[oid+"."+instance+"."] = struct{}{}
for _, index := range filter.Indices {
needToWalk[oid+"."+index+"."] = struct{}{}
}
}
}
Expand Down

0 comments on commit 1ee3577

Please sign in to comment.