agent端:
zabbix 自定义脚本
[root@localhost script]# cat check_ping.sh #!/bin/bashresult=$(/usr/local/nagios/libexec/check_icmp -s $1 $2)a=$(echo $result | awk '{print $1}')if [ $a == "OK" ];then echo "0000"else echo "2222"fi[root@localhost script]#
执行脚本:
[root@localhost script]# sh check_ping.sh 172.16.8.11 www.baidu.com0000[root@localhost script]# [root@localhost script]# sh check_ping.sh 172.16.8.11 www.nimeiakao.com 2222 [root@localhost script]
修改zabbix_agentd.conf配置并重启服务:
+++++++++++++### Option: UnsafeUserParameters# Allow all characters to be passed in arguments to user-defined parameters.# 0 - do not allow# 1 - allow## Mandatory: no# Range: 0-1# Default:UnsafeUserParameters=1### Option: UserParameter# User-defined parameter to monitor. There can be several user-defined parameters.# Format: UserParameter=, # See 'zabbix_agentd' directory for examples.## Mandatory: no# Default:UserParameter=check.icmpping[*],/usr/local/zabbix/script/check_ping.sh $1 $2++++++++++++++++++++++++++ [root@localhost etc]# /etc/init.d/zabbix_agentd restart Shutting down zabbix_agentd: [ OK ] Starting zabbix_agentd: [ OK ] [root@localhost etc]#
在服务端使用命令检测自定义key是否可行:
[root@localhost ~]# zabbix_get -s 172.16.8.11 -p 10050 -k "check.icmpping[172.16.8.11,172.16.8.12]"0000[root@localhost ~]# zabbix_get -s 172.16.8.11 -p 10050 -k "check.icmpping[172.16.8.11,192.168.1.2]"ZBX_NOTSUPPORTED[root@localhost ~]# 从上面可以看出,对于不通的值zabbix服务端始终取不到值,出现ZBX_NOTSUPPORTED
zabbix取不到值得解决办法:
修改agent端的超时时间并重启agent服务:
### Option: Timeout# Spend no more than Timeout seconds on processing## Mandatory: no# Range: 1-30# Default:#Timeout=3Timeout=8 [root@localhost etc]# /etc/init.d/zabbix_agentd restart Shutting down zabbix_agentd: [ OK ] Starting zabbix_agentd: [ OK ] [root@localhost etc]#
在server端再次测试:
[root@localhost ~]# zabbix_get -s 172.16.8.11 -p 10050 -k "check.icmpping[172.16.8.11,172.16.8.12]"0000[root@localhost ~]# zabbix_get -s 172.16.8.11 -p 10050 -k "check.icmpping[172.16.8.11,192.168.1.2]"2222[root@localhost ~]#