zabbix 获取不到自定义脚本的值解决

时间:2023-03-09 17:23:37
zabbix 获取不到自定义脚本的值解决

agent端:

zabbix 自定义脚本

[root@localhost script]# cat check_ping.sh
#!/bin/bash
result=$(/usr/local/nagios/libexec/check_icmp -s $ $)
a=$(echo $result | awk '{print $1}')
if [ $a == "OK" ];then
echo ""
else
echo ""
fi
[root@localhost script]#

执行脚本:

[root@localhost script]# sh check_ping.sh 172.16.8.11 www.baidu.com

[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.
# - do not allow
# - allow
#
# Mandatory: no
# Range: -
# Default:
UnsafeUserParameters= ### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
UserParameter=check.icmpping[*],/usr/local/zabbix/script/check_ping.sh $ $
++++++++++++++++++++++++++
[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  -k "check.icmpping[172.16.8.11,172.16.8.12]"

[root@localhost ~]# zabbix_get -s 172.16.8.11 -p  -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: -
# Default:
#Timeout=
Timeout=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  -k "check.icmpping[172.16.8.11,172.16.8.12]"

[root@localhost ~]# zabbix_get -s 172.16.8.11 -p  -k "check.icmpping[172.16.8.11,192.168.1.2]"

[root@localhost ~]#