3
0
mirror of https://github.com/rvalitov/zabbix-php-fpm.git synced 2023-11-05 03:30:27 +01:00

[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.
This commit is contained in:
Ramil Valitov 2019-10-01 12:02:49 +03:00
parent 7ece5b18c1
commit 97304dcc0f
No known key found for this signature in database
GPG Key ID: 645768E8FD0E18C7

View File

@ -45,13 +45,13 @@ POOL_FIRST=0
echo -n "{\"data\":[" echo -n "{\"data\":["
while IFS= read -r line while IFS= read -r line
do 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}'` 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 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)}'` 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 [[ ! -z $POOL_SOCKET ]]; then
if [[ $POOL_FIRST == 1 ]]; then
echo -n ","
fi
echo -n "{\"{#POOLNAME}\":" echo -n "{\"{#POOLNAME}\":"
echo -n "$line" | $S_JQ -aR . echo -n "$line" | $S_JQ -aR .
echo -n ",\"{#POOLSOCKET}\":" echo -n ",\"{#POOLSOCKET}\":"