1、被监控端agentd安装httping-2.4-1.el6.x86_64.rpm
2、在zabbix的agentd端配置文件添加如下:
$ vim /etc/zabbix/zabbix_agentd.conf
UserParameter=httping.status[*],/etc/zabbix/scripts/httping.sh $1 $2 $3 $4
3、编写httping.sh脚本 /etc/zabbix/scripts/httping.sh
#!/bin/bash
metric=$1
host=$2
port=$3
proto=$4
tmp_file=/tmp/httping/${host}_${metric}_httping_status.txt
if [ $proto == "https" ];then
/bin/httping -c3 -t5 -l $proto://$host:$port > $tmp_file
case $metric in
status)
output=$(cat $tmp_file |grep connected |wc -l )
if [ $output -eq 3 ];then
output=1
echo $output
else
output=0
echo $output
fi
;;
failed)
output=$(cat $tmp_file |grep failed|awk '{print $5}'|awk -F'%' '{print $1}' )
if [ "$output" == "" ];then
echo 100
else
echo $output
fi
;;
min)
output=$( cat $tmp_file|grep min|awk '{print $4}'|awk -F/ '{print $1}' )
if [ "$output" == "" ];then
echo 0
else
echo $output
fi
;;
avg)
output=$(cat $tmp_file|grep avg|awk '{print $4}'|awk -F/ '{print $2}')
if [ "$output" == "" ];then
echo 0
else
echo $output
fi
;;
max)
output=$(cat $tmp_file|grep max|awk '{print $4}'|awk -F/ '{print $3}')
if [ "$output" == "" ];then
echo 0
else
echo $output
fi
;;
*)
echo -e "\e[033mUsage: sh $0 [status|failed|min|avg|max]\e[0m"
esac
elif [ $proto == "http" ];then
/bin/httping -c3 -t5 $proto://$host:$port > $tmp_file
case $metric in
status)
output=$(cat $tmp_file |grep connected |wc -l )
if [ $output -eq 3 ];then
output=1
echo $output
else
output=0
echo $output
fi
;;
failed)
output=$(cat $tmp_file |grep failed|awk '{print $5}'|awk -F'%' '{print $1}' )
if [ "$output" == "" ];then
echo 100
else
echo $output
fi
;;
min)
output=$( cat $tmp_file|grep min|awk '{print $4}'|awk -F/ '{print $1}' )
if [ "$output" == "" ];then
echo 0
else
echo $output
fi
;;
avg)
output=$(cat $tmp_file|grep avg|awk '{print $4}'|awk -F/ '{print $2}')
if [ "$output" == "" ];then
echo 0
else
echo $output
fi
;;
max)
output=$(cat $tmp_file|grep max|awk '{print $4}'|awk -F/ '{print $3}')
if [ "$output" == "" ];then
echo 0
else
echo $output
fi
;;
*)
echo -e "\e[033mUsage: sh $0 [status|failed|min|avg|max]\e[0m"
esac
else
echo "error parm " $proto >/tmp/httping/error.log
fi
4、在web端做相就的配置