Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uptime to SNMP traps to prevent replay attack #219

Merged
merged 11 commits into from
Jan 26, 2025
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