reworked the checkmk module

This commit is contained in:
2025-09-22 18:34:48 +02:00
parent d292e0e486
commit dab7132d31

View File

@@ -9,43 +9,67 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Variable: # Variable:
# * MK_SERVER: Server IP address # * MK_SERVER: Server IP address
# * MK_PORT: Port check_mk agent will use to communicate with server # * MK_SITE: The check_mk site (or instance) to use
# * MK_URL: The URL to use to download the agent
# * MK_SECRET: The secret to use to register the agent
# * MK_USER: The user to use to register
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
export VER_install_mkagent="0.0.7" export VER_install_mkagent="0.1.0"
export DEP_install_mkagent="" export DEP_install_mkagent=""
install_mkagent() install_mkagent()
{ {
wget $MK_URL -O /tmp/check-mk-agent_${MK_VERSION}_all.deb # Download and install agent
pkginst xinetd /tmp/check-mk-agent_${MK_VERSION}_all.deb wget "$MK_URL" -O /tmp/check-mk-agent_latest_all.deb
rm /tmp/check-mk-agent_${MK_VERSION}_all.deb pkginst /tmp/check-mk-agent_latest_all.deb
rm /tmp/check-mk-agent_latest_all.deb
backup_dist /etc/xinetd.d/check_mk # Activate correct service depending on system configuration
install_file cmk/check_mk /etc/xinetd.d/check_mk if pidof systemd >/dev/null; then
tag_file /etc/xinetd.d/check_mk systemctl enable --now check-mk-agent.socket
sed -i -e "s/@MK_SERVER_IP@/$MK_SERVER_IP/" /etc/xinetd.d/check_mk else
pkginst xinetd
backup_dist /etc/xinetd.d/check-mk-agent
install_file cmk/check_mk /etc/xinetd.d/check-mk-agent
tag_file /etc/xinetd.d/check-mk-agent
sed -i -e "s/@MK_SERVER_IP@/$MK_SERVER_IP/" /etc/xinetd.d/check-mk-agent
svc_restart xinetd
fi
mkdir -pv /usr/lib/check_mk_agent/plugins/7200 # Install apt plugin (for Debian)
install_file cmk/mk_apt /usr/lib/check_mk_agent/plugins/7200/mk_apt if [[ $PKG_MAN == "apt-get" ]]; then
mkdir -pv /usr/lib/check_mk_agent/plugins/3600
install_file cmk/mk_apt /usr/lib/check_mk_agent/plugins/3600/mk_apt
fi
# Cmk > 2.1, configure agent # Cmk > 2.1, configure agent
if [[ -n $MK_SECRET ]]; then
local secret
secret=$(fetch_secret "$MK_SECRET")
if [[ -e /var/lib/cmk-agent/cmk-agent-ctl.gz ]]; then if [[ -e /var/lib/cmk-agent/cmk-agent-ctl.gz ]]; then
gunzip /var/lib/cmk-agent/cmk-agent-ctl.gz gunzip -f /var/lib/cmk-agent/cmk-agent-ctl.gz
chmod +x /var/lib/cmk-agent/cmk-agent-ctl chmod +x /var/lib/cmk-agent/cmk-agent-ctl
scp -O $MK_SERVER_IP:/etc/check_mk/agentpwd /tmp/mk-pwd
sleep 1 # Some execution of cmk-agent-ctl have failed with file not found without that line
/var/lib/cmk-agent/cmk-agent-ctl register --hostname $HOSTNAME \
--server $MK_SERVER_IP --site check_mk --user check_mk --password \
"$(read /tmp/mk-pwd)"
fi fi
svc_restart xinetd if [[ -e /var/lib/cmk-agent/cmk-agent-ctl ]]; then
/var/lib/cmk-agent/cmk-agent-ctl register \
--hostname "$HOSTNAME" \
--server "$MK_SERVER_IP" \
--site "$MK_SITE" \
--user "$MK_USER" \
--password "$secret"
fi
unset secret
else
prnt W "No secret configured, agent cannot be registered."
fi
} }
precheck_install_mkagent() precheck_install_mkagent()
{ {
if [[ -z $MK_VERSION ]]; then if [[ -z $MK_SITE ]]; then
prnt E "Undeclared check_mk version of the agent to install." prnt E "Undeclared check_mk site to use."
die 162 die 162
fi fi
if [[ -z $MK_URL ]]; then if [[ -z $MK_URL ]]; then
@@ -56,7 +80,16 @@ precheck_install_mkagent()
prnt E "Undeclared check_mk server." prnt E "Undeclared check_mk server."
die 162 die 162
fi fi
if [[ $PKG_MAN == "apt-get" ]]; then
file_must_exists cmk/check_mk cmk/mk_apt file_must_exists cmk/check_mk cmk/mk_apt
fi
if [[ -z $MK_SECRET ]]; then
prnt W "No secret set for CheckMK, registration won't be possible."
if [[ -z $MK_USER ]]; then
prnt E "A CheckMK user is required to register."
die 162
fi
fi
} }
export -f install_mkagent export -f install_mkagent