Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1ee3577

Browse files
committedJun 2, 2022
Change vocab from instances to indices / index
Signed-off-by: Sébastien Coavoux <sebastien.coavoux@azoplee.com>
1 parent 390502b commit 1ee3577

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed
 

‎collector/collector.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
181181
continue
182182
}
183183

184-
allowedList = filterAllowedInstances(logger, filter, pdus, allowedList)
184+
allowedList = filterAllowedIndices(logger, filter, pdus, allowedList)
185185

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

189-
// Only Keep instance not involved in filters
189+
// Only Keep indices not involved in filters
190190
newCfg := updateGetConfig(newGet, filter, logger)
191191

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

195195
newGet = newCfg
196196
}
@@ -261,7 +261,7 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log
261261
return results, nil
262262
}
263263

264-
func filterAllowedInstances(logger log.Logger, filter config.DynamicFilter, pdus []gosnmp.SnmpPDU, allowedList []string) []string {
264+
func filterAllowedIndices(logger log.Logger, filter config.DynamicFilter, pdus []gosnmp.SnmpPDU, allowedList []string) []string {
265265
level.Debug(logger).Log("msg", "Evaluating rule for oid", "oid", filter.Oid)
266266
for _, pdu := range pdus {
267267
found := false
@@ -276,9 +276,9 @@ func filterAllowedInstances(logger log.Logger, filter config.DynamicFilter, pdus
276276
}
277277
if found {
278278
pduArray := strings.Split(pdu.Name, ".")
279-
instance := pduArray[len(pduArray)-1]
280-
level.Debug(logger).Log("msg", "Caching instance", "instance", instance)
281-
allowedList = append(allowedList, instance)
279+
index := pduArray[len(pduArray)-1]
280+
level.Debug(logger).Log("msg", "Caching index", "index", index)
281+
allowedList = append(allowedList, index)
282282
}
283283
}
284284
return allowedList
@@ -324,11 +324,11 @@ func updateGetConfig(getConfig []string, filter config.DynamicFilter, logger log
324324
return newCfg
325325
}
326326

327-
func addAllowedInstances(filter config.DynamicFilter, allowedList []string, logger log.Logger, newCfg []string) []string {
327+
func addAllowedIndices(filter config.DynamicFilter, allowedList []string, logger log.Logger, newCfg []string) []string {
328328
for _, targetOid := range filter.Targets {
329-
for _, instance := range allowedList {
330-
level.Debug(logger).Log("msg", "Adding get configuration", "oid", targetOid+"."+instance)
331-
newCfg = append(newCfg, targetOid+"."+instance)
329+
for _, index := range allowedList {
330+
level.Debug(logger).Log("msg", "Adding get configuration", "oid", targetOid+"."+index)
331+
newCfg = append(newCfg, targetOid+"."+index)
332332
}
333333
}
334334
return newCfg

‎config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ type Filters struct {
194194
}
195195

196196
type StaticFilter struct {
197-
Targets []string `yaml:"targets,omitempty"`
198-
Instances []string `yaml:"instances,omitempty"`
197+
Targets []string `yaml:"targets,omitempty"`
198+
Indices []string `yaml:"indices,omitempty"`
199199
}
200200
type DynamicFilter struct {
201201
Oid string `yaml:"oid"`

‎generator/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,23 @@ modules:
147147
# EnumAsStateSet: An enum with a time series per state. Good for variable low-cardinality enums.
148148
# Bits: An RFC 2578 BITS construct, which produces a StateSet with a time series per bit.
149149

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

164164
dynamic: # dynamic filters are handed by the snmp exporter. The generator will simply pass on the configuration in the snmp.yml.
165165
# The exporter will do a snmp walk of the oid and will restrict snmp walk made on the targets
166-
# to the instance matching the value in the values list.
166+
# to the index matching the value in the values list.
167167
# This would be typically used to specify a filter for interfaces with a certain name in ifAlias, ifSpeed or admin status.
168168
# For example, only get interfaces that a gig and faster, or get interfaces that are named Up or interfaces that are admin Up
169169
- oid: 1.3.6.1.2.1.2.2.1.7

‎generator/tree.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
385385
if ok {
386386
oid = n.Oid
387387
}
388-
filterMap[oid] = filter.Instances
388+
filterMap[oid] = filter.Indices
389389
}
390390
}
391391

@@ -447,11 +447,11 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
447447
needToWalk[indexNode.Oid] = struct{}{}
448448
}
449449
// we apply the same filter to metric.Oid if the lookup oid is filtered
450-
instances, found := filterMap[indexNode.Oid]
450+
indices, found := filterMap[indexNode.Oid]
451451
if found {
452452
delete(needToWalk, metric.Oid)
453-
for _, instance := range instances {
454-
needToWalk[metric.Oid+"."+instance+"."] = struct{}{}
453+
for _, index := range indices {
454+
needToWalk[metric.Oid+"."+index+"."] = struct{}{}
455455
}
456456
}
457457
if lookup.DropSourceIndexes {
@@ -516,8 +516,8 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
516516
oid = n.Oid
517517
}
518518
delete(needToWalk, oid)
519-
for _, instance := range filter.Instances {
520-
needToWalk[oid+"."+instance+"."] = struct{}{}
519+
for _, index := range filter.Indices {
520+
needToWalk[oid+"."+index+"."] = struct{}{}
521521
}
522522
}
523523
}

0 commit comments

Comments
 (0)
Please sign in to comment.