Skip to content

Commit

Permalink
Add uptime to SNMP traps to prevent replay attack (#219)
Browse files Browse the repository at this point in the history
* Allowing to set a custom base OID for trap sub-objects

* Removed "Enabled" parameter

* Update unit tests with new parameter

* Updated readme

* Fix the http server unit test

* Do not append .1 to the trap OID

* Rename custom-base-oid-sub-object  to sub-object-default-oid

* tes

* With boots time

---------

Co-authored-by: nalixvignola <[email protected]>
  • Loading branch information
vigno88 and vigno99 authored Jan 26, 2025
1 parent 8621de1 commit 0c29e84
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions trapsender/trap_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package trapsender

import (
"errors"
"math"
"strings"
"time"

Expand Down Expand Up @@ -114,10 +115,14 @@ func (trapSender TrapSender) sendTraps(connectionArguments snmpgo.SNMPArguments,
snmp.Close()
}()

hasError := false
uptime, _ := host.Uptime()
if uptime > math.MaxInt32 {
uptime = 0
}

hasError := false
for _, trap := range traps {
err = snmp.V2Trap(trap)
err = snmp.V2TrapWithBootsTime(trap, 0, int(uptime))
if err != nil {
telemetry.SNMPTrapTotal.WithLabelValues(distinationForMetrics, "failure").Inc()
level.Error(*trapSender.logger).Log("msg", "error while generating trap", "destination", distinationForMetrics, "err", err)
Expand Down

0 comments on commit 0c29e84

Please sign in to comment.