自动发现端口并添加监控设置
UserParameter=net.listen.discovery,sudo /etc/zabbix/scripts/discovery_listport.sh

#!/bin/bash

Check=(`netstat -lntp|awk '/^tcp/{split($4,Port,":");split($7,Name,"[/:]");print Name[2]":"Port[length(Port)]}'|sort -u`)
if [ -z "$Check" ];then
        exit
else
        length=${#Check[@]}
fi

printf "{\n"
printf  "\t\"data\":["
for((i=0;i<$length;i++))
do
        Server=`echo ${Check[$i]}|cut -d: -f1`
        Port=`echo ${Check[$i]}|cut -d: -f2`
        printf "\n\t\t{"
        printf "\n\t\t\t\"{#SERVERNAME}\":\"$Server\","
        printf "\n\t\t\t\"{#PORT}\":\"$Port\"}"
        if [ $i -lt $(($length-1)) ];then
                printf ','
        fi
done
printf  "]}\n"
discovery_listport.sh

相关文章: