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
I spent a day on it before this. Although Seata i...
Edit docker-compose.yml and add the following con...
The props of the component (props is an object) F...
Operating system win10 MySQL is the 64-bit zip de...
Table of contents 1 Test Cases 2 JS array dedupli...
Preface Bash has many important built-in commands...
Database read-write separation is an essential an...
Table of contents FileReader reads local files or...
This article example shares the specific code of ...
1. Interconnection between Docker containers Dock...
Table of contents Preface environment Install Cre...
Introduction yum (Yellow dog Updater, Modified) i...
Table of contents Basic Overview Enable GTID onli...
This tutorial is only applicable to Windows syste...
First, you can open Moments and observe several l...