Skip to content

Commit

Permalink
ER 2666: Events not generated in telegraf snmp_heartbeat when ICMP fa…
Browse files Browse the repository at this point in the history
…ils (influxdata#11)
  • Loading branch information
sandeep-vunet authored Dec 17, 2021
1 parent 9cee79b commit 4cf7786
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions plugins/inputs/snmp_heartbeat/snmp_heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,27 +1145,25 @@ func (s *Snmp) nativePing(destination string) (*pingStats, error) {
}

func (s *Snmp) pingToURLNative(destination string, acc telegraf.Accumulator, period int) map[string]interface{} {
fields := map[string]interface{}{}
fields := map[string]interface{}{
"method": "snmp_and_icmp",
"period": period,
"target_state": "Down",
"average_rtt": 0,
"minimum_rtt": 0,
"maximum_rtt": 0,
"jitter": 0,
"pkt_loss_pct": float64(100),
}
stats, err := s.nativePingFunc(destination)
if err != nil {
fmt.Errorf("ping failed: %s", err.Error())
return fields
}

fields = map[string]interface{}{
"method": "snmp_and_icmp",
"period": period,
}

if stats.PacketsSent == 0 || stats.PacketsRecv == 0 {
fields["target_state"] = "Down"
fields["average_rtt"] = 0
fields["minimum_rtt"] = 0
fields["maximum_rtt"] = 0
fields["jitter"] = 0
fields["pkt_loss_pct"] = float64(100)
return fields
}

fields["method"] = "icmp"
fields["target_state"] = "Up"
fields["pkt_loss_pct"] = float64(stats.PacketLoss)
Expand Down

0 comments on commit 4cf7786

Please sign in to comment.