Skip to content

Commit

Permalink
When syslog sends a hostname as ip, try looking up
Browse files Browse the repository at this point in the history
  • Loading branch information
i3149 committed Jan 17, 2025
1 parent 905ea6f commit 1b3fe9f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/inputs/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,21 @@ func (ks *KentikSyslog) formatMessage(ctx context.Context, msg sfmt.LogParts) ([
if hostname, ok := msg["hostname"]; ok {
if hs, ok := hostname.(string); ok {
if ipr := net.ParseIP(hs); ipr != nil {
if ks.resolver != nil {
resolved_name := ks.resolver.Resolve(ctx, hs, true)
if resolved_name != "" {
msg["device_name"] = resolved_name
// First check if this ip is in our devices list.
if dev, ok := ks.devices[hs]; ok {
msg["device_name"] = dev.Name // Copy in any of these info we get
dev.SetMsgUserTags(msg)
} else { // If not, try to resolve via dns.
if ks.resolver != nil {
resolved_name := ks.resolver.Resolve(ctx, hs, true)
if resolved_name != "" {
msg["device_name"] = resolved_name
} else {
msg["device_name"] = hs
}
} else {
msg["device_name"] = hs
}
} else {
msg["device_name"] = hs
}
} else {
msg["device_name"] = hs
Expand Down

0 comments on commit 1b3fe9f

Please sign in to comment.