Add -h <hostname> to syslog logread service

Hello

does anyone know a config option to activate the -h option in the logread service to external syslog? I searched the config files and cannot find it.

At this moment, I simply added this to the /etc/init.d/log file, but if possible I rather do it properly

# MODIFICATION, added hostname
        hostname=`cat /proc/sys/kernel/hostname`
        procd_set_param command "$PROG" -f -r "$log_ip" "${log_port}" -p "$pid_file" -h "$hostname"
        case "${log_proto}" in
                "udp") procd_append_param command -u;;
                "tcp") [ "${log_trailer_null}" -eq 1 ] && procd_append_param command -0;;
        esac

The script code in /etc/init.d/log shows the available options:

validate_log_section()
{
        uci_validate_section system system "${1}" \
                'log_file:string' \
                'log_size:uinteger' \
                'log_hostname:string' \
                'log_ip:ipaddr' \
                'log_remote:bool:1' \
                'log_port:port:514' \
                'log_proto:or("tcp", "udp"):udp' \
                'log_trailer_null:bool:0' \
                'log_prefix:string'
}

So, the option is called log_hostname, and it should be added to /etc/config/system where the "system" section contains the log options.

Ps. which OpenWrt version you are using? The code supporting the hostname option parsing has been there since year 2016 and you code snippet seems to differentiate a bit from the current code.

Interesting. I was reading https://openwrt.org/docs/guide-user/base-system/system_configuration
and was thinking, there should really be one called log_hostname.... So I guess the documentation is a little behind.

Anyway, you are correct, I am using 15.05.1 (which is from 2016 also?)

I have a good 15 or so Ubiquiti AirMaxM, all with 'only' 32M memory, I have 4~6M free on 18.06.1 and 6~8M free on 15.05.1, and so far there has not been anything I thought I needed from the newer one for my current network rebuild. (rebuilding with VLAN's for better guest, private, IoT separation, I keep swapping between 18.06.1 and 15.05.1 to try the differences)

I guess this might be the thing where 18 has something I want. I did not know, because it is not showing in https://openwrt.org/docs/guide-user/base-system/system_configuration. I will reconsider my options.

Thanks

While good to know this is automatic in the later versions, I am creating a patch for myself that automatically executes once, and only once, whenever the configuration is restored on 15.05.01.
At the same time, it does nothing if ever restored to 17 or 18:

rc.local:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

# Replacing log.init with a patched one that adds the -u hostname
# In LEDE/OpenWRT>=17 this is no longer needed, so the pattern I choose is
# such that it does not match those versions, should this config ever be restored there.

file='/etc/init.d/log'

if [ ! -f ${file}.orig ]; then
  mv ${file} ${file}.orig

  old='procd_set_param command \"$PROG\" -f -r \"$log_ip\" \"${log_port}\" -p \"$pid_file\"'
  new='procd_set_param command \"$PROG\" -f -h $(cat \/proc\/sys\/kernel\/hostname) -r \"$log_ip\" \"${log_port}\" -p \"$pid_file\"'

  sed "s/${old}/${new}/g" ${file}.orig >${file}
  chmod a+x ${file}

fi

exit 0

The whole 15.05 branch is mainly May 2015 code, and has been deprecated ages ago by 17.01 and 18.06 and hopefully soon 19.0x.

The branch date tells you when the release branch has been created. You can assume that features introduced later will usually not be there, as only some stuff gets backported to stable release branches. So, feature done in 2016 is likely not in 15.05...

If you ask help for ancient stuff, please remember to state that explicitly. Otherwise the current advice can be misleading. And of course, the question itself may look strange if you ask for something that is standard feature right now...

You are correct of course. In my defence, I was swapping often between 18 and 15 to try both, and the documentation is/was missing for the 18 version. So the question is/was valid for, and meant for, the latest V18 version as well.

That you are fluent enough to read the source instead of documentation is impressive, and thanks for the help, because it did point me toward a better solution for myself (despite hanging around on an older version).

Anyway, I updated the documentation at https://openwrt.org/docs/guide-user/base-system/system_configuration#system_section
Feel free to undo or adjust if you feel I overstepped my permissions with that.

1 Like

That is great. The documentation is a community effort, just the software itself.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.