Skip to content

Commit

Permalink
Recover from a panic in disco if things do not boogie right (#770)
Browse files Browse the repository at this point in the history
* Recover from a panic in disco if things do not boogie right

* also update otel example to show how to send logs and metrics in
  • Loading branch information
i3149 authored Oct 28, 2024
1 parent 187470e commit 7904187
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions hack/grafana-cloud/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ services:
- alloy
command:
- --format=otel
- --sinks=otel
- --metrics=jchf
- --tee_logs=true
- --otel.protocol=grpc
- --otel.endpoint=http://alloy:4317/
- --snmp=/snmp.yml
Expand Down
3 changes: 3 additions & 0 deletions pkg/inputs/snmp/disco.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func doubleCheckHost(result scan.Result, timeout time.Duration, ctl chan bool, m
// Get the token to allow us to run.
_ = <-ctl
defer func() {
if r := recover(); r != nil {
log.Errorf("Recovered from panic, skipping device: %v", r)
}
wg.Done()
ctl <- true
}()
Expand Down
12 changes: 10 additions & 2 deletions pkg/inputs/snmp/metadata/device_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func (dm *DeviceMetadata) poll(ctx context.Context, server *gosnmp.GoSNMP) (*kt.
case SNMP_sysDescr:
md.SysDescr = string(value.([]byte))
case SNMP_sysObjectID:
md.SysObjectID = value.(string)
if s, ok := value.(string); ok {
md.SysObjectID = s
} else if s, ok := value.([]byte); ok {
md.SysObjectID = string(s)
}
case SNMP_sysContact:
md.SysContact = string(value.([]byte))
case SNMP_sysName:
Expand Down Expand Up @@ -315,7 +319,11 @@ func GetBasicDeviceMetadata(log logger.ContextL, server *gosnmp.GoSNMP) (*kt.Dev
case SNMP_sysDescr:
md.SysDescr = string(value.([]byte))
case SNMP_sysObjectID:
md.SysObjectID = value.(string)
if s, ok := value.(string); ok {
md.SysObjectID = s
} else if s, ok := value.([]byte); ok {
md.SysObjectID = string(s)
}
case SNMP_sysContact:
md.SysContact = string(value.([]byte))
case SNMP_sysName:
Expand Down

0 comments on commit 7904187

Please sign in to comment.