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

Docker+nacos+seata1.3.0 installation and usage configuration tutorial

I spent a day on it before this. Although Seata i...

Detailed process of installing logstash in Docker

Edit docker-compose.yml and add the following con...

How to use and limit props in react

The props of the component (props is an object) F...

Install MySQL 5.7.17 in win10 system

Operating system win10 MySQL is the 64-bit zip de...

JS array deduplication details

Table of contents 1 Test Cases 2 JS array dedupli...

A Deep Understanding of Angle Brackets in Bash (For Beginners)

Preface Bash has many important built-in commands...

Implementation principle and configuration of MySql master-slave replication

Database read-write separation is an essential an...

js uses FileReader to read local files or blobs

Table of contents FileReader reads local files or...

Vue implements video upload function

This article example shares the specific code of ...

Docker installation and configuration steps for Redis image

Table of contents Preface environment Install Cre...

Linux yum package management method

Introduction yum (Yellow dog Updater, Modified) i...

Enabling or disabling GTID mode in MySQL online

Table of contents Basic Overview Enable GTID onli...

Installing MySQL 8.0.12 based on Windows

This tutorial is only applicable to Windows syste...

CSS code for arranging photos in Moments

First, you can open Moments and observe several l...