/usr/bin/sh

# Simple wrapper script to use with Zabbix and the C client of vPoller

whitespace="[[:space:]]"
_args=''

### Process variables with spaces in
for i in "$@"
do
    if [[ $i =~ $whitespace ]]
    then
       _args="${_args} \"$i\""
    else
       _args="${_args} $i"
    fi
done

_property_name=`echo ${_args} | sed -ne 's|.* -p \([a-zA-Z\.]*\)|\1|p'`

# Rename property as it might contain dots in the complete property name, so that 'jq' can parse it
sh -c "vpoller-cclient ${_args} 2>/dev/null" | jq -r ".result[0] | {\"property\": .[\"${_property_name}\"]}.property"
