转载自:http://blog.chinaunix.net/uid-346158-id-2131139.html


zabbix 1.6.5
在使用UserParameter的时候,使用星号*通配符将给你带来不少方便,在zabbix_agentd.conf中你可以用一行代码代替多行代码.但是需要注意其中的用法,有些独特:
举例,我要自定义三个UserParameter,如下:
hall_count_[ct]
hall_count_[cnc]
hall_count_[sum]
在不使用通配符的情况下,你不得不编写三行代码:
UserParameter=hall_count_ct,cat /tmp/hall_count.txt|grep ct|awk '{print $2}'
UserParameter=hall_count_cnc,cat /tmp/hall_count.txt|grep cnc|awk '{print $2}'
UserParameter=hall_count_sum,cat /tmp/hall_count.txt|grep sum|awk '{print $2}'

使用星号通配符后,只要一行代码即可:
UserParameter=hall_count_[*],cat /tmp/hall_count.txt|grep "$1"|awk '{print $$2}'

根据本人经验,使用通配符需要注意: 
1. 在使用了星号通配符后,必须使用中括号[*]扩起来,否则无法使用,且zabbix这里自定义只能有一个星号
2. 后面的命令中的$1,$2...$n这种标识匹配的是前面星号里的第几个参数,参数之间用逗号隔开,而不再是shell中原来的含义,如果要继续使用shell中的含义,要多加一个$符号,比如$$1,$$2;

UserParameter=onl_player_[*],grep "\<$1\>" /tmp/onlineplayercount_za.txt|awk '/'$2'/{print $$3}'
如:
onl_player_[zone1,tunnel-01],上面的$1对应zone1,$2对应tunnel-01
zabbix这里的通配是个不错的功能,不过zabbix画出来的图实在太难看了...