mirror of
https://github.com/limosek/zaf.git
synced 2024-11-21 18:09:06 +01:00
Added cron support
Added precache support
This commit is contained in:
parent
cf90b8bc2c
commit
a99c9b8280
@ -226,6 +226,7 @@ zaf_configure(){
|
||||
zaf_get_option ZAF_AGENT_BIN "Zabbix agent binary" "/usr/sbin/zabbix_agentd" "$INSTALL_MODE"
|
||||
zaf_get_option ZAF_AGENT_RESTART "Zabbix agent restart cmd" "service zabbix-agent restart" "$INSTALL_MODE"
|
||||
zaf_get_option ZAF_SUDOERSD "Sudo sudoers.d directory" "/etc/sudoers.d" "$INSTALL_MODE"
|
||||
zaf_get_option ZAF_CROND "Cron.d directory" "/etc/cron.d" "$INSTALL_MODE"
|
||||
zaf_get_option ZAF_ZBXAPI_URL "Zabbix API url" "http://localhost/zabbix/api_jsonrpc.php" "$INSTALL_MODE"
|
||||
zaf_get_option ZAF_ZBXAPI_USER "Zabbix API user" "zaf" "$INSTALL_MODE"
|
||||
zaf_get_option ZAF_ZBXAPI_PASS "Zabbix API password" "" "$INSTALL_MODE"
|
||||
@ -258,6 +259,7 @@ zaf_configure(){
|
||||
zaf_set_option ZAF_AGENT_BIN "$ZAF_AGENT_BIN"
|
||||
zaf_set_option ZAF_AGENT_RESTART "$ZAF_AGENT_RESTART"
|
||||
zaf_set_option ZAF_SUDOERSD "$ZAF_SUDOERSD"
|
||||
zaf_set_option ZAF_CROND "$ZAF_CROND"
|
||||
zaf_set_option ZAF_ZBXAPI_URL "$ZAF_ZBXAPI_URL"
|
||||
zaf_set_option ZAF_ZBXAPI_USER "$ZAF_ZBXAPI_USER"
|
||||
zaf_set_option ZAF_ZBXAPI_PASS "$ZAF_ZBXAPI_PASS"
|
||||
|
@ -25,6 +25,7 @@ zaf_tocache(){
|
||||
local lifetime
|
||||
key=$(zaf_cachekey $1)
|
||||
echo "$2" >$ZAF_CACHE_DIR/$key
|
||||
echo "$1" >$ZAF_CACHE_DIR/$key.key
|
||||
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.tme
|
||||
zaf_trc "Cache: Saving entry $1($key)"
|
||||
}
|
||||
@ -38,6 +39,7 @@ zaf_tocache_stdin(){
|
||||
|
||||
key=$(zaf_cachekey $1)
|
||||
cat >$ZAF_CACHE_DIR/$key
|
||||
echo "$1" >$ZAF_CACHE_DIR/$key.key
|
||||
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.tme
|
||||
zaf_trc "Cache: Saving entry $1($key)"
|
||||
cat $ZAF_CACHE_DIR/$key
|
||||
|
@ -95,11 +95,26 @@ zaf_ctrl_sudo() {
|
||||
fi
|
||||
pdir="$3"
|
||||
plugin=$1
|
||||
(echo -n "zabbix ALL=NOPASSWD: "
|
||||
zaf_dbg "Installing sudoers entry $ZAF_SUDOERSD/zaf_$plugin"
|
||||
(echo -n "zabbix ALL=NOPASSWD:SETENV: "
|
||||
zaf_ctrl_get_global_option $2 "Sudo" | zaf_far '{PLUGINDIR}' "${plugindir}";
|
||||
echo ) >$ZAF_SUDOERSD/zaf_$plugin
|
||||
}
|
||||
|
||||
# Install crontab config from control
|
||||
# $1 plugin
|
||||
# $2 control
|
||||
# $3 plugindir
|
||||
zaf_ctrl_cron() {
|
||||
local pdir
|
||||
local plugin
|
||||
|
||||
pdir="$3"
|
||||
plugin=$1
|
||||
zaf_dbg "Installing cron entry $ZAF_CROND/zaf_$plugin"
|
||||
zaf_ctrl_get_global_option $2 "Cron" | zaf_far '{PLUGINDIR}' "${plugindir}" >$ZAF_CROND/zaf_$plugin
|
||||
}
|
||||
|
||||
# Install sudo options from control
|
||||
# $1 pluginurl
|
||||
# $2 control
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
|
||||
ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}"
|
||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}-${USER}c
|
||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}c
|
||||
|
||||
#trap "rm -rif ${ZAF_TMP_DIR}" EXIT
|
||||
trap "rm -rif ${ZAF_TMP_DIR}" EXIT
|
||||
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
|
||||
! [ -d "${ZAF_CACHE_DIR}" ] && mkdir "${ZAF_CACHE_DIR}"
|
||||
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
|
||||
|
@ -382,6 +382,11 @@ zaf_test_item() {
|
||||
$ZAF_AGENT_BIN -t "$1"
|
||||
}
|
||||
|
||||
zaf_precache_item() {
|
||||
cmd=$(grep "^UserParameter=$item" $ZAF_AGENT_CONFIGD/zaf*.conf | cut -d ',' -f 2-)
|
||||
eval $cmd
|
||||
}
|
||||
|
||||
zaf_remove_plugin() {
|
||||
! [ -d ${ZAF_PLUGINS_DIR}/$1 ] && { zaf_err "Plugin $1 not installed!"; }
|
||||
zaf_wrn "Removing plugin $1"
|
||||
|
22
zaf
22
zaf
@ -18,7 +18,7 @@ done
|
||||
|
||||
[ -z "$ZAF_TMP_BASE" ] && ZAF_TMP_BASE=/tmp/zaf
|
||||
ZAF_TMP_DIR="${ZAF_TMP_BASE}-${USER}"
|
||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}-${USER}c
|
||||
[ -z "$ZAF_CACHE_DIR" ] && ZAF_CACHE_DIR=${ZAF_TMP_BASE}c
|
||||
|
||||
[ -z "$ZAF_DEBUG" ] && ZAF_DEBUG=1
|
||||
export ZAF_DEBUG
|
||||
@ -29,7 +29,9 @@ if [ "$ZAF_DEBUG" -le 3 ]; then
|
||||
fi
|
||||
|
||||
! [ -d "${ZAF_TMP_DIR}" ] && mkdir "${ZAF_TMP_DIR}"
|
||||
! [ -d "${ZAF_CACHE_DIR}" ] && mkdir "${ZAF_CACHE_DIR}"
|
||||
if ! [ -d "${ZAF_CACHE_DIR}" ]; then
|
||||
mkdir "${ZAF_CACHE_DIR}"
|
||||
fi
|
||||
|
||||
if [ -f ./lib/zaf.lib.sh ]; then
|
||||
. ./lib/zaf.lib.sh
|
||||
@ -47,6 +49,11 @@ else
|
||||
[ -f ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh ] && . ${ZAF_LIB_DIR}/zaf.${ZAF_OS}.sh
|
||||
fi
|
||||
|
||||
if zaf_is_root; then
|
||||
chgrp zabbix "${ZAF_CACHE_DIR}"
|
||||
chmod g+w "${ZAF_CACHE_DIR}"
|
||||
fi
|
||||
|
||||
zaf_shift(){
|
||||
local s
|
||||
|
||||
@ -173,6 +180,17 @@ get)
|
||||
done
|
||||
done
|
||||
;;
|
||||
|
||||
precache)
|
||||
shift
|
||||
shift $(zaf_shift "$@")
|
||||
for i in $*; do
|
||||
item=$(echo $i | cut -d '[' -f 1)
|
||||
params=$(echo $i | cut -d '[' -f 2 | cut -d ']' -f 1 | tr ',' ' ')
|
||||
zaf_precache_item $params
|
||||
done
|
||||
;;
|
||||
|
||||
install)
|
||||
shift
|
||||
shift $(zaf_shift "$@")
|
||||
|
Loading…
Reference in New Issue
Block a user