Files
init.sh/modules/install_mkagent.sh

65 lines
2.2 KiB
Bash

# ------------------------------------------------------------------------------
# Install check_mk agent using xinetd superserver
# This file is part of the init.sh project
# Copyright (c) 2019-2023 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# ------------------------------------------------------------------------------
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# https://opensource.org/licenses/BSD-3-Clause
# ------------------------------------------------------------------------------
# Variable:
# * MK_SERVER: Server IP address
# * MK_PORT: Port check_mk agent will use to communicate with server
# ------------------------------------------------------------------------------
export VER_install_mkagent="0.0.6"
export DEP_install_mkagent="upgrade_dist install_pkg"
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
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
mkdir -pv /usr/lib/check_mk_agent/plugins/7200
install_file cmk/mk_apt /usr/lib/check_mk_agent/plugins/7200/mk_apt
# Cmk > 2.1, configure agent
if [[ -e /var/lib/cmk-agent/cmk-agent-ctl.gz ]]; then
gunzip /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
/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
}
precheck_install_mkagent()
{
if [[ -z $MK_VERSION ]]; then
prnt E "Undeclared check_mk version of the agent to install."
die 162
fi
if [[ -z $MK_URL ]]; then
prnt E "Undeclared check_mk download URL."
die 162
fi
if [[ -z $MK_SERVER_IP ]]; then
prnt E "Undeclared check_mk server."
die 162
fi
file_must_exists cmk/check_mk cmk/mk_apt
}
export -f install_mkagent
export -f precheck_install_mkagent
# EOF