mirror of
https://github.com/limosek/zaf.git
synced 2025-11-01 10:07:38 +01:00
Switched working flow to trunk
This commit is contained in:
@@ -71,12 +71,13 @@ zaf_ctrl_get_item_option() {
|
||||
zaf_ctrl_check_deps() {
|
||||
local deps
|
||||
deps=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Depends-${ZAF_PKG}" )
|
||||
zaf_os_specific zaf_check_deps $deps
|
||||
if ! zaf_os_specific zaf_check_deps $deps; then
|
||||
zaf_err "Missing one of dependend system packages: $deps"
|
||||
fi
|
||||
deps=$(zaf_ctrl_get_global_block <$1 | zaf_block_get_option "Depends-bin" )
|
||||
for cmd in $deps; do
|
||||
if ! which $cmd >/dev/null; then
|
||||
zaf_wrn "Missing binary dependency $cmd. Please install it first."
|
||||
return 1
|
||||
zaf_err "Missing binary dependency $cmd. Please install it first."
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -139,7 +140,7 @@ zaf_ctrl_generate_cfg() {
|
||||
fi
|
||||
cmd=$(zaf_ctrl_get_item_option $1 $i "Function")
|
||||
if [ -n "$cmd" ]; then
|
||||
$(which echo) -E "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $lock$cmd";
|
||||
$(which echo) "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $lock$cmd";
|
||||
continue;
|
||||
fi
|
||||
cmd=$(zaf_ctrl_get_item_option $1 $i "Script")
|
||||
|
||||
@@ -12,28 +12,30 @@ zaf_configure_os_freebsd() {
|
||||
ZAF_AGENT_PKG="zabbix3-agent"
|
||||
ZAF_AGENT_CONFIG="/usr/local/etc/zabbix3/zabbix_agentd.conf"
|
||||
ZAF_AGENT_CONFIGD="/usr/local/etc/zabbix3/zabbix_agentd.conf.d/"
|
||||
ZAF_AGENT_BIN="/usr/local/sbin/zabbix_agentd"
|
||||
ZAF_AGENT_RESTART="service zabbix_agentd restart"
|
||||
}
|
||||
|
||||
zaf_detect_system() {
|
||||
if which dpkg >/dev/null; then
|
||||
ZAF_PKG=dpkg
|
||||
ZAF_OS=$(lsb_release -is|tr '[:upper:]' '[:lower:]')
|
||||
ZAF_OS_CODENAME=$(lsb_release -cs|tr '[:upper:]' '[:lower:]')
|
||||
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
||||
ZAF_OS_CODENAME=$(lsb_release -cs|zaf_tolower)
|
||||
ZAF_CURL_INSECURE=0
|
||||
ZAF_AGENT_PKG="zabbix-agent"
|
||||
return
|
||||
else if which rpm >/dev/null; then
|
||||
ZAF_PKG="rpm"
|
||||
ZAF_OS=$(lsb_release -is|tr '[:upper:]' '[:lower:]')
|
||||
ZAF_OS_CODENAME=$(lsb_release -cs|tr '[:upper:]' '[:lower:]')
|
||||
ZAF_OS=$(lsb_release -is|zaf_tolower)
|
||||
ZAF_OS_CODENAME=$(lsb_release -cs|zaf_tolower)
|
||||
ZAF_CURL_INSECURE=0
|
||||
ZAF_AGENT_PKG="zabbix-agent"
|
||||
return
|
||||
else if which opkg >/dev/null; then
|
||||
ZAF_PKG="opkg"
|
||||
. /etc/openwrt_release
|
||||
ZAF_OS="$(echo $DISTRIB_ID|tr '[:upper:]' '[:lower:]')"
|
||||
ZAF_OS_CODENAME="$(echo $DISTRIB_CODENAME|tr '[:upper:]' '[:lower:]')"
|
||||
ZAF_OS="$(echo $DISTRIB_ID|zaf_tolower)"
|
||||
ZAF_OS_CODENAME="$(echo $DISTRIB_CODENAME|zaf_tolower)"
|
||||
return
|
||||
else if which pkg >/dev/null; then
|
||||
ZAF_PKG="pkg"
|
||||
@@ -145,7 +147,7 @@ zaf_check_deps_rpm() {
|
||||
zaf_check_deps_opkg() {
|
||||
local p
|
||||
for p in $*; do
|
||||
opkg info $p | grep -q 'Package:' || { echo "Missing package $p" >&2; return 1; }
|
||||
opkg info $p | grep -q 'Package:' || { return 1; }
|
||||
done
|
||||
}
|
||||
|
||||
@@ -154,7 +156,7 @@ zaf_check_deps_opkg() {
|
||||
zaf_check_deps_pkg() {
|
||||
local p
|
||||
for p in $*; do
|
||||
pkg query -x "Package: %n" $p| grep -q 'Package:' || { echo "Missing package $p" >&2; return 1; }
|
||||
pkg query -x "Package: %n" $p| grep -q 'Package:' || { return 1; }
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# Hardcoded variables
|
||||
ZAF_VERSION="master"
|
||||
ZAF_URL="https://github.com/limosek/zaf"
|
||||
ZAF_RAW_URL="https://raw.githubusercontent.com/limosek/zaf"
|
||||
|
||||
############################################ Common routines
|
||||
|
||||
@@ -143,11 +144,11 @@ zaf_check_agent_config() {
|
||||
|
||||
# Update repo
|
||||
zaf_update_repo() {
|
||||
[ "$ZAF_GIT" != 1 ] && { zaf_err "Git is not installed. Exiting."; }
|
||||
if [ -z "${ZAF_PLUGINS_GITURL}" ] || [ -z "${ZAF_REPO_DIR}" ]; then
|
||||
[ "$ZAF_GIT" != 1 ] && { zaf_err "Git is disabled or is not installed. Exiting."; }
|
||||
if [ -z "${ZAF_REPO_GITURL}" ] || [ -z "${ZAF_REPO_DIR}" ]; then
|
||||
zaf_err "This system is not configured for git repository."
|
||||
else
|
||||
[ ! -d "${ZAF_REPO_DIR}" ] && git clone "${ZAF_PLUGINS_GITURL}" "${ZAF_REPO_DIR}"
|
||||
[ ! -d "${ZAF_REPO_DIR}" ] && git clone "${ZAF_REPO_GITURL}" "${ZAF_REPO_DIR}"
|
||||
(cd ${ZAF_REPO_DIR} && git pull)
|
||||
fi
|
||||
}
|
||||
@@ -171,7 +172,11 @@ zaf_get_plugin_url() {
|
||||
if [ -n "${ZAF_PREPACKAGED_DIR}" ] && [ -d "${ZAF_PREPACKAGED_DIR}/$1" ]; then
|
||||
url="${ZAF_PREPACKAGED_DIR}/$1"
|
||||
else
|
||||
zaf_err "Plugin $1 not found."
|
||||
if [ -n "${ZAF_REPO_URL}" ]; then
|
||||
url="${ZAF_REPO_URL}/$1"
|
||||
else
|
||||
zaf_err "Cannot find plugin $1"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -183,6 +188,7 @@ zaf_get_plugin_url() {
|
||||
zaf_plugin_info() {
|
||||
local control="$1"
|
||||
|
||||
! [ -f "$control" ] && zaf_err "Control file $control not found."
|
||||
plugin=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Plugin)
|
||||
pdescription=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_moption Description)
|
||||
pmaintainer=$(zaf_ctrl_get_global_block <"${control}" | zaf_block_get_option Maintainer)
|
||||
@@ -209,7 +215,7 @@ zaf_prepare_plugin() {
|
||||
local plugindir
|
||||
local control
|
||||
|
||||
url=$(zaf_get_plugin_url "$1")/control.zaf
|
||||
url=$(zaf_get_plugin_url "$1")/control.zaf || exit $?
|
||||
plugindir="$2"
|
||||
control=${plugindir}/control.zaf
|
||||
zaf_install_dir "$plugindir"
|
||||
@@ -217,7 +223,7 @@ zaf_prepare_plugin() {
|
||||
if zaf_fetch_url "$url" >"${control}"; then
|
||||
zaf_ctrl_check_deps "${control}"
|
||||
else
|
||||
zaf_err "Cannot fetch or write control file!"
|
||||
zaf_err "prepare_plugin: Cannot fetch or write control file $control from url $url!"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -231,7 +237,7 @@ zaf_install_plugin() {
|
||||
url=$(zaf_get_plugin_url "$1")
|
||||
plugin=$(zaf_ctrl_get_global_block <"${ZAF_TMP_DIR}/plugin/control.zaf" | zaf_block_get_option Plugin)
|
||||
plugindir="${ZAF_PLUGINS_DIR}"/$plugin
|
||||
if zaf_prepare_plugin "$1" $plugindir; then
|
||||
if [ -n "$plugin" ] && zaf_prepare_plugin "$1" $plugindir; then
|
||||
control=${plugindir}/control.zaf
|
||||
[ "$ZAF_DEBUG" -gt 0 ] && zaf_plugin_info "${control}"
|
||||
zaf_ctrl_check_deps "${control}"
|
||||
@@ -240,7 +246,7 @@ zaf_install_plugin() {
|
||||
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
||||
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
|
||||
else
|
||||
zaf_err "Cannot install plugin $plugin to $plugindir!"
|
||||
zaf_err "Cannot install plugin '$plugin' to $plugindir!"
|
||||
fi
|
||||
else
|
||||
zaf_err "Cannot prepare plugin $1"
|
||||
@@ -266,7 +272,9 @@ zaf_discovery_plugins() {
|
||||
zaf_list_plugins | zaf_discovery '{#PLUGIN}'
|
||||
}
|
||||
|
||||
zaf_plugin_version() {
|
||||
# $1 plugin
|
||||
# $2 ctrl_option
|
||||
zaf_plugin_option() {
|
||||
local plugindir
|
||||
local cfile
|
||||
|
||||
@@ -276,12 +284,28 @@ zaf_plugin_version() {
|
||||
if zaf_is_plugin "$1"; then
|
||||
plugindir="${ZAF_PLUGINS_DIR}/$1"
|
||||
cfile="$plugindir/control.zaf"
|
||||
zaf_ctrl_get_global_option $cfile Version
|
||||
zaf_ctrl_get_global_option $cfile $2
|
||||
else
|
||||
zaf_err "Plugin $1 not installed."
|
||||
fi
|
||||
}
|
||||
|
||||
zaf_plugin_version() {
|
||||
zaf_plugin_option "$1" Version
|
||||
}
|
||||
zaf_plugin_maintainer() {
|
||||
zaf_plugin_option "$1" Maintainer
|
||||
}
|
||||
zaf_plugin_url() {
|
||||
zaf_plugin_option "$1" Url
|
||||
}
|
||||
zaf_plugin_web() {
|
||||
zaf_plugin_option "$1" Web
|
||||
}
|
||||
zaf_plugin_template_url() {
|
||||
echo $(zaf_plugin_option "$1" Url)/template.xml
|
||||
}
|
||||
|
||||
zaf_list_plugin_items() {
|
||||
local items
|
||||
local i
|
||||
@@ -312,7 +336,18 @@ zaf_list_items() {
|
||||
done
|
||||
}
|
||||
|
||||
zaf_get_item() {
|
||||
if which zabbix_get >/dev/null; then
|
||||
zabbix_get -s localhost -k "$1" || zaf_wrn "Cannot reach agent on localhost. Please localhost to Server list."
|
||||
return 11
|
||||
else
|
||||
zaf_wrn "Please install zabbix_get binary to check items over network."
|
||||
return 11
|
||||
fi
|
||||
}
|
||||
|
||||
zaf_test_item() {
|
||||
[ "$USER" != "zabbix" ] && zaf_wrn "You are not zabbix user. Test will be run with your privileges and sudo access!"
|
||||
$ZAF_AGENT_BIN -t "$1"
|
||||
}
|
||||
|
||||
@@ -323,4 +358,11 @@ zaf_remove_plugin() {
|
||||
rm -f ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
||||
}
|
||||
|
||||
zaf_tolower() {
|
||||
tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
|
||||
}
|
||||
|
||||
zaf_toupper() {
|
||||
tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user