1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-21 18:09:06 +01:00

Repaired zaf send

This commit is contained in:
Lukas Macura 2017-02-14 17:05:16 +01:00
parent 52386a624f
commit eaf83df311

30
zaf
View File

@ -223,20 +223,40 @@ get)
;; ;;
send) send)
shift shift
if [ -z "$1" ]; then
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
exit
else
if [ -n "$2" ]; then
exec $0 send "$2" "$3" ZAF_HOSTNAME="$1"
else
if zaf_is_item "$1"; then if zaf_is_item "$1"; then
plugin=$(zaf_get_plugin_name "$1") plugin=$(zaf_get_plugin_name "$1")
item=$(zaf_get_item_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)'" 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 zaf_dbg $zscmd
eval $zscmd eval $zscmd 2>&1 | zaf_dbg
exit exit
else else
zaf_wrn "Waiting for data on stdin (host item value) per line" if echo $1 | grep -q '='; then
zscmd="zabbix_sender -z '$ZAF_ZBXSRV_HOST' -p '$ZAF_ZBXSRV_PORT' -i -" item=$(echo $1 | cut -d '=' -f 1)
value=$(echo $1 | cut -d '=' -f 2-)
else
item=$1
zaf_dbg "Waiting for value of $(zaf_hostname):$1 on stdin"
value=$(cat)
fi
zscmd="zabbix_sender -z '$ZAF_ZBXSRV_HOST' -p '$ZAF_ZBXSRV_PORT' -s '$(zaf_hostname)' -k '$item' -o '$value'"
zaf_dbg $zscmd zaf_dbg $zscmd
eval $zscmd eval $zscmd 2>&1 | zaf_dbg
exit exit
fi fi
fi
fi
;; ;;
register) register)
shift shift
@ -546,6 +566,8 @@ api)
echo echo
echo "Zabbix trapper commands:" echo "Zabbix trapper commands:"
zaf_hlp "$0 send plugin.item" "To send result of agent param directly to Zabbix server by zabbix_server." zaf_hlp "$0 send plugin.item" "To send result of agent param directly to Zabbix server by zabbix_server."
zaf_hlp "$0 send item" "To send value for any item from stdin."
zaf_hlp "$0 send host:item" "To send value for any host:item from stdin."
echo "Zabbix agent registration:" echo "Zabbix agent registration:"
zaf_hlp "$0 register [hostname] [metadata]" "To register hostname on Zabbix server (autoregistration)." zaf_hlp "$0 register [hostname] [metadata]" "To register hostname on Zabbix server (autoregistration)."
echo echo