mirror of
https://github.com/limosek/zaf.git
synced 2024-11-24 11:29:06 +01:00
Repaired caching
Added testparameters and precacheparameters
This commit is contained in:
parent
ce4df86f46
commit
2a0d6848a7
@ -20,13 +20,14 @@ zaf_cache_key(){
|
|||||||
# $2 value
|
# $2 value
|
||||||
# $3 lifetime in seconds
|
# $3 lifetime in seconds
|
||||||
zaf_tocache(){
|
zaf_tocache(){
|
||||||
|
! [ -w $ZAF_CACHE_DIR ] && return 1
|
||||||
local key
|
local key
|
||||||
local value
|
local value
|
||||||
local lifetime
|
|
||||||
key=$(zaf_cache_key "$1")
|
key=$(zaf_cache_key "$1")
|
||||||
echo "$2" >$ZAF_CACHE_DIR/$key
|
echo "$2" >$ZAF_CACHE_DIR/$key
|
||||||
echo "$1" >$ZAF_CACHE_DIR/$key.key
|
echo "$1" >$ZAF_CACHE_DIR/$key.info
|
||||||
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.tme
|
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.info
|
||||||
zaf_trc "Cache: Saving entry $1($key)"
|
zaf_trc "Cache: Saving entry $1($key)"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,14 +35,15 @@ zaf_tocache(){
|
|||||||
# $1 key
|
# $1 key
|
||||||
# $2 lifetime in seconds
|
# $2 lifetime in seconds
|
||||||
zaf_tocache_stdin(){
|
zaf_tocache_stdin(){
|
||||||
|
! [ -w $ZAF_CACHE_DIR ] && return 1
|
||||||
local key
|
local key
|
||||||
local lifetime
|
|
||||||
key=$(zaf_cache_key "$1")
|
key=$(zaf_cache_key "$1")
|
||||||
cat >$ZAF_CACHE_DIR/$key
|
cat >$ZAF_CACHE_DIR/$key
|
||||||
if [ -s $ZAF_CACHE_DIR/$key ]; then
|
if [ -s $ZAF_CACHE_DIR/$key ]; then
|
||||||
zaf_trc "Cache: Saving entry $1($key)"
|
zaf_trc "Cache: Saving entry $1($key)"
|
||||||
echo "$1" >$ZAF_CACHE_DIR/$key.key
|
echo "$1" >$ZAF_CACHE_DIR/$key.info
|
||||||
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.tme
|
touch -m -d "$2 seconds" $ZAF_CACHE_DIR/$key.info
|
||||||
cat $ZAF_CACHE_DIR/$key
|
cat $ZAF_CACHE_DIR/$key
|
||||||
else
|
else
|
||||||
rm $ZAF_CACHE_DIR/$key
|
rm $ZAF_CACHE_DIR/$key
|
||||||
@ -51,6 +53,7 @@ zaf_tocache_stdin(){
|
|||||||
# Remove entry from cache
|
# Remove entry from cache
|
||||||
# $1 key
|
# $1 key
|
||||||
zaf_cache_delentry(){
|
zaf_cache_delentry(){
|
||||||
|
! [ -w $ZAF_CACHE_DIR ] && return 1
|
||||||
local key
|
local key
|
||||||
key=$(zaf_cache_key "$1")
|
key=$(zaf_cache_key "$1")
|
||||||
zaf_trc "Cache: removing $1($key) from cache"
|
zaf_trc "Cache: removing $1($key) from cache"
|
||||||
@ -60,11 +63,12 @@ zaf_cache_delentry(){
|
|||||||
# Get object from cache
|
# Get object from cache
|
||||||
# $1 key
|
# $1 key
|
||||||
zaf_fromcache(){
|
zaf_fromcache(){
|
||||||
|
! [ -r $ZAF_CACHE_DIR ] || [ -n "$ZAF_NOCACHE" ] && return 1
|
||||||
local key
|
local key
|
||||||
local value
|
local value
|
||||||
key=$(zaf_cache_key "$1")
|
key=$(zaf_cache_key "$1")
|
||||||
if [ -f $ZAF_CACHE_DIR/$key ]; then
|
if [ -f $ZAF_CACHE_DIR/$key ]; then
|
||||||
if [ "$ZAF_CACHE_DIR/$key.tme" -nt "$ZAF_CACHE_DIR/$key" ]; then
|
if [ "$ZAF_CACHE_DIR/$key.info" -nt "$ZAF_CACHE_DIR/$key" ]; then
|
||||||
zaf_trc "Cache: serving $1($key) from cache"
|
zaf_trc "Cache: serving $1($key) from cache"
|
||||||
cat $ZAF_CACHE_DIR/$key
|
cat $ZAF_CACHE_DIR/$key
|
||||||
else
|
else
|
||||||
|
@ -21,7 +21,8 @@ export ZAF_LIB_DIR
|
|||||||
export ZAF_TMP_DIR
|
export ZAF_TMP_DIR
|
||||||
export ZAF_PLUGINS_DIR
|
export ZAF_PLUGINS_DIR
|
||||||
|
|
||||||
if [ "$1" = "_cache" ]; then
|
if [ "$1" = "_cache" ] || [ "$1" = "_nocache" ] ; then
|
||||||
|
[ "$1" = "_nocache" ] && export ZAF_NOCACHE=1
|
||||||
shift
|
shift
|
||||||
seconds=$1
|
seconds=$1
|
||||||
shift
|
shift
|
||||||
|
@ -232,7 +232,13 @@ zaf_plugin_info() {
|
|||||||
[ -n "$purl" ] && echo "Url: $purl"
|
[ -n "$purl" ] && echo "Url: $purl"
|
||||||
[ -n "$phome" ] && echo "Home: $phome"
|
[ -n "$phome" ] && echo "Home: $phome"
|
||||||
echo
|
echo
|
||||||
|
if zaf_is_plugin "$(basename $plugin)"; then
|
||||||
|
echo -n "Defined items: "; zaf_list_plugin_items $plugin
|
||||||
|
echo -n "Test items: "; zaf_list_plugin_items $plugin test
|
||||||
|
echo -n "Precache items: "; zaf_list_plugin_items $plugin precache
|
||||||
|
else
|
||||||
echo "Items: $pitems"
|
echo "Items: $pitems"
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,11 +344,15 @@ zaf_plugin_template_url() {
|
|||||||
echo $(zaf_plugin_option "$1" Url)/template.xml
|
echo $(zaf_plugin_option "$1" Url)/template.xml
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# $1 plugin
|
||||||
|
# $2 test to get test items, precache to get items to precache
|
||||||
zaf_list_plugin_items() {
|
zaf_list_plugin_items() {
|
||||||
local items
|
local items
|
||||||
local i
|
local i
|
||||||
local p
|
local p
|
||||||
local key
|
local key
|
||||||
|
local testparms
|
||||||
|
local precache
|
||||||
|
|
||||||
if ! zaf_is_plugin "$1"; then
|
if ! zaf_is_plugin "$1"; then
|
||||||
zaf_err "Missing plugin name or plugin $1 unknown. ";
|
zaf_err "Missing plugin name or plugin $1 unknown. ";
|
||||||
@ -352,12 +362,25 @@ zaf_list_plugin_items() {
|
|||||||
items=$(zaf_ctrl_get_items <$cfile)
|
items=$(zaf_ctrl_get_items <$cfile)
|
||||||
for i in $items; do
|
for i in $items; do
|
||||||
p=$(zaf_ctrl_get_item_option $cfile $i "Parameters")
|
p=$(zaf_ctrl_get_item_option $cfile $i "Parameters")
|
||||||
|
testparms=$(zaf_ctrl_get_item_option $cfile $i "Testparameters")
|
||||||
|
precache=$(zaf_ctrl_get_item_option $cfile $i "Precache")
|
||||||
if [ -n "$p" ]; then
|
if [ -n "$p" ]; then
|
||||||
key="$1.$i[]"
|
if [ -n "$testparms" ] && [ "$2" = "test" ]; then
|
||||||
|
for tp in $testparms; do
|
||||||
|
echo -n "$1.$i[$tp] "
|
||||||
|
done
|
||||||
|
else
|
||||||
|
if [ -n "$precache" ] && [ "$2" = "precache" ]; then
|
||||||
|
for tp in $precache; do
|
||||||
|
echo -n "$1.$i[$tp] "
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
[ "$2" != "test" ] && key="$1.$i[]"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
key="$1.$i"
|
key="$1.$i"
|
||||||
fi
|
fi
|
||||||
echo -n "$key "
|
[ "$2" != "precache" ] && echo -n "$key "
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
@ -379,12 +402,12 @@ zaf_get_item() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
zaf_test_item() {
|
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"
|
$ZAF_AGENT_BIN -t "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
zaf_precache_item() {
|
zaf_precache_item() {
|
||||||
cmd=$(grep "^UserParameter=$item" $ZAF_AGENT_CONFIGD/zaf*.conf | cut -d ',' -f 2-)
|
cmd=$(grep "^UserParameter=$item" $ZAF_AGENT_CONFIGD/zaf*.conf | cut -d ',' -f 2- | sed -e "s/_cache/_nocache/")
|
||||||
|
zaf_wrn "Precaching item $item[$(echo $*| tr ' ' ',')] ($cmd)"
|
||||||
eval $cmd
|
eval $cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
zaf
22
zaf
@ -144,6 +144,7 @@ items)
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
test)
|
test)
|
||||||
|
[ "$USER" != "zabbix" ] && zaf_wrn "You are not zabbix user. Test will be run with your privileges and sudo access!"
|
||||||
shift
|
shift
|
||||||
shift $(zaf_shift "$@")
|
shift $(zaf_shift "$@")
|
||||||
if echo $1|grep -q '\.'; then
|
if echo $1|grep -q '\.'; then
|
||||||
@ -157,8 +158,9 @@ test)
|
|||||||
fi
|
fi
|
||||||
for p in $plugins; do
|
for p in $plugins; do
|
||||||
! zaf_is_plugin $p && zaf_err "Unknown plugin $p"
|
! zaf_is_plugin $p && zaf_err "Unknown plugin $p"
|
||||||
for i in $(zaf_list_plugin_items $p); do
|
for i in $(zaf_list_plugin_items $p test); do
|
||||||
echo $i: $(zaf_test_item $i)
|
echo $i: $(zaf_test_item $i)
|
||||||
|
echo
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
@ -175,8 +177,9 @@ get)
|
|||||||
plugins="$(zaf_list_plugins)"
|
plugins="$(zaf_list_plugins)"
|
||||||
fi
|
fi
|
||||||
for p in $plugins; do
|
for p in $plugins; do
|
||||||
for i in $(zaf_list_plugin_items $p); do
|
for i in $(zaf_list_plugin_items $p test); do
|
||||||
echo $i: $(zaf_get_item $i)
|
echo $i: $(zaf_get_item $i)
|
||||||
|
echo
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
@ -185,9 +188,17 @@ precache)
|
|||||||
shift
|
shift
|
||||||
shift $(zaf_shift "$@")
|
shift $(zaf_shift "$@")
|
||||||
for i in $*; do
|
for i in $*; do
|
||||||
|
if zaf_is_plugin $i; then
|
||||||
|
for j in $(zaf_list_plugin_items $i precache); do
|
||||||
|
item=$(echo $j | cut -d '[' -f 1)
|
||||||
|
params=$(echo $j | cut -d '[' -f 2 | cut -d ']' -f 1 | tr ',' ' ')
|
||||||
|
zaf_precache_item $params >/dev/null
|
||||||
|
done
|
||||||
|
else
|
||||||
item=$(echo $i | cut -d '[' -f 1)
|
item=$(echo $i | cut -d '[' -f 1)
|
||||||
params=$(echo $i | cut -d '[' -f 2 | cut -d ']' -f 1 | tr ',' ' ')
|
params=$(echo $i | cut -d '[' -f 2 | cut -d ']' -f 1 | tr ',' ' ')
|
||||||
zaf_precache_item $params
|
zaf_precache_item $params >/dev/null
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@ -196,8 +207,8 @@ install)
|
|||||||
shift $(zaf_shift "$@")
|
shift $(zaf_shift "$@")
|
||||||
[ -z "$1" ] && echo "$0 install plugin [plugin]..."
|
[ -z "$1" ] && echo "$0 install plugin [plugin]..."
|
||||||
for p in $@; do
|
for p in $@; do
|
||||||
if zaf_is_plugin "$p"; then
|
if zaf_is_plugin "$(basename $p)"; then
|
||||||
zaf_wrn "Plugin $p already installed. Skipping installation."
|
zaf_wrn "Plugin $(basename $p) already installed. Skipping installation."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
zaf_install_plugin "$p"
|
zaf_install_plugin "$p"
|
||||||
@ -334,6 +345,7 @@ api)
|
|||||||
echo "$0 items [plugin] To list all suported items [for plugin]"
|
echo "$0 items [plugin] To list all suported items [for plugin]"
|
||||||
echo "$0 test [plugin[.item]] To test [all] suported items by zabbix_agentd [for plugin]"
|
echo "$0 test [plugin[.item]] To test [all] suported items by zabbix_agentd [for plugin]"
|
||||||
echo "$0 get [plugin[.item]] To test [all] suported items by zabbix_get [for plugin]"
|
echo "$0 get [plugin[.item]] To test [all] suported items by zabbix_get [for plugin]"
|
||||||
|
echo "$0 precache [plugin[.item]] To precache [all] suported items"
|
||||||
echo "$0 install plugin To install plugin"
|
echo "$0 install plugin To install plugin"
|
||||||
echo "$0 remove plugin To remove plugin"
|
echo "$0 remove plugin To remove plugin"
|
||||||
echo "$0 api To zabbix API functions. See $0 api for more info."
|
echo "$0 api To zabbix API functions. See $0 api for more info."
|
||||||
|
Loading…
Reference in New Issue
Block a user