On a Windows machine, I'm currently trying to create a custom field named client_ip and grab the IP address of the sending client. This works, but when I switch IPs, nxlog keeps sending the old stale IP, not the new IP.

Exec $client_ip = string(host_ip());

But, if I restart the nxlog service on the Windows machine, it starts returning the new correct IP. I don't want to have to restart the service.

How can I make nxlog always resolve and return the current ip?

Or is there another way to grab the IP address and assign that to a custom field?

AskedJune 24, 2019 - 6:34pm

Answer (1)

You could use xm_resolver and the name_to_ipaddr() function for this task as host_ip() uses some cached information pulled on startup to help with performance. https://nxlog.co/documentation/nxlog-user-guide/xm_resolver.html#xm_resolver_func_name_to_ipaddr

CacheExpiry defaults to a one hour cache (3600 seconds), ensure that this is appropriate for your environment.