Skip to content

Commit 1b3fe9f

Browse files
committed
When syslog sends a hostname as ip, try looking up
1 parent 905ea6f commit 1b3fe9f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/inputs/syslog/syslog.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,21 @@ func (ks *KentikSyslog) formatMessage(ctx context.Context, msg sfmt.LogParts) ([
225225
if hostname, ok := msg["hostname"]; ok {
226226
if hs, ok := hostname.(string); ok {
227227
if ipr := net.ParseIP(hs); ipr != nil {
228-
if ks.resolver != nil {
229-
resolved_name := ks.resolver.Resolve(ctx, hs, true)
230-
if resolved_name != "" {
231-
msg["device_name"] = resolved_name
228+
// First check if this ip is in our devices list.
229+
if dev, ok := ks.devices[hs]; ok {
230+
msg["device_name"] = dev.Name // Copy in any of these info we get
231+
dev.SetMsgUserTags(msg)
232+
} else { // If not, try to resolve via dns.
233+
if ks.resolver != nil {
234+
resolved_name := ks.resolver.Resolve(ctx, hs, true)
235+
if resolved_name != "" {
236+
msg["device_name"] = resolved_name
237+
} else {
238+
msg["device_name"] = hs
239+
}
232240
} else {
233241
msg["device_name"] = hs
234242
}
235-
} else {
236-
msg["device_name"] = hs
237243
}
238244
} else {
239245
msg["device_name"] = hs

0 commit comments

Comments
 (0)