1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-24 03:19:05 +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)
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
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
eval $zscmd 2>&1 | zaf_dbg
exit
else
zaf_wrn "Waiting for data on stdin (host item value) per line"
zscmd="zabbix_sender -z '$ZAF_ZBXSRV_HOST' -p '$ZAF_ZBXSRV_PORT' -i -"
if echo $1 | grep -q '='; then
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
eval $zscmd
eval $zscmd 2>&1 | zaf_dbg
exit
fi
fi
fi
;;
register)
shift
@ -546,6 +566,8 @@ api)
echo
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 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:"
zaf_hlp "$0 register [hostname] [metadata]" "To register hostname on Zabbix server (autoregistration)."
echo