web界面添加监控项目
类型: Zabbix客户端
键值:如下
httping.status[failed,www.baidu.com,443,https]
httping.status[max,www.baidu.com,443,https]
httping.status[status,www.baidu.com,443,https]
信息类型:浮点数
在zabbix的agentd端的zabbix_agentd.conf添加如下配置
######httping###########
UserParameter=httping.status[*],/etc/zabbix/scripts/httping.sh $1 $2 $3 $4
使用httping脚本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