Search code examples
bashfreebsdzabbix

Zabbix userparameter with multiple values doesn't work


I am trying to make Zabbix item workable on FreeBSD for gathering info from SQUID.

I have the next UserParameter:

UserParameter=data.sclient[*], printf "GET cache_object://localhost/purgeng/$2 HTTP/1.0\nAccept */*\n\n" | for i in $(echo "$1" | tr "," "\n" ); do nc -w 3 127.0.0.1 $i ; done | awk '/^[[:space:]]*$$
/ {getline;split($$0, a, / = /);print a[2]} END{if(!NR) print -2}'

But it works only with one port value, for example:

zabbix_get -s 192.168.1.7 -p 10050 -k data.sclient["1111",distributors/configured]
6

When I try with two port values:

zabbix_get -s 192.168.1.7 -p 10050 -k data.sclient["1111,2222",distributors/configured]
false

Could you please help me to make it work with multiple ports?


Solution

  • My problem was in incorrect setting of for loop.

    I did:

    UserParameter=data.sclient[*], for i in $(echo $1); do printf "GET cache_object://localhost/purgeng/$2 HTTP/1.0\nAccept */*\n\n" | nc -w 3 127.0.0.1 $i ; done | awk '/^[[:space:]]*$$/ {getline;split($$0, a, / = /);print a[2]} END{if(!NR) print -2}'
    
    $ zabbix_get -s 192.168.1.7 -p 10050 -k data.sclient["1111 2222",distributors/connected]
    3
    3