From ed5e0501b888ffaf71fa6792439a2d2f7bfb5950 Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Thu, 14 Apr 2016 10:39:33 +0200 Subject: [PATCH 1/2] Released version 1.1 --- README.md | 14 +++++++------- install.sh | 2 +- lib/ctrl.lib.sh | 18 +++++++++++------- lib/zaf.lib.sh | 8 +++++++- zaf | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e9a366b..a6aad8c 100644 --- a/README.md +++ b/README.md @@ -25,18 +25,18 @@ So zaf is here for you :) ## Installing Zaf You need to be root and you must have curl installed on your system. Depending on your system, github certificates may not be available so you have to use *-k* option for curl (insecure). Default installation type is silent. So there will be no questions and everything will be autodetected. This simple command should be used on most systems: ``` -curl -k https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sh +curl -k https://raw.githubusercontent.com/limosek/zaf/1.1/install.sh | sh ``` ### Install options and autoconfiguration General parameters for install.sh on any system (simplest way how to install) ``` -curl -k https://raw.githubusercontent.com/limosek/zaf/master/install.sh | \ +curl -k https://raw.githubusercontent.com/limosek/zaf/1.1/install.sh | \ sh -s {auto|interactive|debug-auto|debug-interactive} [Agent-Options] [Zaf-Options] ``` or use git version: ``` -git clone https://github.com/limosek/zaf.git; cd zaf; git checkout master +git clone https://github.com/limosek/zaf.git; cd zaf; git checkout 1.1 ./install.sh {auto|interactive|debug-auto|debug-interactive} [Agent-Options] [Zaf-Options] Agent-Options: Z_Option=value [...] Zaf-Options: ZAF_OPT=value [...] @@ -67,7 +67,7 @@ Now everything was tested on Debian and OpenWrt. If somebody is interrested in, Suppose you want to autoinstall agent on clean system. You need only curl installed. Everything else is one-cmd process. This command will install zaf, install zabbix-agent if necessary and sets zabbix variables on agent to reach server. This command can be automatized by puppet or another deploying system. ``` -curl -k https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sh -s auto \ +curl -k https://raw.githubusercontent.com/limosek/zaf/1.1/install.sh | sh -s auto \ Z_Server=zabbix.server.local \ Z_ServerActive=zabbix.server.local \ Z_HostnameItem=system.hostname Z_RefreshActiveChecks=60 \ @@ -79,10 +79,10 @@ You can make your own deb package with preconfigured option. It is up to you to ``` git clone https://github.com/limosek/zaf.git \ && cd zaf \ - && git checkout master \ + && git checkout 1.1 \ && git clone https://github.com/limosek/zaf-plugins.git \ && make deb PLUGINS="./zaf-plugins/fsx" IPLUGINS="zaf" ZAF_OPTIONS="ZAF_GIT=0" AGENT_OPTIONS="Z_Server=zabbix.server Z_ServerActive=zabbix.server Z_StartAgents=8" -sudo dpkg -i out/zaf-1.1master.deb +sudo dpkg -i out/zaf-1.1.deb ``` General usage: ``` @@ -124,7 +124,7 @@ During plugin installation, zaf will check all dependencies, do install binaries Zaf binary can be installed on any system from openwrt to big system. It has minimal dependencies and is shell based. Is has minimal size (up to 50kb of code). It can be used for installing, removing and testing zaf plugin items. Zaf should be run as root. ``` zaf -zaf Version 1.1master. Please use some of this commands: +zaf Version 1.1. Please use some of this commands: zaf update To update repo zaf plugins To list installed plugins zaf show [plugin] To show installed plugins or plugin info diff --git a/install.sh b/install.sh index 08e207e..6e8473b 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ if [ -z "$ZAF_URL" ]; then ZAF_URL="https://github.com/limosek/zaf/" fi -[ -z "$ZAF_GITBRANCH" ] && ZAF_GITBRANCH=master +[ -z "$ZAF_GITBRANCH" ] && ZAF_GITBRANCH=1.1 # Lite version of zaf_fetch_url, full version will be loaded later zaf_fetch_url(){ diff --git a/lib/ctrl.lib.sh b/lib/ctrl.lib.sh index 975f6e4..e5ee3f6 100644 --- a/lib/ctrl.lib.sh +++ b/lib/ctrl.lib.sh @@ -55,11 +55,13 @@ zaf_block_get_option() { # $1 - control file # $2 - option name zaf_ctrl_get_global_option() { + local ctrlvar local ctrlopt - eval ctrlopt=\$ZAF_CTRL_$(echo $2| tr '-' '_') - if [ -n "$ctrlopt" ]; then - zaf_wrn "Overriding $2 from env" + ctrlopt="ZAF_CTRL_$(zaf_stripctrl $2)" + eval ctrlvar=\$$ctrlopt + if [ -n "$ctrlvar" ]; then + zaf_dbg "Overriding control field $2 from env $ctrlopt($ctrlvar)" echo $ctrlopt else zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "$2" \ @@ -71,11 +73,13 @@ zaf_ctrl_get_global_option() { # $2 - item name # $3 - option name zaf_ctrl_get_item_option() { + local ctrlvar local ctrlopt - eval ctrlopt=\$ZAF_CTRL_$2_$(echo $3| tr '-' '_') - if [ -n "$ctrlopt" ]; then - zaf_wrn "Overriding item $2 option $3 from env" + ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)" + eval ctrlvar=\$$ctrlopt + if [ -n "$ctrlvar" ]; then + zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)" echo $ctrlopt else zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_moption "$3" \ @@ -188,7 +192,7 @@ zaf_ctrl_generate_cfg() { items=$(zaf_ctrl_get_items <"$1") (set -e for i in $items; do - iscript=$(echo $i | tr -d '[]*&;:') + iscript=$(zaf_stripctrl $i) params=$(zaf_ctrl_get_item_option $1 $i "Parameters") if [ -n "$params" ]; then ikey="$2.$i[*]" diff --git a/lib/zaf.lib.sh b/lib/zaf.lib.sh index db71851..843e4cc 100644 --- a/lib/zaf.lib.sh +++ b/lib/zaf.lib.sh @@ -1,7 +1,7 @@ # Hardcoded variables ZAF_VERSION="1.1" -ZAF_GITBRANCH="master" +ZAF_GITBRANCH="1.1" ZAF_URL="https://github.com/limosek/zaf" ZAF_RAW_URL="https://raw.githubusercontent.com/limosek/zaf" @@ -426,3 +426,9 @@ zaf_toupper() { tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' } +# Return simplified key with discarded special chars. +zaf_stripctrl() { + echo $1 | tr '[]*&;:.-' '________' +} + + diff --git a/zaf b/zaf index 9388cbd..d03009c 100755 --- a/zaf +++ b/zaf @@ -312,7 +312,7 @@ api) *) echo "$0 Version ${ZAF_VERSION}. Please use some of this commands:" - echo "$0 Cmd [ZAF_OPTION=value] [ZAF_CTRL_Option=value] ..." + echo "$0 Cmd [ZAF_OPTION=value] [ZAF_CTRL_Option=value] [ZAF_CTRLI_Item_Option=value] ..." echo "Commands:" echo "$0 update To update repo (not plugins, similar to apt-get update)" echo "$0 upgrade To upgrade installed plugins from repo" From c830d0e6a0d5f8f5fcfa9e38ad1179bb835bcd66 Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Fri, 15 Apr 2016 08:51:50 +0200 Subject: [PATCH 2/2] Repaired bug in install, version info --- install.sh | 2 +- lib/zaf.lib.sh | 10 +++++++--- lib/zbxapi.lib.sh | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 6e8473b..7978eb5 100755 --- a/install.sh +++ b/install.sh @@ -179,7 +179,7 @@ zaf_configure_agent() { else zaf_unset_agent_option "$option" fi - options="$options Z_$option='$value'" + options="$options Z_$option=$value" done zaf_set_option ZAF_AGENT_OPTIONS "${options}" } diff --git a/lib/zaf.lib.sh b/lib/zaf.lib.sh index 843e4cc..61fbe36 100644 --- a/lib/zaf.lib.sh +++ b/lib/zaf.lib.sh @@ -267,13 +267,17 @@ zaf_install_plugin() { local plugin local plugindir local control + local version if zaf_prepare_plugin "$1" "${ZAF_TMP_DIR}/plugin"; then url=$(zaf_get_plugin_url "$1") - plugin=$(zaf_ctrl_get_global_block <"${ZAF_TMP_DIR}/plugin/control.zaf" | zaf_block_get_option Plugin) + control="${ZAF_TMP_DIR}/plugin/control.zaf" + plugin=$(zaf_ctrl_get_global_option $control Plugin) + version=$(zaf_ctrl_get_global_option $control Version) plugindir="${ZAF_PLUGINS_DIR}"/$plugin if [ -n "$plugin" ] && zaf_prepare_plugin "$1" $plugindir; then - zaf_wrn "Installing plugin $plugin from $url to $plugindir" + zaf_wrn "Installing plugin $plugin version $version" + zaf_dbg "Source url: $url, Destination dir: $plugindir" control=${plugindir}/control.zaf [ "$ZAF_DEBUG" -gt 1 ] && zaf_plugin_info "${control}" zaf_ctrl_check_deps "${control}" @@ -413,7 +417,7 @@ zaf_precache_item() { zaf_remove_plugin() { ! zaf_is_plugin $1 && { zaf_err "Plugin $1 not installed!"; } - zaf_wrn "Removing plugin $1" + zaf_wrn "Removing plugin $1 (version $(zaf_plugin_version $1))" rm -rf ${ZAF_PLUGINS_DIR}/$1 rm -f ${ZAF_AGENT_CONFIGD}/zaf_$1.conf ${ZAF_CROND}/zaf_$1 ${ZAF_SUDOERSD}/zaf_$1 } diff --git a/lib/zbxapi.lib.sh b/lib/zbxapi.lib.sh index 24a6b5e..5cfa897 100644 --- a/lib/zbxapi.lib.sh +++ b/lib/zbxapi.lib.sh @@ -44,7 +44,7 @@ zaf_zbxapi_login(){ local pass local result - [ -z "$ZAF_ZBXAPI_URL" ] || [ -z "$ZAF_ZBXAPI_USER" ] || [ -z "$ZAF_ZBXAPI_PASS" ] && zaf_err "Zabbix Api parameters not set!" + [ -z "$ZAF_ZBXAPI_URL" ] || [ -z "$ZAF_ZBXAPI_USER" ] || [ -z "$ZAF_ZBXAPI_PASS" ] && zaf_err "Zabbix Api parameters not set! Set ZAF_ZBXAPI_URL, ZAF_ZBXAPI_USER and ZAF_ZBXAPI_PASS and try again." authstr='{ "method" : "user.login", "params" : {