the following context is my Input configuration and i get a functong from the manual doc,  but the return value of hos_ip() is ip4addr, and I want to convert the return value to string, I have try the string() function, but it does not work at all. Is there any way to convert the return value to string so i can and a new filed of the Input configuration.

ip4addr host_ip();
description Return the first non-loopback IP address the hostname resolves to.
return type ip4addr


<Input 59dcb7a6dd48cb088969e300>
        Module im_file
        File '/usr/local/nginx_raw/logs/access.log'
        PollInterval 1
        SavePos True
        ReadFromLast True
        Recursive True
        RenameCheck False
        Exec $FileName = file_name(); # Send file name with each message
        Exec $HOSTIP = host_ip();


AskedOctober 12, 2017 - 1:10pm

Answer (1)

> I have try the string() function, but it does not work at all.

The term "does not work" should be banned. If you expect others to help you, at least try to provide details.

BTW, I tried it and it does work.

Comments (2)

  • Little_Rock's picture

    sorry, i have not described it clearly. I am newer user to the nxlog. I try to add a additional Filed (ip address)to the Input, and I have try the following configuration and generate a now log in nginx.

     Exec $HOSTIP = host_ip();
     Exec $HOSTIPAddress = string($HOSTIP);
     Exec file_write("/tmp/debug.txt", "host ip:" + $HOSTIPaddress); 

    but  i get the null string in debug.txt, is the useage(eg: string($HOSTIP)) correct? thanks

  • Little_Rock's picture

    Thanks, I have changed the testing from Ubuntu 16.04.3 LTS  to Ubuntu 14.04.5 LTS,. now I can convert ip4addr to string by sring(host_ip()). I doubt there my be some special factor of my server caused this problem. I will check it.