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

[fix] socket test

This commit is contained in:
Ramil Valitov 2020-07-07 00:50:36 +03:00
parent a6196278aa
commit 6b8e58dc66
No known key found for this signature in database
GPG Key ID: 2AB186DABDFE1914
2 changed files with 17 additions and 18 deletions

View File

@ -24,6 +24,7 @@ jobs:
- sudo apt-get -y purge jq - sudo apt-get -y purge jq
- sudo apt-get -y purge libfcgi-bin libfcgi0ldbl - sudo apt-get -y purge libfcgi-bin libfcgi0ldbl
- sudo apt autoremove - sudo apt autoremove
- jq --version
script: bash tests/missing.sh script: bash tests/missing.sh
- os: linux - os: linux
dist: bionic dist: bionic

View File

@ -6,6 +6,7 @@
MAX_POOLS=3 MAX_POOLS=3
MAX_PORTS=3 MAX_PORTS=3
MIN_PORT=9000 MIN_PORT=9000
TEST_SOCKET=""
copyPool() { copyPool() {
ORIGINAL_FILE=$1 ORIGINAL_FILE=$1
@ -41,6 +42,9 @@ setupPool() {
POOL_NAME="static$c" POOL_NAME="static$c"
POOL_SOCKET="/run/php/php${PHP_VERSION}-fpm-${POOL_NAME}.sock" POOL_SOCKET="/run/php/php${PHP_VERSION}-fpm-${POOL_NAME}.sock"
copyPool "$POOL_FILE" "$POOL_NAME" "$POOL_SOCKET" "static" copyPool "$POOL_FILE" "$POOL_NAME" "$POOL_SOCKET" "static"
if [[ -z $TEST_SOCKET ]]; then
TEST_SOCKET="$POOL_SOCKET"
fi
done done
for ((c = 1; c <= MAX_POOLS; c++)); do for ((c = 1; c <= MAX_POOLS; c++)); do
@ -87,17 +91,6 @@ getNumberOfPHPVersions() {
echo "$PHP_COUNT" echo "$PHP_COUNT"
} }
getAnySocket() {
#Get any socket of PHP-FPM:
PHP_FIRST=$(find /etc/php/ -name 'www.conf' -type f | head -n1)
assertNotNull "Failed to get PHP conf" "$PHP_FIRST"
PHP_VERSION=$(echo "$PHP_FIRST" | grep -oP "(\d\.\d)")
assertNotNull "Failed to get PHP version" "$PHP_VERSION"
PHP_POOL=$(find /run/php/ -name "php${PHP_VERSION}*.sock" -type s | head -n1)
assertNotNull "Failed to get PHP${PHP_VERSION} socket" "$PHP_POOL"
echo "$PHP_POOL"
}
getAnyPort() { getAnyPort() {
PHP_PORT=$(sudo netstat -tulpn | grep -F "LISTEN" | grep -F "php-fpm" | head -n1 | awk '{print $4}' | rev | cut -d: -f1 | rev) PHP_PORT=$(sudo netstat -tulpn | grep -F "LISTEN" | grep -F "php-fpm" | head -n1 | awk '{print $4}' | rev | cut -d: -f1 | rev)
assertNotNull "Failed to get PHP port" "$PHP_PORT" assertNotNull "Failed to get PHP port" "$PHP_PORT"
@ -155,10 +148,8 @@ testPHPIsRunning() {
} }
testStatusScriptSocket() { testStatusScriptSocket() {
PHP_POOL=$(getAnySocket)
#Make the test: #Make the test:
DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_status.sh" "$PHP_POOL" "/php-fpm-status") DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_status.sh" "$TEST_SOCKET" "/php-fpm-status")
IS_OK=$(echo "$DATA" | grep -F '{"pool":"') IS_OK=$(echo "$DATA" | grep -F '{"pool":"')
assertNotNull "Failed to get status from pool $PHP_POOL: $DATA" "$IS_OK" assertNotNull "Failed to get status from pool $PHP_POOL: $DATA" "$IS_OK"
echo "Success test of $PHP_POOL" echo "Success test of $PHP_POOL"
@ -176,9 +167,7 @@ testStatusScriptPort() {
} }
testZabbixStatusSocket() { testZabbixStatusSocket() {
PHP_POOL=$(getAnySocket) DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.status["$TEST_SOCKET","/php-fpm-status"])
DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.status["$PHP_POOL","/php-fpm-status"])
IS_OK=$(echo "$DATA" | grep -F '{"pool":"') IS_OK=$(echo "$DATA" | grep -F '{"pool":"')
assertNotNull "Failed to get status from pool $PHP_POOL: $DATA" "$IS_OK" assertNotNull "Failed to get status from pool $PHP_POOL: $DATA" "$IS_OK"
echo "Success test of $PHP_POOL" echo "Success test of $PHP_POOL"
@ -228,7 +217,16 @@ testZabbixDiscoverNumberOfDynamicPools() {
assertEquals "Number of pools mismatch" "$POOLS_BY_DESIGN" "$NUMBER_OF_POOLS" assertEquals "Number of pools mismatch" "$POOLS_BY_DESIGN" "$NUMBER_OF_POOLS"
} }
testZabbixDiscoverNumberOfOndemandPools() { testZabbixDiscoverNumberOfOndemandPoolsCold() {
DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"])
NUMBER_OF_POOLS=$(echo "$DATA" | grep -o -F '{"{#POOLNAME}":"ondemand' | wc -l)
#If the pools are not started then we have 0 here:
assertEquals "Number of pools mismatch" "0" "$NUMBER_OF_POOLS"
}
testZabbixDiscoverNumberOfOndemandPoolsHot() {
# We must start all the pools
DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"]) DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"])
NUMBER_OF_POOLS=$(echo "$DATA" | grep -o -F '{"{#POOLNAME}":"ondemand' | wc -l) NUMBER_OF_POOLS=$(echo "$DATA" | grep -o -F '{"{#POOLNAME}":"ondemand' | wc -l)
PHP_COUNT=$(getNumberOfPHPVersions) PHP_COUNT=$(getNumberOfPHPVersions)