AGENT:
Zabbix Custom Script
[[email protected] 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[[email protected] script]#
Run the script:
[[email protected] script]# sh check_ping.sh 172.16.8.11 www.baidu.com0000[[email protected] script]#
[[email protected] script]# sh check_ping.sh 172.16.8.11 www.nimeiakao.com
2222
[[email protected] script]
Modify zabbix_agentd.conf configuration and restart the service:
+++++++++++++### 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=<key>,<shell command># See ‘zabbix_agentd‘ directory for examples.## Mandatory: no# Default:UserParameter=check.icmpping[*],/usr/local/zabbix/script/check_ping.sh $1 $2++++++++++++++++++++++++++
[[email protected] etc]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd: [ OK ]
Starting zabbix_agentd: [ OK ]
[[email protected] etc]#
Use commands on the server to check whether the custom key is feasible:
[[Email protected] ~] # Zabbix_get-s 172.16.8.11-P 10050-k "check. icmpping [172.16.8.11, 172.16.8.12]" 0000 [[email protected] ~] # Zabbix_get-s 172.16.8.11-P 10050-k "check. icmpping [172.16.8.11, 192.168.1.2]" zbx_notsupported [[email protected] ~] #
We can see from the above that zabbix server cannot get the value for the value that cannot be obtained, and zbx_notsupported appears.
Zabbix cannot be used as a solution:
Modify the agent timeout and restart the agent service:
### Option: Timeout# Spend no more than Timeout seconds on processing## Mandatory: no# Range: 1-30# Default:#Timeout=3Timeout=8
[[email protected] etc]# /etc/init.d/zabbix_agentd restart
Shutting down zabbix_agentd: [ OK ]
Starting zabbix_agentd: [ OK ]
[[email protected] etc]#
Test again on the server:
[[email protected] ~]# zabbix_get -s 172.16.8.11 -p 10050 -k "check.icmpping[172.16.8.11,172.16.8.12]"0000[[email protected] ~]# zabbix_get -s 172.16.8.11 -p 10050 -k "check.icmpping[172.16.8.11,192.168.1.2]"2222[[email protected] ~]#
Zabbix cannot obtain the value of the custom script.