mirror of
https://github.com/limosek/zaf.git
synced 2024-11-22 02:19:06 +01:00
Repaired userparms creation and including libraries
This commit is contained in:
parent
84f7e55078
commit
ddbdff55d9
@ -281,7 +281,7 @@ zaf_install_all() {
|
|||||||
for i in lib/zaf.lib.sh lib/os.lib.sh lib/ctrl.lib.sh lib/cache.lib.sh lib/zbxapi.lib.sh README.md; do
|
for i in lib/zaf.lib.sh lib/os.lib.sh lib/ctrl.lib.sh lib/cache.lib.sh lib/zbxapi.lib.sh README.md; do
|
||||||
zaf_install $i ${ZAF_LIB_DIR}/ || zaf_err "Error installing $i"
|
zaf_install $i ${ZAF_LIB_DIR}/ || zaf_err "Error installing $i"
|
||||||
done
|
done
|
||||||
for i in lib/zaflock lib/preload.sh; do
|
for i in lib/zaflock lib/zafcache lib/preload.sh; do
|
||||||
zaf_install_bin $i ${ZAF_LIB_DIR}/ || zaf_err "Error installing $i"
|
zaf_install_bin $i ${ZAF_LIB_DIR}/ || zaf_err "Error installing $i"
|
||||||
done
|
done
|
||||||
zaf_install_dir ${ZAF_BIN_DIR}
|
zaf_install_dir ${ZAF_BIN_DIR}
|
||||||
@ -295,8 +295,10 @@ zaf_install_all() {
|
|||||||
|
|
||||||
zaf_postconfigure() {
|
zaf_postconfigure() {
|
||||||
if zaf_is_root; then
|
if zaf_is_root; then
|
||||||
|
${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf cache-clean
|
||||||
[ "${ZAF_GIT}" = 1 ] && ${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf update
|
[ "${ZAF_GIT}" = 1 ] && ${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf update
|
||||||
${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf reinstall zaf || zaf_err "Error installing zaf plugin."
|
${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf reinstall zaf || zaf_err "Error installing zaf plugin."
|
||||||
|
${INSTALL_PREFIX}/${ZAF_BIN_DIR}/zaf agent-config || zaf_err "Error configuring agent."
|
||||||
if zaf_is_root && ! zaf_test_item zaf.framework_version; then
|
if zaf_is_root && ! zaf_test_item zaf.framework_version; then
|
||||||
echo "Something is wrong with zabbix agent config."
|
echo "Something is wrong with zabbix agent config."
|
||||||
echo "Ensure that zabbix_agentd reads ${ZAF_AGENT_CONFIG}"
|
echo "Ensure that zabbix_agentd reads ${ZAF_AGENT_CONFIG}"
|
||||||
|
@ -8,7 +8,7 @@ zaf_ctrl_get_items() {
|
|||||||
# Get item body from stdin
|
# Get item body from stdin
|
||||||
# $1 itemname
|
# $1 itemname
|
||||||
zaf_ctrl_get_item_block() {
|
zaf_ctrl_get_item_block() {
|
||||||
grep -v '^#' | awk '/^Item '$1'/ { i=0;
|
grep -vE '^#[a-zA-Z ]' | awk '/^Item '$1'/ { i=0;
|
||||||
while (i==0) {
|
while (i==0) {
|
||||||
getline;
|
getline;
|
||||||
if (/^\/Item/) exit;
|
if (/^\/Item/) exit;
|
||||||
@ -22,7 +22,7 @@ zaf_ctrl_get_item_block() {
|
|||||||
# Get global plugin block body from stdin
|
# Get global plugin block body from stdin
|
||||||
# $1 itemname
|
# $1 itemname
|
||||||
zaf_ctrl_get_global_block() {
|
zaf_ctrl_get_global_block() {
|
||||||
grep -v '^#' | awk '{ i=0; print $0;
|
grep -vE '^#[a-zA-Z ]' | awk '{ i=0; print $0;
|
||||||
while (i==0) {
|
while (i==0) {
|
||||||
getline;
|
getline;
|
||||||
if (/^Item /) exit;
|
if (/^Item /) exit;
|
||||||
@ -33,7 +33,7 @@ zaf_ctrl_get_global_block() {
|
|||||||
# Get item multiline option
|
# Get item multiline option
|
||||||
# $1 optionname
|
# $1 optionname
|
||||||
zaf_block_get_moption() {
|
zaf_block_get_moption() {
|
||||||
awk '/^'$1'::$/ { i=0; print $0;
|
awk '/^'$1'::$/ { i=0;
|
||||||
while (i==0) {
|
while (i==0) {
|
||||||
getline;
|
getline;
|
||||||
if (/^::$/) {i=1; continue;};
|
if (/^::$/) {i=1; continue;};
|
||||||
@ -181,6 +181,7 @@ zaf_ctrl_install() {
|
|||||||
# Generates zabbix cfg from control file
|
# Generates zabbix cfg from control file
|
||||||
# $1 control
|
# $1 control
|
||||||
# $2 pluginname
|
# $2 pluginname
|
||||||
|
# $3 if nonempty, only return cfg, do not generate scripts
|
||||||
zaf_ctrl_generate_cfg() {
|
zaf_ctrl_generate_cfg() {
|
||||||
local items
|
local items
|
||||||
local cmd
|
local cmd
|
||||||
@ -211,20 +212,25 @@ zaf_ctrl_generate_cfg() {
|
|||||||
fi
|
fi
|
||||||
cache=$(zaf_ctrl_get_item_option $1 $i "Cache")
|
cache=$(zaf_ctrl_get_item_option $1 $i "Cache")
|
||||||
if [ -n "$cache" ]; then
|
if [ -n "$cache" ]; then
|
||||||
cache="_cache '$cache' "
|
cache="${ZAF_LIB_DIR}/zafcache '$cache' "
|
||||||
fi
|
fi
|
||||||
cmd=$(zaf_ctrl_get_item_option $1 $i "Cmd")
|
cmd=$(zaf_ctrl_get_item_option $1 $i "Cmd")
|
||||||
|
if [ -z "$cache" ] && [ -z "$lock" ]; then
|
||||||
|
preload="${ZAF_LIB_DIR}/preload.sh "
|
||||||
|
else
|
||||||
|
preload=""
|
||||||
|
fi
|
||||||
if [ -n "$cmd" ]; then
|
if [ -n "$cmd" ]; then
|
||||||
$(which echo) "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $cache $lock$cmd";
|
printf "%s" "UserParameter=$ikey,${preload}${cache}${lock}${cmd}"; echo
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
cmd=$(zaf_ctrl_get_item_option $1 $i "Script")
|
cmd=$(zaf_ctrl_get_item_option $1 $i "Script")
|
||||||
if [ -n "$cmd" ]; then
|
if [ -n "$cmd" ]; then
|
||||||
zaf_ctrl_get_item_option $1 $i "Script" | \
|
zaf_ctrl_get_item_option $1 $i "Script" | \
|
||||||
zaf_far '{INCLUDES}' '. /etc/zaf.conf; . ${ZAF_LIB_DIR}/zaf.lib.sh; . ${ZAF_LIB_DIR}/ctrl.lib.sh; . ${ZAF_LIB_DIR}/zbxapi.lib.sh; . ${ZAF_LIB_DIR}/cache.lib.sh; ' \
|
zaf_far '{INCLUDES}' ". $ZAF_LIB_DIR/preload.sh; " \
|
||||||
>${ZAF_TMP_DIR}/${iscript}.sh;
|
>${ZAF_TMP_DIR}/${iscript}.sh;
|
||||||
zaf_install_bin ${ZAF_TMP_DIR}/${iscript}.sh ${ZAF_PLUGINS_DIR}/$2/
|
[ -z "$3" ] && zaf_install_bin ${ZAF_TMP_DIR}/${iscript}.sh ${ZAF_PLUGINS_DIR}/$2/
|
||||||
$(which echo) "UserParameter=$ikey,$cache $lock${ZAF_PLUGINS_DIR}/$2/${iscript}.sh $args";
|
printf "%s" "UserParameter=$ikey,${preload}${cache}${lock}${ZAF_PLUGINS_DIR}/$2/${iscript}.sh $args"; echo
|
||||||
continue;
|
continue;
|
||||||
fi
|
fi
|
||||||
zaf_err "Item $i declared in control file but has no Cmd, Function or Script!"
|
zaf_err "Item $i declared in control file but has no Cmd, Function or Script!"
|
||||||
|
@ -19,19 +19,10 @@ trap "rm -rif ${ZAF_TMP_DIR}" EXIT
|
|||||||
|
|
||||||
export ZAF_LIB_DIR
|
export ZAF_LIB_DIR
|
||||||
export ZAF_TMP_DIR
|
export ZAF_TMP_DIR
|
||||||
|
export ZAF_CACHE_DIR
|
||||||
export ZAF_PLUGINS_DIR
|
export ZAF_PLUGINS_DIR
|
||||||
|
|
||||||
if [ "$1" = "_cache" ] || [ "$1" = "_nocache" ] ; then
|
|
||||||
[ "$1" = "_nocache" ] && export ZAF_NOCACHE=1
|
|
||||||
shift
|
|
||||||
seconds=$1
|
|
||||||
shift
|
|
||||||
parms=$(echo $*|tr -d ' ')
|
|
||||||
if ! zaf_fromcache $parms; then
|
|
||||||
([ "$(basename $0)" = "preload.sh" ] && [ -n "$*" ] && $@ ) | zaf_tocache_stdin $parms $seconds
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[ "$(basename $0)" = "preload.sh" ] && [ -n "$*" ] && $@
|
[ "$(basename $0)" = "preload.sh" ] && [ -n "$*" ] && $@
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -412,7 +412,8 @@ zaf_list_items() {
|
|||||||
|
|
||||||
zaf_get_item() {
|
zaf_get_item() {
|
||||||
if which zabbix_get >/dev/null; then
|
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."
|
zaf_dbg zabbix_get -s localhost -k "'$1'"
|
||||||
|
(zabbix_get -s localhost -k "$1" | tr '\n' ' '; echo) || zaf_wrn "Cannot reach agent on localhost. Please localhost to Server list."
|
||||||
return 11
|
return 11
|
||||||
else
|
else
|
||||||
zaf_wrn "Please install zabbix_get binary to check items over network."
|
zaf_wrn "Please install zabbix_get binary to check items over network."
|
||||||
@ -421,7 +422,12 @@ zaf_get_item() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
zaf_test_item() {
|
zaf_test_item() {
|
||||||
$ZAF_AGENT_BIN -t "$1"
|
if $ZAF_AGENT_BIN -t "$1" | grep ZBX_NOTSUPPORTED; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
$ZAF_AGENT_BIN -t "$1" | tr '\n' ' '
|
||||||
|
echo
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
zaf_precache_item() {
|
zaf_precache_item() {
|
||||||
|
17
lib/zafcache
Normal file
17
lib/zafcache
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. $(dirname $0)/preload.sh
|
||||||
|
|
||||||
|
help() {
|
||||||
|
zaf_err "$0 seconds cmd..."
|
||||||
|
}
|
||||||
|
|
||||||
|
seconds=$1
|
||||||
|
shift
|
||||||
|
[ -z "$*" ] && help
|
||||||
|
|
||||||
|
parms=$(echo $*|tr -d ' ')
|
||||||
|
if ! zaf_fromcache "$parms"; then
|
||||||
|
$@ | zaf_tocache_stdin "$parms" "$seconds"
|
||||||
|
fi
|
||||||
|
|
@ -1,12 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
. /etc/zaf.conf
|
. $(dirname $0)/preload.sh
|
||||||
|
|
||||||
. ${ZAF_LIB_DIR}/zaf.lib.sh
|
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
echo "$0 key cmd"
|
zaf_err "$0 key cmd"
|
||||||
exit 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lkey="$1"
|
lkey="$1"
|
||||||
|
2
zaf
2
zaf
@ -77,7 +77,7 @@ userparms)
|
|||||||
for plugin in $(zaf_list_plugins); do
|
for plugin in $(zaf_list_plugins); do
|
||||||
plugindir=$ZAF_PLUGINS_DIR/$plugin
|
plugindir=$ZAF_PLUGINS_DIR/$plugin
|
||||||
control=$plugindir/control.zaf
|
control=$plugindir/control.zaf
|
||||||
zaf_ctrl_generate_cfg "${control}" "${plugin}" \
|
zaf_ctrl_generate_cfg "${control}" "${plugin}" "noscripts" \
|
||||||
| zaf_far '{PLUGINDIR}' "${plugindir}"
|
| zaf_far '{PLUGINDIR}' "${plugindir}"
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user