Let an agent report a chosen hostname
CI / tests (Python 3.10) (pull_request) Successful in 22s
CI / tests (Python 3.11) (pull_request) Successful in 22s
CI / tests (Python 3.12) (pull_request) Successful in 22s
CI / tests (Python 3.13) (pull_request) Successful in 21s
CI / lint (pull_request) Successful in 3s

REPORT_HOSTNAME in agent.conf replaces hostname -f in the report, for hosts
registered under a label that differs from their real hostname (otherwise the
dashboard notes a mismatch forever). install.sh --report-hostname NAME sets it,
--default-report-hostname clears it, and re-running with --server (register,
rotate) keeps it. Agent 0.4.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Sonnet 5.5 committed 2026-10-29 22:14:41 -04:00
1 parent 3e62d086d1
commit 10b1d6abb8
6 files changed
+57 -6

No files matched your search

+24 -1
View File
@@ -3,6 +3,7 @@
#
# sudo ./install.sh --server https://kernelwatch.example.internal [--ca ca.pem]
# [--with-needrestart] [--with-apt-update | --without-apt-update]
# [--report-hostname NAME | --default-report-hostname]
#
# --with-needrestart installs needrestart (Ubuntu has it already) so the
# dashboard can show services needing a restart, and sets it to only list
@@ -12,6 +13,11 @@
# hourly report, so new kernel and security updates show up within the hour.
# --without-apt-update turns that off again. Without either, it stays as it was.
#
# --report-hostname makes the agent report NAME as its hostname instead of its
# own, for a host registered under a different name (the dashboard notes a
# mismatch). --default-report-hostname goes back to the machine's own. Without
# either, it stays as it was.
#
# The host token (from `kernelwatch add-host <name>` on the server) is read
# from --token-file, the KERNELWATCH_TOKEN environment variable, or a prompt,
# so it never lands in shell history. Re-running without --server or a token
@@ -24,6 +30,7 @@ ca=
token_file=
with_needrestart=0
apt_update=
report_hostname=keep
while (($#)); do
case $1 in
@@ -33,7 +40,12 @@ while (($#)); do
--with-needrestart) with_needrestart=1; shift ;;
--with-apt-update) apt_update=on; shift ;;
--without-apt-update) apt_update=off; shift ;;
-h | --help) sed -n '2,19s/^# \{0,1\}//p' "$0"; exit 0 ;;
--report-hostname)
report_hostname=${2:?--report-hostname needs a name}; shift 2
[[ $report_hostname =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$ ]] ||
{ echo "invalid --report-hostname '$report_hostname'" >&2; exit 2; } ;;
--default-report-hostname) report_hostname=off; shift ;;
-h | --help) sed -n '2,25s/^# \{0,1\}//p' "$0"; exit 0 ;;
*) echo "unknown argument: $1" >&2; exit 2 ;;
esac
done
@@ -78,6 +90,9 @@ if [[ -n $ca ]]; then
install -m 0644 "$ca" /etc/kernelwatch/ca.pem
fi
# Writing the config below replaces it, so remember a REPORT_HOSTNAME to keep.
prev_report_hostname=$(sed -n 's/^REPORT_HOSTNAME=//p' /etc/kernelwatch/agent.conf 2>/dev/null | tail -n1 || true)
if [[ -n $server ]]; then
{
echo "SERVER_URL=$server"
@@ -90,6 +105,14 @@ elif [[ ! -e /etc/kernelwatch/agent.conf ]]; then
exit 1
fi
case $report_hostname in
keep) report_hostname=$prev_report_hostname ;;
off) report_hostname= ;;
esac
sed -i '/^REPORT_HOSTNAME=/d' /etc/kernelwatch/agent.conf
[[ -z $report_hostname ]] || echo "REPORT_HOSTNAME=$report_hostname" >>/etc/kernelwatch/agent.conf
chmod 0644 /etc/kernelwatch/agent.conf
token=
if [[ -n $token_file ]]; then
token=$(tr -d '[:space:]' <"$token_file")