From 37ac4c5e52ecc2802acbefaae5cc69897063cf12 Mon Sep 17 00:00:00 2001 From: Nick Kotov Date: Mon, 12 Aug 2024 10:06:48 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20zbx=5Fdiscovery=5Fsupervisor.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbx_discovery_supervisor.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 zbx_discovery_supervisor.sh diff --git a/zbx_discovery_supervisor.sh b/zbx_discovery_supervisor.sh new file mode 100644 index 0000000..561fcbb --- /dev/null +++ b/zbx_discovery_supervisor.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +# list all processes +PROCESSES=`sudo /usr/bin/supervisorctl status 2>/dev/null| grep -v 'supervisor.sock'|awk '{print $1}'` + + +# get processes array +INDEX=0 +for PROCESS_NAME in $PROCESSES +do + PROCESS_NAME_NUM[$INDEX]=$PROCESS_NAME + let INDEX=INDEX+1 +done + +num=$(echo ${#PROCESS_NAME_NUM[@]}) + +# echo json +printf '{\n' +printf '\t"data":[\n' +for((i=0;i<${#PROCESS_NAME_NUM[@]};++i)) +{ + NUM=$(echo $((${#PROCESS_NAME_NUM[@]}-1))) + if [ "$i" != ${NUM} ];then + printf "\t\t{ \n" + printf "\t\t\t\"{#PROCESS_NAME}\":\"${PROCESS_NAME_NUM[$i]}\"},\n" + else + printf "\t\t{ \n" + printf "\t\t\t\"{#PROCESS_NAME}\":\"${PROCESS_NAME_NUM[$NUM]}\"}\n" + fi +} +printf ']}' \ No newline at end of file