Repaired send operation

master
Lukas Macura 2017-02-15 15:35:16 +01:00
parent eaf83df311
commit 8b81fea72c
3 changed files with 44 additions and 8 deletions

View File

@ -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]
```

View File

@ -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

14
zaf
View File

@ -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