feat(snmp_trap): metrics aggregation and flexible varbind mappings#1454
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the snmp_trap input to support aggregating trap varbinds into a single “core” event metric (with optional label promotion) and adds configurable, prefix-based varbind/trap mappings to better control metric/label naming.
Changes:
- Add per-instance aggregation controls:
fields_to_labels,varbind_mapping, andtrap_mapping(including trap-specific label/value selection). - Update trap handler logic to (a) extract trap OID/name robustly, (b) optionally emit an aggregated core metric, and (c) keep dispersed metrics with consistent timestamps.
- Add unit tests covering aggregation and dispersed fallback behavior; update README with new configuration and a migration note removing
communityfrom labels.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
inputs/snmp_trap/snmp_trap.go |
Implements OID-prefix matching, trap/varbind mapping, label promotion, and core/dispersed metric generation. |
inputs/snmp_trap/snmp_trap_test.go |
Adds tests for aggregated core metric behavior and dispersed fallback with label inheritance. |
inputs/snmp_trap/README.md |
Documents new mapping/aggregation config and removes community label from examples with a migration note. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+398
to
+403
| varbindName := v.Name | ||
| e, err := s.transl.lookup(v.Name) | ||
| if nil != err { | ||
| log.Printf("Error resolving OID oid=%s, source=%s: %v", v.Name, tags["source"], err) | ||
| return | ||
| if err == nil { | ||
| varbindName = e.OidText | ||
| } | ||
|
|
Comment on lines
150
to
152
| - version (string, "1" or "2c" or "3") | ||
| - context_name (string, value from v3 trap) | ||
| - engine_id (string, value from v3 trap) |
Comment on lines
+85
to
+97
| func TestTrapDispersedFallback(t *testing.T) { | ||
| slist := types.NewSampleList() | ||
| instance := &Instance{ | ||
| Translator: "mock", | ||
| FieldsToLabels: []string{"ifIndex"}, // only ifIndex | ||
| transl: &mockTranslator{ | ||
| dict: map[string]string{ | ||
| ".1.3.6.1.6.3.1.1.5.3": "linkDown", | ||
| ".1.3.6.1.2.1.2.2.1.1.835": "ifIndex.835", | ||
| ".1.3.6.1.2.1.1.3.0": "sysUpTimeInstance", | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.