1
0
spogulis no https://github.com/limosek/zaf.git synced 2025-11-01 01:57:38 +01:00

Support for plugin subcommands

Šī revīzija ir iekļauta:
Lukas Macura
2017-01-30 10:32:29 +01:00
vecāks 211d2fca39
revīzija 2977958dd5
5 mainīti faili ar 200 papildinājumiem un 14 dzēšanām

80
zaf
Parādīt failu

@@ -25,6 +25,8 @@ ZAF_CFG_FILE="/etc/zaf.conf"
[ -n "$secondstage" ] && exec $0 $params
fi
export ZAF_BIN=$(realpath $0)
if [ -n "$ZAF_PROXY" ]; then
export ALL_PROXY="$ZAF_PROXY"
export http_proxy="$ZAF_PROXY"
@@ -175,21 +177,35 @@ test)
done
done
;;
itemsh)
itemsh)
shift
if zaf_is_item "$1"; then
plugin=$(echo $1|cut -d '.' -f 1)
item=$(echo $1|cut -d '.' -f 2)
script=$(zaf_ctrl_generate_items_cfg "${ZAF_PLUGINS_DIR}/${plugin}/control.zaf" "${plugin}" "" "sh -i #"| grep "UserParameter=$1" | cut -d ',' -f 2-)
eval $script
exit
plugin=$(zaf_get_plugin_name "$1")
item=$(zaf_get_item_name "$1")
params=$(zaf_get_item_params "$1")
params2=$(zaf_paramstosh "[$params]")
script=$(zaf_ctrl_generate_items_cfg "${ZAF_PLUGINS_DIR}/${plugin}/control.zaf" "${plugin}" "" "sh -i #"| grep "UserParameter=$plugin.$item" | cut -d ',' -f 2-)
exec sh -c "$script" dummy $params2
else
zaf_err "No such plugin/item $1"
fi
;;
run)
shift
if zaf_is_item "$1"; then
plugin=$(zaf_get_plugin_name "$1")
item=$(zaf_get_item_name "$1")
params=$(zaf_get_item_params "$1")
params2=$(zaf_paramstosh "[$params]")
script=$(zaf_ctrl_generate_items_cfg "${ZAF_PLUGINS_DIR}/${plugin}/control.zaf" "${plugin}" | grep "UserParameter=$plugin.$item" | cut -d ',' -f 2-)
exec sh -c "$script" dummy $params2
else
zaf_err "No such plugin/item $1"
fi
;;
get)
shift
if echo $1|grep -q '\.'; then
if zaf_is_item "$1"; then
zaf_get_item "$1"
exit
fi
@@ -205,6 +221,39 @@ get)
done
done
;;
send)
shift
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
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 -"
zaf_dbg $zscmd
eval $zscmd
exit
fi
;;
register)
shift
if [ -z "$1" ]; then
hostname=$(zaf_hostname)
else
hostname="$1"
if [ -z "$2" ]; then
metadata="ZAF"
else
metadata="$2"
fi
fi
zaf_register "$hostname" "$metadata"
exit;
;;
precache)
shift
for i in $*; do
@@ -306,7 +355,8 @@ self-remove)
echo
echo "To continue, please do $0 self-remove force"
fi
;;
;;
###### API related commands
api)
zaf_zbxapi_login
@@ -463,6 +513,14 @@ api)
;;
*)
if zaf_is_plugin "$1"; then
if [ -z "$2" ]; then
zaf_list_plugin_commands "$1"
else
zaf_plugin_run_command "$@"
fi
exit
fi
echo "$0 Version ${ZAF_VERSION}. Please use some of this commands:"
echo "$0 Cmd [ZAF_OPTION=value] [ZAF_CTRL_Option=value] [ZAF_CTRLI_Item_Option=value] ..."
echo "Plugin manipulation commands:"
@@ -479,12 +537,18 @@ api)
echo "Plugin diagnostic commands:"
zaf_hlp "$0 test [plugin[.item]]" "To test [all] suported items by zabbix_agentd [for plugin]"
zaf_hlp "$0 get [plugin[.item]]" "To test [all] suported items by zabbix_get [for plugin]"
zaf_hlp "$0 run [plugin[.item]]" "To test [all] suported items by directly runing command [for plugin]"
zaf_hlp "$0 precache [plugin[.item]]" "To precache [all] suported items"
zaf_hlp "$0 itemsh plugin.item" "To spawn interactive shell in item context (same as UserParameter)."
echo
echo "Zabbix API commands:"
zaf_hlp "$0 api" "To zabbix API functions. See $0 api for more info."
echo
echo "Zabbix trapper commands:"
zaf_hlp "$0 send plugin.item" "To send result of agent param directly to Zabbix server by zabbix_server."
echo "Zabbix agent registration:"
zaf_hlp "$0 register [hostname] [metadata]" "To register hostname on Zabbix server (autoregistration)."
echo
echo "Agent config info commands:"
zaf_hlp "$0 userparms" "See userparms generated from zaf on stdout"
zaf_hlp "$0 agent-config [force]" "Reconfigure zabbix userparms in $ZAF_AGENT_CONFIGD"