Zabbix redis automatic port discovery script returns json format

Zabbix redis automatic port discovery script returns json format

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!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed explanation of Selenium's execution of Javascript script parameters and return values
  • Springboot2.0 handles custom exceptions and returns json
  • Example code of javascript jump, return and refresh page
  • Processing null values ​​returned in json in SpringBoot project (springboot project as an example)
  • Laravel error handling, interface error returns json code
  • Spring boot unified JSON format interface return result implementation
  • JavaScript find() method and returned data example

<<:  Detailed usage of Vue more filter widget

>>:  Detailed explanation of MySQL database--multi-table query--inner join, outer join, subquery, correlated subquery

Recommend

Nginx load balancing algorithm and failover analysis

Overview Nginx load balancing provides upstream s...

Detailed installation process of MySQL5.6.40 under CentOS7 64

MySQL5.6.40 installation process under CentOS7 64...

How to mark the source and origin of CSS3 citations

I am almost going moldy staying at home due to th...

Solution - BASH: /HOME/JAVA/JDK1.8.0_221/BIN/JAVA: Insufficient permissions

1) Enter the folder path where the jdk file is st...

How to install git on linux

1. Introduction Git is a free, open source distri...

Vue.js uses Element-ui to implement the navigation menu

This article shares the specific code for impleme...

Detailed discussion of MySQL stored procedures and stored functions

1 Stored Procedure 1.1 What is a stored procedure...

Example of how to implement underline effects using Css and JS

This article mainly describes two kinds of underl...

How to start multiple MySQL instances in CentOS 7.0 (mysql-5.7.21)

Configuration Instructions Linux system: CentOS-7...

Based on the special characters in the URL escape encoding

Table of contents Special characters in URLs URL ...

Detailed explanation of how to use zabbix to monitor oracle database

1. Overview Zabbix is ​​a very powerful and most ...