From 60009d71e6a36696aa3834f77947d9ad6fe231ad Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Fri, 15 Apr 2016 11:15:43 +0200 Subject: [PATCH] Updated cfg creation process --- README.md | 14 ++++++++++++++ lib/ctrl.lib.sh | 11 ++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index da1b58b..2ebffb5 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,20 @@ Commands: ./zaf cache-clean To remove all entries from cache ``` +Zaf can even communicate with zabbix server using its API. If you set ZAF_ZBXAPI_URL, ZAF_ZBXAPI_USER and ZAF_ZBXAPI_PASS in /etc/zaf.conf, you can use it: +``` +./zaf api command [parameters] +hostid 'host' Get hostid from hostname +host 'hostid' Get hostname from hostid +hostgroupid 'hostgroup' Get hostgroup id from hostgroup +hosts 'hostgroup' Get hosts in group +export-hosts dir [hostgroup] Backup all hosts [in group] (get their config from zabbix and save to dir/hostname.xml) +export-host 'host' Backup host (get config from zabbix to stdout) +import-template {plugin|file} Import template for plugin or from file +export-template 'name' Export template to stdout +export-templates dir Export all template to dir +``` + ### Installing plugin To install plugin from common repository. If git is available, local git repo is tried first. If not, remote https repo is tried second. ``` diff --git a/lib/ctrl.lib.sh b/lib/ctrl.lib.sh index 3c67cf7..8386ba6 100644 --- a/lib/ctrl.lib.sh +++ b/lib/ctrl.lib.sh @@ -218,16 +218,13 @@ zaf_ctrl_generate_cfg() { $(which echo) "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $cache $lock$cmd"; continue fi - cmd=$(zaf_ctrl_get_item_option $1 $i "Function") - if [ -n "$cmd" ]; then - $(which echo) "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $cache $lock$cmd"; - continue; - fi cmd=$(zaf_ctrl_get_item_option $1 $i "Script") if [ -n "$cmd" ]; then - zaf_ctrl_get_item_option $1 $i "Script" >${ZAF_TMP_DIR}/${iscript}.sh; + 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_TMP_DIR}/${iscript}.sh; zaf_install_bin ${ZAF_TMP_DIR}/${iscript}.sh ${ZAF_PLUGINS_DIR}/$2/ - $(which echo) "UserParameter=$ikey,${ZAF_LIB_DIR}/preload.sh $cache $lock${ZAF_PLUGINS_DIR}/$2/${iscript}.sh $args"; + $(which echo) "UserParameter=$ikey,$cache $lock${ZAF_PLUGINS_DIR}/$2/${iscript}.sh $args"; continue; fi zaf_err "Item $i declared in control file but has no Cmd, Function or Script!"