zabbix 监控端口

监控HTTPD端口的shell

#!/bin/bash
#2019年4月19日18:16:05
#######
httpd=` netstat -tnlp|grep httpd|awk '{print $4}'|sed 's/://g'`
port=($httpd)
printf '{'
printf '"data":['
for key in ${!port[@]}
do
        if [[ "${#port[@]}" -gt 1 && $key -ne "$((${#port[@]}-1))" ]];then
                printf '{'
                printf "\"{#HTTPDPORT}\":\"${port[${key}]}\"},"
        else [[ "${key}" -eq "$((${#port[@]} -1))" ]]
                printf '{'
                printf "\"{#HTTPDPROT}\":\"${port[${key}]}\"}"
        fi
done
printf ']'
printf '}'
~            

在agent添加如下代码

vim /etc/zabbix/zabbix_agentd.conf 

UserParameter=httpd.discovery[*],/data/sh/discovery_httpd.sh $1
UserParameter=httpd.status[*], netstat -tnlp|grep -c $1

猜你喜欢

转载自www.cnblogs.com/legenidongma/p/10740640.html
今日推荐