From 8b81fea72c1aeb5d039819a71295749ee7f803e9 Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Wed, 15 Feb 2017 15:35:16 +0100 Subject: [PATCH] Repaired send operation --- README.md | 34 ++++++++++++++++++++++++++++++++-- lib/zaf.lib.sh | 4 ++-- zaf | 14 ++++++++++---- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6b9f582..2e1267d 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,9 @@ Zaf related commands: ``` -### Installing plugin +### Plugin operations + +#### 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. ``` zaf install zaf @@ -237,7 +239,7 @@ zaf install /some/plugin ``` Installer will look into control file, run setup task defined there, fetch binaries and scripts needed for specific plugin and test system dependencies for that plugin. If everything is OK, zaf_plugin.conf is created in zabbix_agentd.d conf directory and userparameters are automaticaly added. -### Plugin parameters +#### Plugin parameters Plugin can have some global parameters. For example url of local server to check. See booked plugin. In that case, you have to specify parameters before use. To set parameters by environment: ``` @@ -254,5 +256,33 @@ zaf itemsh booked.num_reservations ``` Interactive shell will be spawn and you can test your commands or scripts in same way how zabbix agent would do it. Use exit command or ctrl-D to get back. +#### Run plugin subcommand +If plugin is capable of runing subcommand (for example csv plugin), it can be called directly +``` +zaf csv send +``` + +### Agent tests + +#### To test result of item (using zabbix_agent -t) + +``` +zaf test plugin.item[parameters] +``` + +#### To test result of item (using zabbix_get) + +``` +zaf test plugin.item[parameters] +``` + +#### To get result of item directly to stdout + +``` +zaf run plugin.item[parameters] +``` + + + diff --git a/lib/zaf.lib.sh b/lib/zaf.lib.sh index 4e92a67..8b1e493 100644 --- a/lib/zaf.lib.sh +++ b/lib/zaf.lib.sh @@ -24,8 +24,8 @@ zaf_wrn() { } zaf_err() { logger ${ZAF_LOG_STDERR} -p user.err -t zaf-error -- $@ - logger ${ZAF_LOG_STDERR} -p user.err -t zaf-error "Exiting with error!" - exit 1 + logger ${ZAF_LOG_STDERR} -p user.err -t zaf-error "Exiting with error!" + exit 1 } # Help option # $1 - key diff --git a/zaf b/zaf index 02a860b..89297fc 100755 --- a/zaf +++ b/zaf @@ -224,21 +224,28 @@ get) send) shift if [ -z "$1" ]; then + # No parameters - pipe to zabbix_sender zaf_dbg "Waiting for data on stdin (host item value) per line" zscmd="zabbix_sender -z '$ZAF_ZBXSRV_HOST' -p '$ZAF_ZBXSRV_PORT' -i -" zaf_dbg $zscmd - eval $zscmd 2>&1 | zaf_dbg + eval $zscmd exit else if [ -n "$2" ]; then + # Hostname as parameter - rerun with right hostname set exec $0 send "$2" "$3" ZAF_HOSTNAME="$1" else + if echo "$1" | grep -q ':'; then + # Hostname:item - rerun with right hostname set + exec $0 send "$(echo $1 |cut -d ':' -f 2-)" "$3" ZAF_HOSTNAME="$(echo $1 |cut -d ':' -f 1)" + fi if zaf_is_item "$1"; then + # Item supported by zaf plugin=$(zaf_get_plugin_name "$1") item=$(zaf_get_item_name "$1") zscmd="zabbix_sender -z '$ZAF_ZBXSRV_HOST' -p '$ZAF_ZBXSRV_PORT' -s '$(zaf_hostname)' -k '$plugin.$item' -o '$(zaf_run_item $1)'" zaf_dbg $zscmd - eval $zscmd 2>&1 | zaf_dbg + eval $zscmd exit else if echo $1 | grep -q '='; then @@ -251,12 +258,11 @@ send) fi zscmd="zabbix_sender -z '$ZAF_ZBXSRV_HOST' -p '$ZAF_ZBXSRV_PORT' -s '$(zaf_hostname)' -k '$item' -o '$value'" zaf_dbg $zscmd - eval $zscmd 2>&1 | zaf_dbg + eval $zscmd exit fi fi fi - ;; register) shift