reworked the checkmk module
This commit is contained in:
@@ -9,54 +9,87 @@
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# 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 [[ -e /var/lib/cmk-agent/cmk-agent-ctl.gz ]]; then
|
if [[ -n $MK_SECRET ]]; then
|
||||||
gunzip /var/lib/cmk-agent/cmk-agent-ctl.gz
|
local secret
|
||||||
chmod +x /var/lib/cmk-agent/cmk-agent-ctl
|
secret=$(fetch_secret "$MK_SECRET")
|
||||||
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
|
if [[ -e /var/lib/cmk-agent/cmk-agent-ctl.gz ]]; then
|
||||||
/var/lib/cmk-agent/cmk-agent-ctl register --hostname $HOSTNAME \
|
gunzip -f /var/lib/cmk-agent/cmk-agent-ctl.gz
|
||||||
--server $MK_SERVER_IP --site check_mk --user check_mk --password \
|
chmod +x /var/lib/cmk-agent/cmk-agent-ctl
|
||||||
"$(read /tmp/mk-pwd)"
|
fi
|
||||||
|
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
|
fi
|
||||||
svc_restart xinetd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
prnt E "Undeclared check_mk download URL."
|
prnt E "Undeclared check_mk download URL."
|
||||||
die 162
|
die 162
|
||||||
fi
|
fi
|
||||||
if [[ -z $MK_SERVER_IP ]]; then
|
if [[ -z $MK_SERVER_IP ]]; then
|
||||||
prnt E "Undeclared check_mk server."
|
prnt E "Undeclared check_mk server."
|
||||||
die 162
|
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
|
fi
|
||||||
file_must_exists cmk/check_mk cmk/mk_apt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export -f install_mkagent
|
export -f install_mkagent
|
||||||
|
|||||||
Reference in New Issue
Block a user