Skip to content

Commit

Permalink
CMK-19981: UNIX agent: support new directory structure
Browse files Browse the repository at this point in the history
Introduce MK_INSTALLDIR variable.
It can either be passed as environment variable, or be set
manually by editing the agent shell script.
When set, the agent will apply the new directory structure and
ignore all other configured agent directories.

Change-Id: Iea3d87826c13092cdce0d401c2013be6f8479a63
  • Loading branch information
andiumbreit committed Nov 5, 2024
1 parent eeb38ed commit 873bd85
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 23 deletions.
32 changes: 30 additions & 2 deletions agents/check_mk_agent.aix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
# BEGIN COMMON AGENT CODE
#

###
# Note on agent package deployment modes:
# (Only relevant when deploying a Checkmk agent package manually)
# Agent paths (MK_LIBDIR, MK_CONFDIR, MK_VARDIR, MK_LOGDIR, MK_BIN)
# can be configured implicitly by setting MK_INSTALLDIR in function "set_up_single_directory()"
# or by setting the path variables explicitly under "set_default_paths()".
# Please refer to the official documentation for more details.
###

usage() {
cat <<HERE
Usage: ${0} [OPTION...]
Expand Down Expand Up @@ -99,11 +108,20 @@ set_up_current_shell() {
CURRENT_SHELL="$(ps -o args= -p $$ | cut -d' ' -f1)"
}

set_up_single_directory() {
# Set this path when deploying the Checkmk agent installation
# under a single directory.
: "${MK_INSTALLDIR:=""}"
}

#
# END COMMON AGENT CODE
#

set_variable_defaults() {
set_default_paths() {
# Set/edit these paths when deploying the Checkmk agent installation
# under multiple directories.
# Will be ignored if MK_INSTALLDIR is already set and not empty.
: "${MK_LIBDIR:="/usr/check_mk/lib"}"
: "${MK_CONFDIR:="/usr/check_mk/conf"}"
: "${MK_VARDIR:="/tmp/check_mk"}"
Expand Down Expand Up @@ -142,6 +160,15 @@ determine_sync_async() {
}

provide_agent_paths() {
# If MK_INSTALLDIR is set, this will always win over separately set agent paths
[ -n "${MK_INSTALLDIR}" ] && {
MK_LIBDIR="${MK_INSTALLDIR}/package"
MK_CONFDIR="${MK_INSTALLDIR}/package/config"
MK_VARDIR="${MK_INSTALLDIR}/runtime"
MK_LOGDIR="${MK_INSTALLDIR}/runtime/log"
MK_BIN="${MK_INSTALLDIR}/package/bin"
}

export MK_LIBDIR
export MK_CONFDIR
export MK_VARDIR
Expand Down Expand Up @@ -1020,8 +1047,9 @@ main_setup() {
fi
set_up_get_epoch
set_up_current_shell
set_variable_defaults
determine_sync_async
set_up_single_directory
set_default_paths
provide_agent_paths
unset_locale
preamble_1
Expand Down
33 changes: 30 additions & 3 deletions agents/check_mk_agent.freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
# BEGIN COMMON AGENT CODE
#

###
# Note on agent package deployment modes:
# (Only relevant when deploying a Checkmk agent package manually)
# Agent paths (MK_LIBDIR, MK_CONFDIR, MK_VARDIR, MK_LOGDIR, MK_BIN)
# can be configured implicitly by setting MK_INSTALLDIR in function "set_up_single_directory()"
# or by setting the path variables explicitly under "set_default_paths()".
# Please refer to the official documentation for more details.
###

usage() {
cat <<HERE
Usage: ${0} [OPTION...]
Expand Down Expand Up @@ -112,11 +121,20 @@ set_up_current_shell() {
CURRENT_SHELL="$(ps -o args= -p $$ | cut -d' ' -f1)"
}

set_up_single_directory() {
# Set this path when deploying the Checkmk agent installation
# under a single directory.
: "${MK_INSTALLDIR:=""}"
}

#
# END COMMON AGENT CODE
#

set_variable_defaults() {
set_default_paths() {
# Set/edit these paths when deploying the Checkmk agent installation
# under multiple directories.
# Will be ignored if MK_INSTALLDIR is already set and not empty.
: "${MK_LIBDIR:="/usr/local/lib/check_mk_agent"}"
: "${MK_CONFDIR:="/etc/check_mk"}"
: "${MK_VARDIR:="/var/lib/check_mk_agent"}"
Expand Down Expand Up @@ -146,6 +164,15 @@ determine_sync_async() {
}

provide_agent_paths() {
# If MK_INSTALLDIR is set, this will always win over separately set agent paths
[ -n "${MK_INSTALLDIR}" ] && {
MK_LIBDIR="${MK_INSTALLDIR}/package"
MK_CONFDIR="${MK_INSTALLDIR}/package/config"
MK_VARDIR="${MK_INSTALLDIR}/runtime"
MK_LOGDIR="${MK_INSTALLDIR}/runtime/log"
MK_BIN="${MK_INSTALLDIR}/package/bin"
}

export MK_LIBDIR
export MK_CONFDIR
export MK_VARDIR
Expand Down Expand Up @@ -979,10 +1006,10 @@ main_setup() {

set_up_current_shell

set_variable_defaults

determine_sync_async

set_up_single_directory
set_default_paths
provide_agent_paths

unset_locale
Expand Down
36 changes: 31 additions & 5 deletions agents/check_mk_agent.linux
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
# BEGIN COMMON AGENT CODE
#

###
# Note on agent package deployment modes:
# (Only relevant when deploying a Checkmk agent package manually)
# Agent paths (MK_LIBDIR, MK_CONFDIR, MK_VARDIR, MK_LOGDIR, MK_BIN)
# can be configured implicitly by setting MK_INSTALLDIR in function "set_up_single_directory()"
# or by setting the path variables explicitly under "set_default_paths()".
# Please refer to the official documentation for more details.
###

usage() {
cat <<HERE
Usage: ${0} [OPTION...]
Expand Down Expand Up @@ -99,14 +108,20 @@ set_up_current_shell() {
CURRENT_SHELL="$(ps -o args= -p $$ | cut -d' ' -f1)"
}

set_up_single_directory() {
# Set this path when deploying the Checkmk agent installation
# under a single directory.
: "${MK_INSTALLDIR:=""}"
}

#
# END COMMON AGENT CODE
#

set_variable_defaults() {
# WATCH OUT: These 5 lines are searched for and replaced by the
# agent bakery!
# TODO: CMK-8339 (proper configuration)
set_default_paths() {
# Set/edit these paths when deploying the Checkmk agent installation
# under multiple directories.
# Will be ignored if MK_INSTALLDIR is already set and not empty.
: "${MK_LIBDIR:="/usr/lib/check_mk_agent"}"
: "${MK_CONFDIR:="/etc/check_mk"}"
: "${MK_VARDIR:="/var/lib/check_mk_agent"}"
Expand Down Expand Up @@ -154,6 +169,15 @@ determine_sync_async() {
}

provide_agent_paths() {
# If MK_INSTALLDIR is set, this will always win over separately set agent paths
[ -n "${MK_INSTALLDIR}" ] && {
MK_LIBDIR="${MK_INSTALLDIR}/package"
MK_CONFDIR="${MK_INSTALLDIR}/package/config"
MK_VARDIR="${MK_INSTALLDIR}/runtime"
MK_LOGDIR="${MK_INSTALLDIR}/runtime/log"
MK_BIN="${MK_INSTALLDIR}/package/bin"
}

export MK_LIBDIR
export MK_CONFDIR
export MK_VARDIR
Expand Down Expand Up @@ -2261,8 +2285,10 @@ main_setup() {

set_up_current_shell

set_variable_defaults
determine_sync_async

set_up_single_directory
set_default_paths
provide_agent_paths

announce_remote # needs MK_VARDIR!
Expand Down
33 changes: 30 additions & 3 deletions agents/check_mk_agent.openwrt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
# BEGIN COMMON AGENT CODE
#

###
# Note on agent package deployment modes:
# (Only relevant when deploying a Checkmk agent package manually)
# Agent paths (MK_LIBDIR, MK_CONFDIR, MK_VARDIR, MK_LOGDIR, MK_BIN)
# can be configured implicitly by setting MK_INSTALLDIR in function "set_up_single_directory()"
# or by setting the path variables explicitly under "set_default_paths()".
# Please refer to the official documentation for more details.
###

usage() {
cat <<HERE
Usage: ${0} [OPTION...]
Expand Down Expand Up @@ -101,11 +110,20 @@ set_up_current_shell() {
CURRENT_SHELL="$(ps -o args= -p $$ | cut -d' ' -f1)"
}

set_up_single_directory() {
# Set this path when deploying the Checkmk agent installation
# under a single directory.
: "${MK_INSTALLDIR:=""}"
}

#
# END COMMON AGENT CODE
#

set_variable_defaults() {
set_default_paths() {
# Set/edit these paths when deploying the Checkmk agent installation
# under multiple directories.
# Will be ignored if MK_INSTALLDIR is already set and not empty.
: "${MK_LIBDIR:="/usr/lib/check_mk_agent"}"
: "${MK_CONFDIR:="/etc/check_mk"}"
: "${MK_VARDIR:="/var/lib/check_mk_agent"}"
Expand Down Expand Up @@ -146,6 +164,15 @@ determine_sync_async() {
}

provide_agent_paths() {
# If MK_INSTALLDIR is set, this will always win over separately set agent paths
[ -n "${MK_INSTALLDIR}" ] && {
MK_LIBDIR="${MK_INSTALLDIR}/package"
MK_CONFDIR="${MK_INSTALLDIR}/package/config"
MK_VARDIR="${MK_INSTALLDIR}/runtime"
MK_LOGDIR="${MK_INSTALLDIR}/runtime/log"
MK_BIN="${MK_INSTALLDIR}/package/bin"
}

export MK_LIBDIR
export MK_CONFDIR
export MK_VARDIR
Expand Down Expand Up @@ -1524,10 +1551,10 @@ main_setup() {

set_up_current_shell

set_variable_defaults

determine_sync_async

set_up_single_directory
set_default_paths
provide_agent_paths

set_up_profiling
Expand Down
47 changes: 37 additions & 10 deletions agents/check_mk_agent.solaris
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
# BEGIN COMMON AGENT CODE
#

###
# Note on agent package deployment modes:
# (Only relevant when deploying a Checkmk agent package manually)
# Agent paths (MK_LIBDIR, MK_CONFDIR, MK_VARDIR, MK_LOGDIR, MK_BIN)
# can be configured implicitly by setting MK_INSTALLDIR in function "set_up_single_directory()"
# or by setting the path variables explicitly under "set_default_paths()".
# Please refer to the official documentation for more details.
###

usage() {
cat <<HERE
Usage: ${0} [OPTION...]
Expand Down Expand Up @@ -99,25 +108,34 @@ set_up_current_shell() {
CURRENT_SHELL="$(ps -o args= -p $$ | cut -d' ' -f1)"
}

set_up_single_directory() {
# Set this path when deploying the Checkmk agent installation
# under a single directory.
: "${MK_INSTALLDIR:=""}"
}

#
# END COMMON AGENT CODE
#

set_up_grep() {
# https://docs.oracle.com/cd/E19683-01/816-0210/6m6nb7m89/index.html:
# The /usr/xpg4/bin/egrep utility is identical to /usr/xpg4/bin/grep -E
# (see grep(1)). Portable applications should use /usr/xpg4/bin/grep -E.
[ -x /usr/xpg4/bin/grep ] && grep() { "/usr/xpg4/bin/grep" "$@"; }
}

set_variable_defaults() {
set_default_paths() {
# Set/edit these paths when deploying the Checkmk agent installation
# under multiple directories.
# Will be ignored if MK_INSTALLDIR is already set and not empty.
: "${MK_LIBDIR:="/usr/lib/check_mk_agent"}"
: "${MK_CONFDIR:="/etc/check_mk"}"
: "${MK_VARDIR:="/var/lib/check_mk_agent"}"
: "${MK_LOGDIR:="/var/log/check_mk_agent"}"
: "${MK_BIN:="/usr/bin"}"
}

set_up_grep() {
# https://docs.oracle.com/cd/E19683-01/816-0210/6m6nb7m89/index.html:
# The /usr/xpg4/bin/egrep utility is identical to /usr/xpg4/bin/grep -E
# (see grep(1)). Portable applications should use /usr/xpg4/bin/grep -E.
[ -x /usr/xpg4/bin/grep ] && grep() { "/usr/xpg4/bin/grep" "$@"; }
}

preamble_1() {
# Provide information about the remote host. That helps when data
# is being sent only once to each remote host.
Expand All @@ -139,6 +157,15 @@ determine_sync_async() {
}

provide_agent_paths() {
# If MK_INSTALLDIR is set, this will always win over separately set agent paths
[ -n "${MK_INSTALLDIR}" ] && {
MK_LIBDIR="${MK_INSTALLDIR}/package"
MK_CONFDIR="${MK_INSTALLDIR}/package/config"
MK_VARDIR="${MK_INSTALLDIR}/runtime"
MK_LOGDIR="${MK_INSTALLDIR}/runtime/log"
MK_BIN="${MK_INSTALLDIR}/package/bin"
}

export MK_LIBDIR
export MK_CONFDIR
export MK_VARDIR
Expand Down Expand Up @@ -1065,10 +1092,10 @@ main_setup() {

set_up_grep

set_variable_defaults

determine_sync_async

set_up_single_directory
set_default_paths
provide_agent_paths

unset_locale
Expand Down

0 comments on commit 873bd85

Please sign in to comment.