yadianna 发表于 2018-1-2 10:20:34

自动化监控:zabbix自动发现mysql端口并监控

# cat /etc/zabbix/alertscripts/zabbix_discovery_mysql.sh  
#!/bin/bash
  
mysql() {
  port=($(sudo netstat -tpln | awk -F "[ :]+" '/ysql/' | awk -F: '{print $4}'))
  printf '{\n'
  printf '\t"data":[\n'
  for key in ${!port[@]}
  do
  if [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#port[@]}-1))" ]];then
  socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $10}'|cut -d ' ' -f 1`
  printf '\t {\n'
  printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"},\n"
  else [[ "${key}" -eq "((${#port[@]}-1))" ]]
  socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F '=' '{print $10}'|cut -d ' ' -f 1`
  printf '\t {\n'
  printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"}\n"
  fi
  done
  printf '\t ]\n'
  printf '}\n'
  
}
  
$1

chelly 发表于 2018-3-14 15:53:32

这个很不错

chelly 发表于 2018-3-14 15:53:45

这个很不错

chelly 发表于 2018-3-14 15:53:56

这个很不错
页: [1]
查看完整版本: 自动化监控:zabbix自动发现mysql端口并监控