Skip to content

feat(snmp_trap): metrics aggregation and flexible varbind mappings#1454

Merged
kongfei605 merged 1 commit into
flashcatcloud:mainfrom
kongfei605:trap_up
Jun 11, 2026
Merged

feat(snmp_trap): metrics aggregation and flexible varbind mappings#1454
kongfei605 merged 1 commit into
flashcatcloud:mainfrom
kongfei605:trap_up

Conversation

@kongfei605

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings June 11, 2026 02:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and trap_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 community from 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",
},
},
}
@kongfei605 kongfei605 merged commit 8c471fd into flashcatcloud:main Jun 11, 2026
2 of 3 checks passed
@kongfei605 kongfei605 deleted the trap_up branch June 11, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants