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

Closed
wants to merge 1 commit into from

Conversation

stklcode
Copy link
Contributor

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
Contributor Author

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

@stklcode
Copy link
Contributor 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.

@CheckmkCI CheckmkCI closed this in aefb22e Nov 11, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2024
CheckmkCI pushed a commit that referenced this pull request Nov 11, 2024
… unavailable

Built-in BusyBox shell in OpenWRT has no `hostname` command available per 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.
This werk uses one of those alternatives.

Closes: #721

Change-Id: Ib05f837151f02942077a5b405dab966e7f4f9318
CheckmkCI pushed a commit that referenced this pull request Nov 11, 2024
… unavailable

Built-in BusyBox shell in OpenWRT has no `hostname` command available per 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.
This werk uses one of those alternatives.

Closes: #721

Change-Id: Ib05f837151f02942077a5b405dab966e7f4f9318
@stklcode stklcode deleted the openwrt-hostname branch November 11, 2024 09:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants