官方有模板示例, 根据官方更改
连接如下
https://zabbix.org/wiki/File:ZabbixTemplate_-_TCP_service_discovery.xml
配置端口服务列表
- root #cat tcp-port.conf
- http,80
- tomcat,8080
- mq,1883
编写自动发现脚本
- discovery_tcp_service.sh
- #/bin/bash
- CONFIG_FILE=/etc/zabbix/script/tcp-port.conf
- portarray=(`cat ${CONFIG_FILE}|awk -F ',' '{print $1","$2}'`)
- PortDiscovery(){
- length=${#portarray[@]}
- printf "{\n"
- printf '\t'"\"data\":["
- for ((i=0;i<$length;i++))
- do
- Name=`echo ${portarray[$i]}|awk -F',' '{print $1}'`
- Port=`echo ${portarray[$i]}|awk -F',' '{print $2}'`
- printf '\n\t\t{'
- printf '"{#NAME}":"%s", "{#PORT}":"%s"}'"$Name" "$Port"
- if [ $i -lt $[$length-1] ];then
- printf ','
- fi
- done
- printf "\n\t]\n"
- printf "}\n"
- }
- port(){
- PortDiscovery
- }
- port
配置 template
创建模板
自动发现
创建 Item
创建触发器
来源: http://www.bubuko.com/infodetail-3507419.html