Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_mk_agent: Do not rely on "hostname" cmd on OpenWRT #721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stklcode
Copy link

Issue:

Built-in BusyBox shell in OpenWRT has no hostname command available by default. While it can be added with additional packages in custom images there are alternative ways to determine the machine's hostname without introducing an additional dependency.

On some default OpenWRT image the "Hostname" attribute is empty:

root@my-openwrt-box:~# hostname
-ash: hostname: not found

root@my-openwrt-box:~# cat /proc/sys/kernel/hostname
my-openwrt-box

root@my-openwrt-box:~# check_mk_agent dump
<<<check_mk>>>
Version: 2.2.0p26
AgentOS: openwrt
Hostname: 
AgentDirectory: /etc/check_mk
...

Well, it doesn't really hurt much, but it's not desired behavior either.

Proposed changes:

Read the hostname from the sysctl parameter kernel.hostname (i.e. read /proc/sys/kernel/hostname) instead which is likely available on every image.

root@my-openwrt-box:~# check_mk_agent dump

<<<check_mk>>>
Version: 2.2.0p26
AgentOS: openwrt
Hostname: my-openwrt-box
AgentDirectory: /etc/check_mk
...

Built-in BusyBox shell in OpenWRT has no hostname command available by
default. While it can be added with additional packages in custom images
there are alternative ways to determine the machine's hostname without
introducing an additional dependency.

Read the hostname from the sysctl parameter kernel.hostname (i.e. read
/proc/sys/kernel/hostname) instead which is likely available on every
image.
Copy link

github-actions bot commented Jun 21, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@stklcode
Copy link
Author

I have read the CLA Document and I hereby sign the CLA or my organization already has a signed CLA.

@stklcode
Copy link
Author

My first attempt had a conditional function in the preamble

if ! inpath hostname; then
  hostname() {
    cat /proc/sys/kernel/hostname
  }
fi

but I couldn't find any real reasons why a system's hostname command should be preferable in this context.
If desired though, I can update my PR accordingly.

@martinhv
Copy link
Member

Thanks for highlighting this.
In OpenWRT hostname isn't there and won't come anytime soon (openwrt/openwrt#11765)

So, your PR is approved from my perspective (product, not dev).
We are pondering as well, if we should not just use /proc/sys/kernel/hostname in all UNIX agents though.
Will forward to a dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants