From 97304dcc0fa889ff4ac63294110badf3fec77166 Mon Sep 17 00:00:00 2001 From: Ramil Valitov Date: Tue, 1 Oct 2019 12:02:49 +0300 Subject: [PATCH] [fix] correct autodiscovery if there are problems with PID or socket, #1 If PID or socket are invalid or failed to detect, then it caused the JSON to be malformed because of extra comma. --- zabbix/zabbix_php_fpm_discovery.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zabbix/zabbix_php_fpm_discovery.sh b/zabbix/zabbix_php_fpm_discovery.sh index 6e1caad..305df3b 100644 --- a/zabbix/zabbix_php_fpm_discovery.sh +++ b/zabbix/zabbix_php_fpm_discovery.sh @@ -45,13 +45,13 @@ POOL_FIRST=0 echo -n "{\"data\":[" while IFS= read -r line do - if [[ $POOL_FIRST == 1 ]]; then - echo -n "," - fi POOL_PID=`printf '%s\n' "${PS_LIST[@]}" | $S_GREP "php-fpm: pool $line" | $S_HEAD -1 | $S_AWK '{print $1}'` if [[ ! -z $POOL_PID ]]; then POOL_SOCKET=`$S_LSOF -p $POOL_PID 2>/dev/null | $S_GREP unix | $S_HEAD -1 | $S_AWK '{ print $(NF-1)}'` if [[ ! -z $POOL_SOCKET ]]; then + if [[ $POOL_FIRST == 1 ]]; then + echo -n "," + fi echo -n "{\"{#POOLNAME}\":" echo -n "$line" | $S_JQ -aR . echo -n ",\"{#POOLSOCKET}\":"