reworked the checkmk module
This commit is contained in:
@@ -9,43 +9,67 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Variable:
|
||||
# * 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=""
|
||||
|
||||
install_mkagent()
|
||||
{
|
||||
wget $MK_URL -O /tmp/check-mk-agent_${MK_VERSION}_all.deb
|
||||
pkginst xinetd /tmp/check-mk-agent_${MK_VERSION}_all.deb
|
||||
rm /tmp/check-mk-agent_${MK_VERSION}_all.deb
|
||||
# Download and install agent
|
||||
wget "$MK_URL" -O /tmp/check-mk-agent_latest_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
|
||||
install_file cmk/check_mk /etc/xinetd.d/check_mk
|
||||
tag_file /etc/xinetd.d/check_mk
|
||||
sed -i -e "s/@MK_SERVER_IP@/$MK_SERVER_IP/" /etc/xinetd.d/check_mk
|
||||
# Activate correct service depending on system configuration
|
||||
if pidof systemd >/dev/null; then
|
||||
systemctl enable --now check-mk-agent.socket
|
||||
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_file cmk/mk_apt /usr/lib/check_mk_agent/plugins/7200/mk_apt
|
||||
# Install apt plugin (for Debian)
|
||||
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
|
||||
if [[ -n $MK_SECRET ]]; then
|
||||
local secret
|
||||
secret=$(fetch_secret "$MK_SECRET")
|
||||
|
||||
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
|
||||
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
|
||||
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()
|
||||
{
|
||||
if [[ -z $MK_VERSION ]]; then
|
||||
prnt E "Undeclared check_mk version of the agent to install."
|
||||
if [[ -z $MK_SITE ]]; then
|
||||
prnt E "Undeclared check_mk site to use."
|
||||
die 162
|
||||
fi
|
||||
if [[ -z $MK_URL ]]; then
|
||||
@@ -56,7 +80,16 @@ precheck_install_mkagent()
|
||||
prnt E "Undeclared check_mk server."
|
||||
die 162
|
||||
fi
|
||||
if [[ $PKG_MAN == "apt-get" ]]; then
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user