When we perform automatic discovery, there is always a script to obtain information such as ports and return them in json format. Taking redis as an example, the following is the script for automatic discovery of redis redisport=(`ps aux|grep -w redis-server|grep -v "grep" |awk -F':' '{print $NF}'`) portnum=${#redisport[@]} count=`hostname | grep "\-SQ" | wc -l` if [ $count -eq 1 ];then address=` /usr/sbin/ip address | grep -w "inet" | awk -F " " '{print $2}' | egrep "^10."| awk -F"/" '{print $1}'` else address=` /usr/sbin/ip address | grep "192.168" | awk '{print $2}' | awk -F "/" '{print $1}'` fi printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$portnum;i++)) do printf '\n\t\t{\n' printf '\t\t\t' printf "\"{#REDIS_PORT}\":\"${redisport[$i]}\"", printf '\n\t\t\t' printf "\"{#REDIS_ADDRESS}\":\"${address}"\", printf '\n\t\t\t' printf "\"{#REDIS_NAME}\":\"Redis ${address}:${redisport[$i]}\"" printf '\n\t\t}' if [ $i -lt $[$portnum-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n" The returned results are as follows { "data":[ { "{#REDIS_PORT}":"6386", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6386" }, { "{#REDIS_PORT}":"6387", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6387" }, { "{#REDIS_PORT}":"6388", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6388" }, { "{#REDIS_PORT}":"6379", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6379" }, { "{#REDIS_PORT}":"6384", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6384" }, { "{#REDIS_PORT}":"6385", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6385" } ] } Summarize The above is the zabbix redis automatic discovery port script return json format introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Detailed usage of Vue more filter widget
Overview Nginx load balancing provides upstream s...
MySQL5.6.40 installation process under CentOS7 64...
getElementById cannot get the object There is a s...
I am almost going moldy staying at home due to th...
1) Enter the folder path where the jdk file is st...
1. Introduction Git is a free, open source distri...
This article uses examples to illustrate the prin...
This article shares the specific code for impleme...
1 Stored Procedure 1.1 What is a stored procedure...
Effect: <!doctype html> <html> <he...
This article mainly describes two kinds of underl...
Table of contents 1. Background: 2. Design ideas:...
Configuration Instructions Linux system: CentOS-7...
Table of contents Special characters in URLs URL ...
1. Overview Zabbix is a very powerful and most ...