├── .gitattributes ├── zabbix ├── userparameter_php_fpm.conf ├── zabbix_php_fpm_status.sh └── zabbix_php_fpm_discovery.sh ├── .gitignore ├── ispconfig ├── nginx.patch ├── php-fpm.patch ├── php_fpm_pool.conf.master └── nginx_vhost.conf.master ├── .github ├── FUNDING.yml ├── stale.yml └── config.yml ├── tests ├── missing.sh └── all.sh ├── .travis.yml ├── README.md └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf -------------------------------------------------------------------------------- /zabbix/userparameter_php_fpm.conf: -------------------------------------------------------------------------------- 1 | UserParameter=php-fpm.discover[*],sudo /etc/zabbix/zabbix_php_fpm_discovery.sh $1 2 | UserParameter=php-fpm.status[*],sudo /etc/zabbix/zabbix_php_fpm_status.sh $1 $2 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows thumbnail db 2 | Thumbs.db 3 | 4 | # OSX files 5 | .DS_Store 6 | 7 | #log files 8 | *.log 9 | 10 | #bak files 11 | ~* 12 | *.bak 13 | 14 | #temp files 15 | *.tmp 16 | 17 | #PhpStorm 18 | .idea/ 19 | 20 | #Visual Studio 21 | .vs/ 22 | -------------------------------------------------------------------------------- /ispconfig/nginx.patch: -------------------------------------------------------------------------------- 1 | --- ../conf/nginx_vhost.conf.master 2020-08-05 22:13:51.469316718 +0300 2 | +++ nginx_vhost.conf.master 2020-08-05 22:39:44.744479903 +0300 3 | @@ -164,7 +164,7 @@ 4 | alias /usr/share/awstats/icon; 5 | } 6 | 7 | - location ~ \.php$ { 8 | + location ~ (\.php|^/php-fpm-status)$ { 9 | try_files @php; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | patreon: ramram 4 | open_collective: ramil-valitov 5 | ko_fi: ramram 6 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 7 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 8 | liberapay: ram 9 | issuehunt: rvalitov 10 | custom: ['https://www.paypal.me/valitov/0eur', 'https://money.yandex.ru/to/410011424143476'] 11 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 30 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 14 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | - bug 10 | # Label to use when marking an issue as stale 11 | staleLabel: wontfix 12 | # Comment to post when marking an issue as stale. Set to `false` to disable 13 | markComment: > 14 | This issue has been automatically marked as stale because it has not had 15 | recent activity. It will be closed if no further activity occurs. Thank you 16 | for your contributions. 17 | # Comment to post when closing a stale issue. Set to `false` to disable 18 | closeComment: false -------------------------------------------------------------------------------- /ispconfig/php-fpm.patch: -------------------------------------------------------------------------------- 1 | From 12444b7b13a8f771549e2f9171362ae0cc252d40 Mon Sep 17 00:00:00 2001 2 | From: Ramil Valitov 3 | Date: Mon, 12 Aug 2019 09:21:35 +0300 4 | Subject: [PATCH] [add] enable php-fpm status page 5 | 6 | --- 7 | ispconfig/php_fpm_pool.conf.master | 1 + 8 | 1 file changed, 1 insertion(+) 9 | 10 | diff --git a/ispconfig/php_fpm_pool.conf.master b/ispconfig/php_fpm_pool.conf.master 11 | index fb5c4b4..a314594 100644 12 | --- a/ispconfig/php_fpm_pool.conf.master 13 | +++ b/ispconfig/php_fpm_pool.conf.master 14 | @@ -25,6 +25,7 @@ pm.max_spare_servers = 15 | pm.process_idle_timeout = s; 16 | 17 | pm.max_requests = 18 | +pm.status_path = /php-fpm-status 19 | 20 | chdir = / 21 | 22 | -- 23 | 2.24.1.windows.2 24 | 25 | -------------------------------------------------------------------------------- /zabbix/zabbix_php_fpm_status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Ramil Valitov ramilvalitov@gmail.com 3 | #https://github.com/rvalitov/zabbix-php-fpm 4 | #Script gets status of PHP-FPM pool 5 | 6 | S_FCGI=$(type -P cgi-fcgi) 7 | S_GREP=$(type -P grep) 8 | 9 | if [[ ! -x $S_FCGI ]]; then 10 | echo "Utility 'cgi-fcgi' not found. Please, install it first." 11 | exit 1 12 | fi 13 | 14 | if [[ ! -x $S_GREP ]]; then 15 | echo "Utility 'grep' not found. Please, install it first." 16 | exit 1 17 | fi 18 | 19 | USER_ID=$(id -u) 20 | if [[ $USER_ID -ne 0 ]]; then 21 | echo "Insufficient privileges. This script must be run under 'root' user or with 'sudo'." 22 | exit 1 23 | fi 24 | 25 | if [[ -z $1 ]] || [[ -z $2 ]]; then 26 | echo "No input data specified" 27 | echo "Usage: $0 php-path status" 28 | echo "where:" 29 | echo "php-path - path to socket file, for example, /var/lib/php7.3-fpm/web1.sock" 30 | echo "or IP and port of the PHP-FPM, for example, 127.0.0.1:9000" 31 | echo "status - path configured in pm.status of PHP-FPM" 32 | exit 1 33 | fi 34 | 35 | POOL_URL=$1 36 | POOL_PATH=$2 37 | #connecting to socket or address, https://easyengine.io/tutorials/php/directly-connect-php-fpm/ 38 | PHP_STATUS=$( 39 | SCRIPT_NAME=$POOL_PATH \ 40 | SCRIPT_FILENAME=$POOL_PATH \ 41 | QUERY_STRING=json \ 42 | REQUEST_METHOD=GET \ 43 | $S_FCGI -bind -connect "$POOL_URL" 2>/dev/null 44 | ) 45 | echo "$PHP_STATUS" | $S_GREP "{" 46 | exit 0 47 | -------------------------------------------------------------------------------- /ispconfig/php_fpm_pool.conf.master: -------------------------------------------------------------------------------- 1 | [] 2 | 3 | 4 | listen = 127.0.0.1: 5 | listen.allowed_clients = 127.0.0.1 6 | 7 | 8 | listen = 9 | listen.owner = 10 | listen.group = 11 | listen.mode = 12 | 13 | 14 | user = 15 | group = 16 | 17 | pm = 18 | pm.max_children = 19 | 20 | pm.start_servers = 21 | pm.min_spare_servers = 22 | pm.max_spare_servers = 23 | 24 | 25 | pm.process_idle_timeout = s; 26 | 27 | pm.max_requests = 28 | pm.status_path = /php-fpm-status 29 | 30 | chdir = / 31 | 32 | chroot = 33 | php_admin_value[doc_root] = 34 | php_admin_value[cgi.fix_pathinfo] = 0 35 | 36 | 37 | env[HOSTNAME] = $HOSTNAME 38 | env[TMP] = /tmp 39 | env[TMPDIR] = /tmp 40 | env[TEMP] = /tmp 41 | env[PATH] = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 42 | 43 | 44 | php_admin_value[open_basedir] = 45 | 46 | php_admin_value[session.save_path] = /tmp 47 | 48 | php_admin_value[upload_tmp_dir] = /tmp 49 | php_admin_value[sendmail_path] = "/usr/sbin/sendmail -t -i -f webmaster@" 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | # Configuration for welcome - https://github.com/behaviorbot/welcome 2 | 3 | # Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome 4 | 5 | # Comment to be posted to on first time issues 6 | newIssueWelcomeComment: | 7 | ![Hello welcome GIF](https://media.giphy.com/media/bcKmIWkUMCjVm/giphy.gif) 8 | Thank you so much for opening your first issue here! :cherry_blossom: 9 | :white_check_mark: I hope you have kindly checked any other [opened issues](https://github.com/rvalitov/zabbix-php-fpm/issues) to make sure that it's not a duplicate :pray: 10 | :white_check_mark: And you have read the [Wiki](https://github.com/rvalitov/zabbix-php-fpm/wiki) of this project that contains a full documentation, specifically the [Installation instructions](https://github.com/rvalitov/zabbix-php-fpm/wiki/Installation) and [Troubleshooting guide](https://github.com/rvalitov/zabbix-php-fpm/wiki/Testing-and-Troubleshooting) :innocent: 11 | :information_source: You may add any additional information by editing your original post or by posting additional comments below. 12 | :information_source: We need some time to read your issue and verify it, so please, be patient :innocent: 13 | :information_source: Any questions or comments regarding your issue will be posted here below that may require your response. So, please, don't miss the Github notifications about new updates on this topic :wink: 14 | 15 | We will kindly investigate the information you provided and hopefully return to you as soon as possible! :blush: 16 | 17 | # Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome 18 | 19 | # Comment to be posted to on PRs from first time contributors in your repository 20 | newPRWelcomeComment: | 21 | ![Thank you GIF](https://media.giphy.com/media/3o6Zt6KHxJTbXCnSvu/giphy.gif) 22 | Thank you so much for opening this pull request! :blush::cherry_blossom: Your contribution is much appreciated! :pray: 23 | It takes some time to make a review of your contribution before merging your code, so please, be patient :innocent: 24 | Any questions or comments regarding your pull request will be posted here below that may require your response. So, please, don't miss the Github notifications about this pull request :wink: Thank you! 25 | 26 | # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge 27 | 28 | # Comment to be posted to on pull requests merged by a first time user 29 | firstPRMergeComment: | 30 | ![Happy dance GIF](https://media.giphy.com/media/Q8IYWnnogTYM5T6Yo0/giphy.gif) 31 | Congrats on merging your first pull request! :clap::cherry_blossom: Thank you so much for your contribution! :pray: A really good work! :muscle::thumbsup: 32 | If you would like to improve this project any further, I will be happy to receive new pull requests from you! :innocent: 33 | 34 | # It is recommend to include as many gifs and emojis as possible -------------------------------------------------------------------------------- /tests/missing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Ramil Valitov ramilvalitov@gmail.com 3 | #https://github.com/rvalitov/zabbix-php-fpm 4 | #This script is used for testing 5 | 6 | # Used for section folding in Travis CI 7 | SECTION_UNIQUE_ID="" 8 | 9 | # ---------------------------------- 10 | # Colors 11 | # ---------------------------------- 12 | NOCOLOR='\033[0m' 13 | RED='\033[0;31m' 14 | GREEN='\033[0;32m' 15 | ORANGE='\033[0;33m' 16 | BLUE='\033[0;34m' 17 | PURPLE='\033[0;35m' 18 | CYAN='\033[0;36m' 19 | LIGHTGRAY='\033[0;37m' 20 | DARKGRAY='\033[1;30m' 21 | LIGHTRED='\033[1;31m' 22 | LIGHTGREEN='\033[1;32m' 23 | YELLOW='\033[1;33m' 24 | LIGHTBLUE='\033[1;34m' 25 | LIGHTPURPLE='\033[1;35m' 26 | LIGHTCYAN='\033[1;36m' 27 | WHITE='\033[1;37m' 28 | 29 | function printYellow() { 30 | local info=$1 31 | echo -e "${YELLOW}$info${NOCOLOR}" 32 | } 33 | 34 | function printRed() { 35 | local info=$1 36 | echo -e "${RED}$info${NOCOLOR}" 37 | } 38 | 39 | function printGreen() { 40 | local info=$1 41 | echo -e "${LIGHTGREEN}$info${NOCOLOR}" 42 | } 43 | 44 | function printSuccess() { 45 | local name=$1 46 | printGreen "✓ OK: test '$name' passed" 47 | } 48 | 49 | function printDebug() { 50 | local info=$1 51 | echo -e "${DARKGRAY}$info${NOCOLOR}" 52 | } 53 | 54 | function printAction() { 55 | local info=$1 56 | echo -e "${LIGHTBLUE}$info${NOCOLOR}" 57 | } 58 | 59 | function travis_fold_start() { 60 | local name=$1 61 | local info=$2 62 | local CURRENT_TIMING 63 | CURRENT_TIMING=$(date +%s%3N) 64 | SECTION_UNIQUE_ID="$name.$CURRENT_TIMING" 65 | echo -e "travis_fold:start:${SECTION_UNIQUE_ID}\033[33;1m${info}\033[0m" 66 | } 67 | 68 | function travis_fold_end() { 69 | echo -e "\ntravis_fold:end:${SECTION_UNIQUE_ID}\r" 70 | } 71 | 72 | oneTimeSetUp() { 73 | printAction "Started job $TRAVIS_JOB_NAME" 74 | 75 | travis_fold_start "host_info" "ⓘ Host information" 76 | nslookup localhost 77 | sudo ifconfig 78 | sudo cat /etc/hosts 79 | travis_fold_end 80 | 81 | printAction "Copying Zabbix files..." 82 | #Install files: 83 | sudo cp "$TRAVIS_BUILD_DIR/zabbix/zabbix_php_fpm_discovery.sh" "/etc/zabbix" 84 | sudo cp "$TRAVIS_BUILD_DIR/zabbix/zabbix_php_fpm_status.sh" "/etc/zabbix" 85 | sudo cp "$TRAVIS_BUILD_DIR/zabbix/userparameter_php_fpm.conf" "$(find /etc/zabbix/ -name 'zabbix_agentd*.d' -type d | head -n1)" 86 | sudo chmod +x /etc/zabbix/zabbix_php_fpm_discovery.sh 87 | sudo chmod +x /etc/zabbix/zabbix_php_fpm_status.sh 88 | 89 | printAction "All done, starting tests..." 90 | } 91 | 92 | testMissingPackagesDiscoveryScript() { 93 | DATA=$(sudo bash "/etc/zabbix/zabbix_php_fpm_discovery.sh" "/php-fpm-status") 94 | IS_OK=$(echo "$DATA" | grep -F ' not found.') 95 | assertNotNull "Discovery script didn't report error on missing utilities $DATA" "$IS_OK" 96 | printSuccess "${FUNCNAME[0]}" 97 | } 98 | 99 | testMissingPackagesStatusScript() { 100 | DATA=$(sudo bash "/etc/zabbix/zabbix_php_fpm_status.sh" "localhost:9000" "/php-fpm-status") 101 | IS_OK=$(echo "$DATA" | grep -F ' not found.') 102 | assertNotNull "Status script didn't report error on missing utilities $DATA" "$IS_OK" 103 | printSuccess "${FUNCNAME[0]}" 104 | } 105 | 106 | # Load shUnit2. 107 | . shunit2 108 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: bash 3 | 4 | jobs: 5 | include: 6 | - os: linux 7 | dist: bionic 8 | name: "Missing packages test" 9 | arch: amd64 10 | addons: 11 | apt: 12 | sources: 13 | - sourceline: 'deb http://repo.zabbix.com/zabbix/4.0/ubuntu bionic main' 14 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 15 | packages: 16 | - bc 17 | - curl 18 | - grep 19 | - sed 20 | - gawk 21 | - zabbix-agent 22 | before_script: 23 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 24 | - sudo apt-get -y remove jq 25 | - sudo apt-get -y remove libfcgi-bin libfcgi0ldbl 26 | - sudo apt autoremove 27 | - jq --version 28 | script: bash tests/missing.sh 29 | - os: linux 30 | dist: trusty 31 | name: "Zabbix 4.0 @ Ubuntu 14 trusty, PHP default" 32 | arch: amd64 33 | addons: 34 | apt: 35 | sources: 36 | - sourceline: 'deb http://repo.zabbix.com/zabbix/4.0/ubuntu trusty main' 37 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 38 | packages: 39 | - ca-certificates 40 | - curl 41 | - grep 42 | - sed 43 | - gawk 44 | - lsof 45 | - jq 46 | - libfcgi0ldbl 47 | - unzip 48 | - zabbix-agent 49 | - zabbix-get 50 | - php5-fpm 51 | before_script: 52 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 53 | - os: linux 54 | dist: xenial 55 | name: "Zabbix 4.0 @ Ubuntu 16 xenial, PHP default" 56 | arch: amd64 57 | addons: 58 | apt: 59 | sources: 60 | - sourceline: 'deb http://repo.zabbix.com/zabbix/4.0/ubuntu xenial main' 61 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 62 | packages: 63 | - ca-certificates 64 | - curl 65 | - grep 66 | - sed 67 | - gawk 68 | - lsof 69 | - jq 70 | - libfcgi0ldbl 71 | - unzip 72 | - zabbix-agent 73 | - zabbix-get 74 | - php-fpm 75 | before_script: 76 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 77 | - os: linux 78 | dist: bionic 79 | name: "Zabbix 4.0 @ Ubuntu 18 bionic, PHP default" 80 | arch: amd64 81 | addons: 82 | apt: 83 | sources: 84 | - sourceline: 'deb http://repo.zabbix.com/zabbix/4.0/ubuntu bionic main' 85 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 86 | packages: 87 | - bc 88 | - ca-certificates 89 | - curl 90 | - grep 91 | - sed 92 | - gawk 93 | - lsof 94 | - jq 95 | - libfcgi-bin 96 | - unzip 97 | - zabbix-agent 98 | - zabbix-get 99 | - php-fpm 100 | before_script: 101 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 102 | - os: linux 103 | dist: bionic 104 | name: "Zabbix 4.4 @ Ubuntu 18 bionic, PHP default" 105 | arch: amd64 106 | addons: 107 | apt: 108 | sources: 109 | - sourceline: 'deb http://repo.zabbix.com/zabbix/4.4/ubuntu bionic main' 110 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 111 | packages: 112 | - bc 113 | - ca-certificates 114 | - curl 115 | - grep 116 | - sed 117 | - gawk 118 | - lsof 119 | - jq 120 | - libfcgi-bin 121 | - unzip 122 | - zabbix-agent 123 | - zabbix-get 124 | - php-fpm 125 | before_script: 126 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 127 | - os: linux 128 | dist: bionic 129 | name: "Zabbix 5.0 @ Ubuntu 18 bionic, PHP default" 130 | arch: amd64 131 | addons: 132 | apt: 133 | sources: 134 | - sourceline: 'deb http://repo.zabbix.com/zabbix/5.0/ubuntu bionic main' 135 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 136 | packages: 137 | - bc 138 | - ca-certificates 139 | - curl 140 | - grep 141 | - sed 142 | - gawk 143 | - lsof 144 | - jq 145 | - libfcgi-bin 146 | - unzip 147 | - zabbix-agent 148 | - zabbix-get 149 | - php-fpm 150 | before_script: 151 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 152 | - os: linux 153 | dist: bionic 154 | name: "Zabbix 4.0 @ Ubuntu 18 bionic, PHP 7.0-7.4" 155 | arch: amd64 156 | addons: 157 | apt: 158 | sources: 159 | - sourceline: 'deb http://repo.zabbix.com/zabbix/4.0/ubuntu bionic main' 160 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 161 | - sourceline: 'ppa:ondrej/php' 162 | packages: 163 | - bc 164 | - ca-certificates 165 | - curl 166 | - grep 167 | - sed 168 | - gawk 169 | - lsof 170 | - jq 171 | - libfcgi-bin 172 | - unzip 173 | - zabbix-agent 174 | - zabbix-get 175 | - php7.0-fpm 176 | - php7.1-fpm 177 | - php7.2-fpm 178 | - php7.3-fpm 179 | - php7.4-fpm 180 | before_script: 181 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 182 | - os: linux 183 | dist: bionic 184 | name: "Zabbix 4.4 @ Ubuntu 18 bionic, PHP 7.0-7.4" 185 | arch: amd64 186 | addons: 187 | apt: 188 | sources: 189 | - sourceline: 'deb http://repo.zabbix.com/zabbix/4.4/ubuntu bionic main' 190 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 191 | - sourceline: 'ppa:ondrej/php' 192 | packages: 193 | - bc 194 | - ca-certificates 195 | - curl 196 | - grep 197 | - sed 198 | - gawk 199 | - lsof 200 | - jq 201 | - libfcgi-bin 202 | - unzip 203 | - zabbix-agent 204 | - zabbix-get 205 | - php7.0-fpm 206 | - php7.1-fpm 207 | - php7.2-fpm 208 | - php7.3-fpm 209 | - php7.4-fpm 210 | before_script: 211 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 212 | - os: linux 213 | dist: bionic 214 | name: "Zabbix 5.0 @ Ubuntu 18 bionic, PHP 7.0-7.4" 215 | arch: amd64 216 | addons: 217 | apt: 218 | sources: 219 | - sourceline: 'deb http://repo.zabbix.com/zabbix/5.0/ubuntu bionic main' 220 | key_url: "https://repo.zabbix.com/zabbix-official-repo.key" 221 | - sourceline: 'ppa:ondrej/php' 222 | packages: 223 | - bc 224 | - ca-certificates 225 | - curl 226 | - grep 227 | - sed 228 | - gawk 229 | - lsof 230 | - jq 231 | - libfcgi-bin 232 | - unzip 233 | - zabbix-agent 234 | - zabbix-get 235 | - php7.0-fpm 236 | - php7.1-fpm 237 | - php7.2-fpm 238 | - php7.3-fpm 239 | - php7.4-fpm 240 | before_script: 241 | - sudo curl -o /usr/local/bin/shunit2 https://raw.githubusercontent.com/kward/shunit2/master/shunit2 242 | 243 | script: bash tests/all.sh 244 | notifications: 245 | email: false 246 | env: 247 | - SH=bash 248 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-FPM Zabbix Template with Auto Discovery and Multiple Pools 2 | 3 | ![Zabbix versions](https://img.shields.io/badge/Zabbix_versions-5.0,_4.4,_4.2,_4.0-green.svg?style=flat) ![PHP](https://img.shields.io/badge/PHP-5.3.3+-blue.svg?style=flat) ![PHP7](https://img.shields.io/badge/PHP7-supported-green.svg?style=flat) ![LLD](https://img.shields.io/badge/LLD-yes-green.svg?style=flat) ![ISPConfig](https://img.shields.io/badge/ISPConfig-supported-green.svg?style=flat) ![Apache](https://img.shields.io/badge/Apache-tested-green.svg?style=flat) ![nginx](https://img.shields.io/badge/Nginx-tested-green.svg?style=flat) [![Build Status](https://travis-ci.com/rvalitov/zabbix-php-fpm.svg?branch=master)](https://travis-ci.com/rvalitov/zabbix-php-fpm) [![CodeFactor](https://www.codefactor.io/repository/github/rvalitov/zabbix-php-fpm/badge)](https://www.codefactor.io/repository/github/rvalitov/zabbix-php-fpm) 4 | 5 | ![Banner](https://github.com/rvalitov/zabbix-php-fpm/wiki/media/repository-open-graph-template.png) 6 | 7 | ## Main features 8 | 9 | - Provides auto discovery of PHP-FPM pools (LLD) 10 | - Detects pools that [listen](https://www.php.net/manual/en/install.fpm.configuration.php#listen) via socket and via TCP 11 | - Supported types of PHP [process manager](https://www.php.net/manual/en/install.fpm.configuration.php#pm): 12 | - [x] dynamic 13 | - [x] static 14 | - [x] ondemand. Such pools are invisible (undiscoverable) if they are not active because of their nature, i.e. when no PHP-FPM processes related to the pools spawned during the discovery process of Zabbix agent. After a pool has been discovered for the first time, it becomes permanently visible for Zabbix. Regular checks performed by Zabbix agent require at least one active PHP-FPM process that can report the status, and if such process does not exist, then it will be spawned. As a result, Zabbix agent will always report that there's at least one active PHP-FPM process for the pool. Besides, there's a chance that such behaviour may have a negative impact on the pool's performance and you may consider changing to another type of process manager, for example, dynamic. 15 | - Supports multiple PHP versions, i.e. you can use PHP 7.2 and PHP 7.3 on the same server and we will detect them all 16 | - Easy configuration 17 | - Supports [ISPConfig](https://www.ispconfig.org/) 18 | - Script is in pure `bash`: no need to install `Perl`, `Go` or other languages. 19 | 20 | ## Provided Items 21 | We capture only useful data from host and PHP-FPM status page: 22 | 23 | - Number of CPUs 24 | - For each pool: 25 | 26 | - **Accepted Connections Per Second** - the number of requests accepted by the pool 27 | - **Active Processes** - the number of active processes 28 | - **Idle Processes** - the number of idle processes 29 | - **Max Children Reached** – the number of times, the process limit has been reached, when pm tries to start more children (works only for pm `dynamic` and `ondemand`) 30 | - **CPU Utilization** - CPU load for all processes of the pool in % 31 | - **CPU Average Utilization** - CPU load for all processes of the pool in % normalized by number of CPUs 32 | - **Listen Queue** - the number of requests in the queue of pending connections 33 | - **Max Listen Queue** - the maximum number of requests in the queue of pending connections since FPM has started 34 | - **Listen Queue Length** - the size of the socket queue of pending connections. This value is defined by the [backlog](https://www.php.net/manual/en/install.fpm.configuration.php#listen-backlog) option in your pool's configuration. On Debian the length is always reported zero for pools that listen via socket. 35 | - **Queue Utilization** - queue usage in % 36 | - **Memory Used** - how much RAM used by the pool in bytes 37 | - **Memory Utilization** - how much RAM used by the pool in % 38 | - **Process Manager** - `dynamic`, `ondemand` or `static`, see [PHP manual](https://www.php.net/manual/en/install.fpm.configuration.php#pm). 39 | - **Slow Requests** - the number of requests that exceeded your [`request_slowlog_timeout`](https://www.php.net/manual/en/install.fpm.configuration.php#request-slowlog-timeout) value. 40 | - **Start Since** - number of seconds since FPM has started 41 | - **Start Time** - the date and time FPM has started 42 | 43 | History storage period is from 1 hour to 1 day (depends on specific item), trend storage period is 365 days that's optimal for environments with multiple websites. 44 | Data is captured every minute. These timings can be adjusted in template or per host if needed. 45 | 46 | ## Provided Triggers 47 | 48 | |Title|Severity|Description| 49 | |-----|--------|-----------| 50 | |Too many connections on pool|High|It means this pool is under high load. Please, make sure that your website is reachable and works as expected. For high load websites with huge amount of traffic please manually adjust this trigger to higher values (default is 500 concurrent connections). For websites with low or standard amount of visitors you may be under DDoS attack. Anyway, please, check the status of your server (CPU, memory utilization) to make sure that your server can handle this traffic and does not have performance issues.| 51 | |PHP-FPM uses too much memory|Average|Please, make sure that your server has sufficient resources to handle this pool, and check that the traffic of your website is not abnormal (check that your website is not under DDoS attack).| 52 | |PHP-FPM detected slow request|Warning|PHP-FPM detected slow request on pool. A slow request means that it took more time to execute than expected (defined in the configuration of your pool). It means that your pool has performance issues: either it is under high load, your pool has non-optimal configuration, your server has insufficient resources, or your PHP scripts have slow code (have bugs or bad programming style). You need to set [request_slowlog_timeout](https://www.php.net/manual/en/install.fpm.configuration.php#request-slowlog-timeout) and [slowlog](https://www.php.net/manual/en/install.fpm.configuration.php#slowlog) options in your pool's configuration if you want to use this trigger. Otherwise the trigger will never be fired.| 53 | |The queue utilization for pool reached 25%|Warning|The queue for this pool reached 25% of its maximum capacity. Items in queue represent the current number of connections that have been initiated on this pool, but not yet accepted. It typically means that all the available server processes are currently busy, and there are no processes available to serve the next request. Raising pm.max_children (provided the server can handle it) should help keep this number low. This trigger follows from the fact that PHP-FPM listens via a socket (TCP or file based), and thus inherits some of the characteristics of sockets. Low values of the listen queue generally result in performance issues of this pool. The queue length is defined by the [backlog option](https://www.php.net/manual/en/install.fpm.configuration.php#listen-backlog) in your pool's configuration.| 54 | |The queue utilization for pool reached 50%|Average|The queue for this pool reached 50% of its maximum capacity. Items in queue represent the current number of connections that have been initiated on this pool, but not yet accepted. It typically means that all the available server processes are currently busy, and there are no processes available to serve the next request. Raising pm.max_children (provided the server can handle it) should help keep this number low. This trigger follows from the fact that PHP-FPM listens via a socket (TCP or file based), and thus inherits some of the characteristics of sockets. This pool already has performance issues. Please, check that your server has enough resources and adjust the configuration of this pool to handle more concurrent requests, otherwise you can suffer serious degraded performance. The queue length is defined by the [backlog option](https://www.php.net/manual/en/install.fpm.configuration.php#listen-backlog) in your pool's configuration.| 55 | |The queue utilization for pool reached 85%|High|The queue for this pool reached 85% of its maximum capacity. Items in queue represent the current number of connections that have been initiated on this pool, but not yet accepted. It typically means that all the available server processes are currently busy, and there are no processes available to serve the next request. Raising pm.max_children (provided the server can handle it) should help keep this number low. This trigger follows from the fact that PHP-FPM listens via a socket (TCP or file based), and thus inherits some of the characteristics of sockets. This pool already has serious performance issues. Please, check that your server has enough resources and adjust the configuration of this pool to handle more concurrent requests, otherwise you can face severe errors when new requests can't be processed and will be rejected generating errors such as HTTP 500. The queue length is defined by the [backlog option](https://www.php.net/manual/en/install.fpm.configuration.php#listen-backlog) in your pool's configuration.| 56 | |PHP-FPM manager changed|Information|The [process manager](https://www.php.net/manual/en/install.fpm.configuration.php#pm) of PHP-FPM for this pool has changed.| 57 | 58 | ## Provided Graphs 59 | #### Connections 60 | ![Zabbix PHP-FPM connections graph](https://github.com/rvalitov/zabbix-php-fpm/wiki/media/demo-connections.png) 61 | 62 | Displays the following data: 63 | 64 | - Accepted connections per second 65 | - CPU average utilization in % 66 | - Memory utilization in % 67 | - Queue utilization in % 68 | 69 | #### CPU 70 | ![Zabbix PHP-FPM CPU utilization graph](https://github.com/rvalitov/zabbix-php-fpm/wiki/media/demo-cpu.png) 71 | 72 | Displays the following data: 73 | 74 | - CPU average utilization in % 75 | - Accepted connections per second 76 | 77 | #### Memory 78 | ![Zabbix PHP-FPM RAM utilization graph](https://github.com/rvalitov/zabbix-php-fpm/wiki/media/demo-memory.png) 79 | 80 | Displays the following data: 81 | 82 | - Memory used in bytes 83 | - CPU average utilization in % 84 | - Memory utilization in % 85 | - Queue utilization in % 86 | 87 | #### Process 88 | ![Zabbix PHP-FPM CPU utilization graph](https://github.com/rvalitov/zabbix-php-fpm/wiki/media/demo-process.png) 89 | 90 | Displays the following data: 91 | 92 | - Active processes 93 | - Idle processes 94 | - Accepted connections per second 95 | 96 | #### Queue 97 | Displays the following data: 98 | 99 | - Listen Queue 100 | 101 | #### Max Children Reached 102 | Displays the following data: 103 | 104 | - Max Children Reached 105 | - Accepted connections per second 106 | 107 | ## Provided Screens 108 | Screens are based on the graphs above: 109 | 110 | - Connections 111 | - Processes 112 | - CPU utilization 113 | - Memory utilization 114 | - Queue 115 | - Max children reached 116 | 117 | ![Zabbix screens example](https://github.com/rvalitov/zabbix-php-fpm/wiki/media/zabbix-screens.jpg) 118 | 119 | # Installation and configuration 120 | Please refer to [Wiki](https://github.com/rvalitov/zabbix-php-fpm/wiki/Installation). 121 | 122 | # Testing and Troubleshooting 123 | Please refer to [Wiki](https://github.com/rvalitov/zabbix-php-fpm/wiki/Testing-and-Troubleshooting). 124 | 125 | # Compatibility 126 | 127 | ### System requirements 128 | 129 | - **PHP**. Should work with any version of PHP-FPM (starting with PHP 5.3.3) 130 | - **Zabbix** 4.0.x and later. 131 | - **ISPConfig**. Can work with any version of ISPConfig as long as you have a valid PHP-FPM status page configuration there. 132 | - Minimal `bash` version 4. 133 | - **OS** 134 | - **Debian** 8 Jessie or newer 135 | - **Ubuntu** 20 Focal, 18 Bionic, 16 Xenial, 14 Trusty. Other versions are supported if they are present in the [Zabbix repository](http://repo.zabbix.com/zabbix/4.0/ubuntu/dists/). 136 | - **CentOS** 6 or newer 137 | - **RHEL** 5 or newer 138 | 139 | ### Tested with: 140 | 141 | - [**Travis CI**](https://travis-ci.com/rvalitov/zabbix-php-fpm) 142 | - **PHP** 7.4, 7.3, 7.2, 7.1, 7.0 143 | - **Zabbix** 5.0.1, 4.4.4, 4.2.5, 4.0.20, 4.0.16, 4.0.4 144 | - **Debian** 10, 9 145 | - **Ubuntu** 18 Bionic, 16 Xenial, 14 Trusty 146 | - **CentOS** 7 147 | - [**Apache** web server](https://httpd.apache.org/) 148 | - [**NGINX** web server](https://www.nginx.com/) 149 | - [**ISPConfig**](https://www.ispconfig.org/) 3.1.14p2, 3.1.15p3 150 | -------------------------------------------------------------------------------- /ispconfig/nginx_vhost.conf.master: -------------------------------------------------------------------------------- 1 | server { 2 | listen :; 3 | 4 | listen []:; 5 | 6 | 7 | listen [::]:; 8 | 9 | 10 | listen : ssl{tmpl_if name='enable_http2' op='==' value='y'} http2{/tmpl_if}{tmpl_if name='enable_spdy' op='==' value='y'} spdy{/tmpl_if}; 11 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 12 | # ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; 13 | # ssl_prefer_server_ciphers on; 14 | 15 | listen []: ssl{tmpl_if name='enable_http2' op='==' value='y'} http2{/tmpl_if}{tmpl_if name='enable_spdy' op='==' value='y'} spdy{/tmpl_if}; 16 | 17 | 18 | listen [::]: ssl{tmpl_if name='enable_http2' op='==' value='y'} http2{/tmpl_if}{tmpl_if name='enable_spdy' op='==' value='y'} spdy{/tmpl_if}; 19 | 20 | ssl_certificate ; 21 | ssl_certificate_key ; 22 | 23 | 24 | server_name ; 25 | 26 | root ; 27 | 28 | 29 | 30 | if ($scheme != "https") { 31 | rewrite ^ https://$http_host$request_uri? permanent; 32 | } 33 | 34 | 35 | 36 | if ($http_host "") { 37 | rewrite ^ $scheme://$request_uri? permanent; 38 | } 39 | 40 | 41 | if ($http_host "") { 42 | rewrite ^ $scheme://$request_uri? permanent; 43 | } 44 | 45 | 46 | if ($http_host "") { 47 | rewrite ^(.*)$ $2 ; 48 | } 49 | 50 | 51 | 52 | 53 | if ($http_host != "") { rewrite ^(.*)$ $2 ; } 54 | 55 | 56 | location / { 57 | proxy_pass ; 58 | rewrite ^/(.*) /$1; 59 | 60 | 61 | 62 | } 63 | 64 | 65 | 66 | index index.html index.htm index.php index.cgi index.pl index.xhtml; 67 | 68 | 69 | location ~ \.shtml$ { 70 | ssi on; 71 | } 72 | 73 | 74 | 75 | error_page 400 /error/400.html; 76 | error_page 401 /error/401.html; 77 | error_page 403 /error/403.html; 78 | error_page 404 /error/404.html; 79 | error_page 405 /error/405.html; 80 | error_page 500 /error/500.html; 81 | error_page 502 /error/502.html; 82 | error_page 503 /error/503.html; 83 | recursive_error_pages on; 84 | location = /error/400.html { 85 | 86 | internal; 87 | } 88 | location = /error/401.html { 89 | 90 | internal; 91 | } 92 | location = /error/403.html { 93 | 94 | internal; 95 | } 96 | location = /error/404.html { 97 | 98 | internal; 99 | } 100 | location = /error/405.html { 101 | 102 | internal; 103 | } 104 | location = /error/500.html { 105 | 106 | internal; 107 | } 108 | location = /error/502.html { 109 | 110 | internal; 111 | } 112 | location = /error/503.html { 113 | 114 | internal; 115 | } 116 | 117 | 118 | 119 | error_log /var/log/ispconfig/httpd//error.log; 120 | access_log /var/log/ispconfig/httpd//access.log combined; 121 | 122 | 123 | error_log /var/log/ispconfig/httpd//error.log; 124 | access_log /var/log/ispconfig/httpd//access.log anonymized; 125 | 126 | 127 | ## Disable .htaccess and other hidden files 128 | location ~ /\. { 129 | deny all; 130 | } 131 | 132 | ## Allow access for .well-known/acme-challenge 133 | location ^~ /.well-known/acme-challenge/ { 134 | access_log off; 135 | log_not_found off; 136 | auth_basic off; 137 | root /usr/local/ispconfig/interface/acme/; 138 | autoindex off; 139 | index index.html; 140 | try_files $uri $uri/ =404; 141 | } 142 | 143 | location = /favicon.ico { 144 | log_not_found off; 145 | access_log off; 146 | expires max; 147 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 148 | } 149 | 150 | location = /robots.txt { 151 | allow all; 152 | log_not_found off; 153 | access_log off; 154 | } 155 | 156 | location /stats/ { 157 | 158 | index index.html index.php; 159 | auth_basic "Members Only"; 160 | auth_basic_user_file ; 161 | } 162 | 163 | location ^~ /awstats-icon { 164 | alias /usr/share/awstats/icon; 165 | } 166 | 167 | location ~ (\.php|^/php-fpm-status)$ { 168 | try_files @php; 169 | } 170 | 171 | 172 | location @php { 173 | try_files $uri =404; 174 | include /etc/nginx/fastcgi_params; 175 | 176 | fastcgi_pass 127.0.0.1:; 177 | 178 | 179 | fastcgi_pass unix:; 180 | 181 | fastcgi_index index.php; 182 | 183 | fastcgi_param DOCUMENT_ROOT ; 184 | fastcgi_param HOME ; 185 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 186 | 187 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 188 | 189 | #fastcgi_param PATH_INFO $fastcgi_script_name; 190 | fastcgi_intercept_errors on; 191 | } 192 | 193 | 194 | location @php { 195 | try_files $uri =404; 196 | include /etc/nginx/fastcgi_params; 197 | fastcgi_pass unix:/var/run/hhvm/hhvm..sock; 198 | fastcgi_index index.php; 199 | 200 | fastcgi_param DOCUMENT_ROOT ; 201 | fastcgi_param HOME ; 202 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 203 | 204 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 205 | 206 | #fastcgi_param PATH_INFO $fastcgi_script_name; 207 | fastcgi_intercept_errors on; 208 | error_page 500 501 502 503 = @phpfallback; 209 | } 210 | 211 | location @phpfallback { 212 | try_files $uri =404; 213 | include /etc/nginx/fastcgi_params; 214 | 215 | fastcgi_pass 127.0.0.1:; 216 | 217 | 218 | fastcgi_pass unix:; 219 | 220 | fastcgi_index index.php; 221 | 222 | fastcgi_param DOCUMENT_ROOT ; 223 | fastcgi_param HOME ; 224 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 225 | 226 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 227 | 228 | #fastcgi_param PATH_INFO $fastcgi_script_name; 229 | fastcgi_intercept_errors on; 230 | } 231 | 232 | 233 | location @php { 234 | deny all; 235 | } 236 | 237 | 238 | 239 | 240 | location /cgi-bin/ { 241 | try_files $uri =404; 242 | include /etc/nginx/fastcgi_params; 243 | root ; 244 | gzip off; 245 | fastcgi_pass unix:/var/run/fcgiwrap.socket; 246 | fastcgi_index index.cgi; 247 | 248 | fastcgi_param DOCUMENT_ROOT ; 249 | fastcgi_param HOME ; 250 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 251 | 252 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 253 | 254 | fastcgi_intercept_errors on; 255 | } 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | pagespeed on; 268 | pagespeed FileCachePath /var/ngx_pagespeed_cache; 269 | pagespeed FetchHttps enable,allow_self_signed; 270 | 271 | 272 | # let's speed up PageSpeed by storing it in the super duper fast memcached 273 | pagespeed MemcachedThreads 1; 274 | pagespeed MemcachedServers "localhost:11211"; 275 | 276 | # Filter settings 277 | pagespeed RewriteLevel CoreFilters; 278 | pagespeed EnableFilters collapse_whitespace,remove_comments; 279 | 280 | # Ensure requests for pagespeed optimized resources go to the pagespeed 281 | # handler and no extraneous headers get set. 282 | location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { 283 | add_header "" ""; 284 | access_log off; 285 | } 286 | location ~ "^/ngx_pagespeed_static/" { 287 | access_log off; 288 | } 289 | location ~ "^/ngx_pagespeed_beacon$" { 290 | access_log off; 291 | } 292 | location /ngx_pagespeed_statistics { 293 | allow 127.0.0.1; 294 | deny all; 295 | access_log off; 296 | } 297 | location /ngx_pagespeed_global_statistics { 298 | allow 127.0.0.1; 299 | deny all; 300 | access_log off; 301 | } 302 | location /ngx_pagespeed_message { 303 | allow 127.0.0.1; 304 | deny all; 305 | access_log off; 306 | } 307 | location /pagespeed_console { 308 | allow 127.0.0.1; 309 | deny all; 310 | access_log off; 311 | } 312 | 313 | 314 | 315 | location { ##merge## 316 | auth_basic "Members Only"; 317 | auth_basic_user_file .htpasswd; 318 | 319 | location ~ \.php$ { 320 | try_files @php; 321 | } 322 | } 323 | 324 | 325 | } 326 | 327 | 328 | server { 329 | listen :80; 330 | 331 | listen []:80; 332 | 333 | 334 | 335 | listen :443 ssl; 336 | 337 | listen []:443 ssl; 338 | 339 | ssl_certificate ; 340 | ssl_certificate_key ; 341 | 342 | 343 | server_name ; 344 | 345 | 346 | 347 | if ($http_host "") { 348 | rewrite ^ $scheme://$request_uri? permanent; 349 | } 350 | 351 | 352 | ## no redirect for acme 353 | location ^~ /.well-known/acme-challenge/ { 354 | access_log off; 355 | log_not_found off; 356 | root /usr/local/ispconfig/interface/acme/; 357 | autoindex off; 358 | index index.html; 359 | try_files $uri $uri/ =404; 360 | } 361 | 362 | location / { 363 | rewrite ^ $request_uri? ; 364 | } 365 | 366 | 367 | location / { 368 | proxy_pass ; 369 | rewrite ^/(.*) /$1; 370 | 371 | 372 | 373 | } 374 | 375 | } 376 | 377 | -------------------------------------------------------------------------------- /zabbix/zabbix_php_fpm_discovery.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Ramil Valitov ramilvalitov@gmail.com 3 | #https://github.com/rvalitov/zabbix-php-fpm 4 | #This script scans local machine for active PHP-FPM pools and returns them as a list in JSON format 5 | 6 | # This parameter is used to limit the execution time of this script. 7 | # Zabbix allows us to use a script that runs no more than 3 seconds by default. This option can be adjusted in settings: 8 | # see Timeout option https://www.zabbix.com/forum/zabbix-help/1284-server-agentd-timeout-parameter-in-config 9 | # So, we need to stop and save our state in case we need more time to run. 10 | # This parameter sets the maximum number of milliseconds that the script is allowed to run. 11 | # After this duration is reached, the script will stop running and save its state. 12 | # So, the actual execution time will be slightly more than this parameter. 13 | # We put value equivalent to 1.5 seconds here. 14 | MAX_EXECUTION_TIME="1500" 15 | 16 | #Status path used in calls to PHP-FPM 17 | STATUS_PATH="/php-fpm-status" 18 | 19 | #Debug mode is disabled by default 20 | DEBUG_MODE="" 21 | 22 | #Use sleep for testing timeouts, disabled by default. Can be used for testing & debugging 23 | USE_SLEEP_TIMEOUT="" 24 | 25 | #Sleep timeout in seconds 26 | SLEEP_TIMEOUT="0.5" 27 | 28 | #Parent directory where all cache files are located in the OS 29 | CACHE_ROOT="/var/cache" 30 | 31 | #Name of the private directory to store the cache files 32 | CACHE_DIR_NAME="zabbix-php-fpm" 33 | 34 | #Full path to directory to store cache files 35 | CACHE_DIRECTORY="$CACHE_ROOT/$CACHE_DIR_NAME" 36 | 37 | #Checking all the required executables 38 | S_PS=$(type -P ps) 39 | S_GREP=$(type -P grep) 40 | S_AWK=$(type -P awk) 41 | S_SORT=$(type -P sort) 42 | S_UNIQ=$(type -P uniq) 43 | S_HEAD=$(type -P head) 44 | S_LSOF=$(type -P lsof) 45 | S_JQ=$(type -P jq) 46 | S_DIRNAME=$(type -P dirname) 47 | S_CAT=$(type -P cat) 48 | S_BASH=$(type -P bash) 49 | S_PRINTF=$(type -P printf) 50 | S_WHOAMI=$(type -P whoami) 51 | S_DATE=$(type -P date) 52 | S_BC=$(type -P bc) 53 | S_SLEEP=$(type -P sleep) 54 | S_FCGI=$(type -P cgi-fcgi) 55 | 56 | if [[ ! -x $S_PS ]]; then 57 | echo "Utility 'ps' not found. Please, install it first." 58 | exit 1 59 | fi 60 | if [[ ! -x $S_GREP ]]; then 61 | echo "Utility 'grep' not found. Please, install it first." 62 | exit 1 63 | fi 64 | if [[ ! -x $S_AWK ]]; then 65 | echo "Utility 'awk' not found. Please, install it first." 66 | exit 1 67 | fi 68 | if [[ ! -x $S_SORT ]]; then 69 | echo "Utility 'sort' not found. Please, install it first." 70 | exit 1 71 | fi 72 | if [[ ! -x $S_UNIQ ]]; then 73 | echo "Utility 'uniq' not found. Please, install it first." 74 | exit 1 75 | fi 76 | if [[ ! -x $S_HEAD ]]; then 77 | echo "Utility 'head' not found. Please, install it first." 78 | exit 1 79 | fi 80 | if [[ ! -x $S_LSOF ]]; then 81 | echo "Utility 'lsof' not found. Please, install it first." 82 | exit 1 83 | fi 84 | if [[ ! -x $S_JQ ]]; then 85 | echo "Utility 'jq' not found. Please, install it first." 86 | exit 1 87 | fi 88 | if [[ ! -x ${S_DIRNAME} ]]; then 89 | echo "Utility 'dirname' not found. Please, install it first." 90 | exit 1 91 | fi 92 | if [[ ! -x ${S_CAT} ]]; then 93 | echo "Utility 'cat' not found. Please, install it first." 94 | exit 1 95 | fi 96 | if [[ ! -x ${S_BASH} ]]; then 97 | echo "Utility 'bash' not found. Please, install it first." 98 | exit 1 99 | fi 100 | if [[ ! -x ${S_PRINTF} ]]; then 101 | echo "Utility 'printf' not found. Please, install it first." 102 | exit 1 103 | fi 104 | if [[ ! -x ${S_WHOAMI} ]]; then 105 | echo "Utility 'whoami' not found. Please, install it first." 106 | exit 1 107 | fi 108 | if [[ ! -x ${S_DATE} ]]; then 109 | echo "Utility 'date' not found. Please, install it first." 110 | exit 1 111 | fi 112 | if [[ ! -x $S_BC ]]; then 113 | echo "Utility 'bc' not found. Please, install it first." 114 | exit 1 115 | fi 116 | if [[ ! -x $S_SLEEP ]]; then 117 | echo "Utility 'sleep' not found. Please, install it first." 118 | exit 1 119 | fi 120 | if [[ ! -x $S_FCGI ]]; then 121 | echo "Utility 'cgi-fcgi' not found. Please, install it first." 122 | exit 1 123 | fi 124 | 125 | if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then 126 | ${S_ECHO} "This script requires bash version 4.x or newer. Older version detected." 127 | exit 1 128 | fi 129 | 130 | if [[ ! -d "$CACHE_ROOT" ]]; then 131 | ${S_ECHO} "The OS cache directory '$CACHE_ROOT' not found in the system." 132 | exit 1 133 | fi 134 | 135 | USER_ID=$(id -u) 136 | if [[ $USER_ID -ne 0 ]]; then 137 | echo "Insufficient privileges. This script must be run under 'root' user or with 'sudo'." 138 | exit 1 139 | fi 140 | 141 | function createCacheDirectory() { 142 | if [[ ! -d "$CACHE_DIRECTORY" ]]; then 143 | mkdir "$CACHE_DIRECTORY" 144 | fi 145 | if [[ ! -d "$CACHE_DIRECTORY" ]]; then 146 | return 1 147 | fi 148 | 149 | chmod 700 "$CACHE_DIRECTORY" 150 | return 0 151 | } 152 | 153 | createCacheDirectory 154 | EXIT_CODE=$? 155 | if [[ ${EXIT_CODE} -ne 0 ]]; then 156 | ${S_ECHO} "Failed to create cache directory '$CACHE_DIRECTORY'." 157 | exit 1 158 | fi 159 | 160 | #Local directory 161 | LOCAL_DIR=$(${S_DIRNAME} "$0") 162 | 163 | #Cache file for pending pools, used to store execution state 164 | #File format: 165 | # 166 | PENDING_FILE="$CACHE_DIRECTORY/php_fpm_pending.cache" 167 | 168 | #Cache file with list of active pools, used to store execution state 169 | #File format: 170 | # 171 | RESULTS_CACHE_FILE="$CACHE_DIRECTORY/php_fpm_results.cache" 172 | 173 | #Path to status script, another script of this bundle 174 | STATUS_SCRIPT="$LOCAL_DIR/zabbix_php_fpm_status.sh" 175 | 176 | #Start time of the script 177 | START_TIME=$($S_DATE +%s%N) 178 | 179 | ACTIVE_USER=$(${S_WHOAMI}) 180 | 181 | # Prints a string on screen. Works only if debug mode is enabled. 182 | function PrintDebug() { 183 | if [[ -n $DEBUG_MODE ]] && [[ -n $1 ]]; then 184 | echo "$1" 185 | fi 186 | } 187 | 188 | # Encodes input data to JSON and saves it to result string 189 | # Input arguments: 190 | # - pool name 191 | # - pool socket 192 | # Function returns 1 if all OK, and 0 otherwise. 193 | function EncodeToJson() { 194 | local POOL_NAME=$1 195 | local POOL_SOCKET=$2 196 | if [[ -z ${POOL_NAME} ]] || [[ -z ${POOL_SOCKET} ]]; then 197 | return 0 198 | fi 199 | 200 | local JSON_POOL 201 | JSON_POOL=$(echo -n "$POOL_NAME" | ${S_JQ} -aR .) 202 | local JSON_SOCKET 203 | JSON_SOCKET=$(echo -n "$POOL_SOCKET" | ${S_JQ} -aR .) 204 | if [[ ${POOL_FIRST} == 1 ]]; then 205 | RESULT_DATA="$RESULT_DATA," 206 | fi 207 | RESULT_DATA="$RESULT_DATA{\"{#POOLNAME}\":$JSON_POOL,\"{#POOLSOCKET}\":$JSON_SOCKET}" 208 | POOL_FIRST=1 209 | return 1 210 | } 211 | 212 | # Updates information about the pool in cache. 213 | # Input arguments: 214 | # - pool name 215 | # - pool socket 216 | # - pool type 217 | function UpdatePoolInCache() { 218 | local POOL_NAME=$1 219 | local POOL_SOCKET=$2 220 | local POOL_TYPE=$3 221 | local UNSET_USED="" 222 | 223 | if [[ -z $POOL_NAME ]] || [[ -z $POOL_SOCKET ]] || [[ -z $POOL_TYPE ]]; then 224 | PrintDebug "Error: Invalid arguments for UpdatePoolInCache" 225 | return 0 226 | fi 227 | 228 | for ITEM_INDEX in "${!CACHE[@]}"; do 229 | local CACHE_ITEM="${CACHE[$ITEM_INDEX]}" 230 | 231 | local ITEM_NAME 232 | # shellcheck disable=SC2016 233 | ITEM_NAME=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $1}') 234 | 235 | local ITEM_SOCKET 236 | # shellcheck disable=SC2016 237 | ITEM_SOCKET=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $2}') 238 | 239 | local ITEM_POOL_TYPE 240 | # shellcheck disable=SC2016 241 | ITEM_POOL_TYPE=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $3}') 242 | if [[ $ITEM_NAME == "$POOL_NAME" && $ITEM_SOCKET == "$POOL_SOCKET" ]] || [[ -z $ITEM_POOL_TYPE ]]; then 243 | PrintDebug "Pool $POOL_NAME $POOL_SOCKET is in cache, deleting..." 244 | #Deleting the pool first 245 | unset "CACHE[$ITEM_INDEX]" 246 | UNSET_USED="1" 247 | fi 248 | done 249 | 250 | if [[ -n "$UNSET_USED" ]]; then 251 | #Renumber the indexes 252 | CACHE=("${CACHE[@]}") 253 | fi 254 | 255 | CACHE+=("$POOL_NAME $POOL_SOCKET $POOL_TYPE") 256 | PrintDebug "Added pool $POOL_NAME $POOL_SOCKET to cache list" 257 | return 0 258 | } 259 | 260 | # Removes pools from cache that are currently inactive and are missing in pending list 261 | function UpdateCacheList() { 262 | local UNSET_USED="" 263 | 264 | for ITEM_INDEX in "${!CACHE[@]}"; do 265 | local CACHE_ITEM="${CACHE[$ITEM_INDEX]}" 266 | 267 | local ITEM_NAME 268 | # shellcheck disable=SC2016 269 | ITEM_NAME=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $1}') 270 | 271 | local ITEM_SOCKET 272 | # shellcheck disable=SC2016 273 | ITEM_SOCKET=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $2}') 274 | 275 | local ITEM_POOL_TYPE 276 | # shellcheck disable=SC2016 277 | ITEM_POOL_TYPE=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $3}') 278 | 279 | if [[ $ITEM_NAME == "$POOL_NAME" && $ITEM_SOCKET == "$POOL_SOCKET" ]] || [[ -z $ITEM_POOL_TYPE ]]; then 280 | PrintDebug "Pool $POOL_NAME $POOL_SOCKET is in cache, deleting..." 281 | #Deleting the pool first 282 | unset "CACHE[$ITEM_INDEX]" 283 | UNSET_USED="1" 284 | fi 285 | done 286 | 287 | if [[ -n "$UNSET_USED" ]]; then 288 | #Renumber the indexes 289 | CACHE=("${CACHE[@]}") 290 | fi 291 | } 292 | 293 | # Checks if selected pool is in pending list 294 | # Function returns 1 if pool is in list, and 0 otherwise 295 | function IsInPendingList() { 296 | local POOL_NAME=$1 297 | local POOL_SOCKET=$2 298 | 299 | if [[ -z $POOL_NAME ]] || [[ -z $POOL_SOCKET ]]; then 300 | PrintDebug "Error: Invalid arguments for IsInPendingList" 301 | return 0 302 | fi 303 | 304 | for ITEM in "${PENDING_LIST[@]}"; do 305 | if [[ "$ITEM" == "$POOL_NAME $POOL_SOCKET" ]]; then 306 | return 1 307 | fi 308 | done 309 | return 0 310 | } 311 | 312 | # Adds a pool to the pending list 313 | # The pool is added only if it's not already in the list. 314 | # A new pool is added to the end of the list. 315 | # Function returns 1, if a pool was added, and 0 otherwise. 316 | function AddPoolToPendingList() { 317 | local POOL_NAME=$1 318 | local POOL_SOCKET=$2 319 | 320 | if [[ -z $POOL_NAME ]] || [[ -z $POOL_SOCKET ]]; then 321 | PrintDebug "Error: Invalid arguments for AddPoolToPendingList" 322 | return 0 323 | fi 324 | 325 | IsInPendingList "$POOL_NAME" "$POOL_SOCKET" 326 | local FOUND=$? 327 | 328 | if [[ ${FOUND} == 1 ]]; then 329 | #Already in list, quit 330 | PrintDebug "Pool $POOL_NAME $POOL_SOCKET is already in pending list" 331 | return 0 332 | fi 333 | 334 | #Otherwise add this pool to the end of the list 335 | PENDING_LIST+=("$POOL_NAME $POOL_SOCKET") 336 | PrintDebug "Added pool $POOL_NAME $POOL_SOCKET to pending list" 337 | return 1 338 | } 339 | 340 | # Removes a pool from pending list 341 | # Returns 1 if success, 0 otherwise 342 | function DeletePoolFromPendingList() { 343 | local POOL_NAME=$1 344 | local POOL_SOCKET=$2 345 | local UNSET_USED="" 346 | 347 | if [[ -z $POOL_NAME ]] || [[ -z $POOL_SOCKET ]]; then 348 | PrintDebug "Error: Invalid arguments for DeletePoolFromPendingList" 349 | return 0 350 | fi 351 | 352 | for ITEM_INDEX in "${!PENDING_LIST[@]}"; do 353 | local PENDING_ITEM="${PENDING_LIST[$ITEM_INDEX]}" 354 | if [[ "$PENDING_ITEM" == "$POOL_NAME $POOL_SOCKET" ]]; then 355 | unset "PENDING_LIST[$ITEM_INDEX]" 356 | UNSET_USED="1" 357 | fi 358 | done 359 | 360 | if [[ -z "$UNSET_USED" ]]; then 361 | #Not in list, quit 362 | PrintDebug "Error: Pool $POOL_NAME $POOL_SOCKET is already missing in pending list" 363 | return 0 364 | fi 365 | 366 | #Renumber the indexes 367 | PENDING_LIST=("${PENDING_LIST[@]}") 368 | PrintDebug "Removed pool $POOL_NAME $POOL_SOCKET from pending list" 369 | return 1 370 | } 371 | 372 | function SavePrintResults() { 373 | #Checking and creating cache directory just in case: 374 | createCacheDirectory 375 | 376 | #Saving pending list: 377 | if [[ -f $PENDING_FILE ]] && [[ ! -w $PENDING_FILE ]]; then 378 | echo "Error: write permission is not granted to user $ACTIVE_USER for cache file $PENDING_FILE" 379 | exit 1 380 | fi 381 | 382 | PrintDebug "Saving pending pools list to file $PENDING_FILE..." 383 | ${S_PRINTF} "%s\n" "${PENDING_LIST[@]}" >"$PENDING_FILE" 384 | 385 | #We must sort the cache list 386 | readarray -t CACHE < <(for a in "${CACHE[@]}"; do echo "$a"; done | $S_SORT) 387 | 388 | if [[ -n $DEBUG_MODE ]]; then 389 | PrintDebug "List of pools to be saved to cache pools file:" 390 | PrintCacheList 391 | fi 392 | 393 | if [[ -f $RESULTS_CACHE_FILE ]] && [[ ! -w $RESULTS_CACHE_FILE ]]; then 394 | echo "Error: write permission is not granted to user $ACTIVE_USER for cache file $RESULTS_CACHE_FILE" 395 | exit 1 396 | fi 397 | 398 | PrintDebug "Saving cache file to file $RESULTS_CACHE_FILE..." 399 | ${S_PRINTF} "%s\n" "${CACHE[@]}" >"$RESULTS_CACHE_FILE" 400 | 401 | POOL_FIRST=0 402 | #We store the resulting JSON data for Zabbix in the following var: 403 | RESULT_DATA="{\"data\":[" 404 | 405 | for CACHE_ITEM in "${CACHE[@]}"; do 406 | local ITEM_NAME 407 | # shellcheck disable=SC2016 408 | ITEM_NAME=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $1}') 409 | 410 | local ITEM_SOCKET 411 | # shellcheck disable=SC2016 412 | ITEM_SOCKET=$(echo "$CACHE_ITEM" | ${S_AWK} '{print $2}') 413 | EncodeToJson "${ITEM_NAME}" "${ITEM_SOCKET}" 414 | done 415 | 416 | RESULT_DATA="$RESULT_DATA]}" 417 | PrintDebug "Resulting JSON data for Zabbix:" 418 | echo -n "$RESULT_DATA" 419 | } 420 | 421 | function CheckExecutionTime() { 422 | local CURRENT_TIME 423 | CURRENT_TIME=$($S_DATE +%s%N) 424 | 425 | local ELAPSED_TIME 426 | ELAPSED_TIME=$(echo "($CURRENT_TIME - $START_TIME)/1000000" | $S_BC) 427 | if [[ $ELAPSED_TIME -lt $MAX_EXECUTION_TIME ]]; then 428 | #All good, we can continue 429 | PrintDebug "Check execution time OK, elapsed $ELAPSED_TIME ms" 430 | return 1 431 | fi 432 | 433 | #We need to save our state and exit 434 | PrintDebug "Check execution time: stop required, elapsed $ELAPSED_TIME ms" 435 | 436 | SavePrintResults 437 | 438 | exit 0 439 | } 440 | 441 | # Validates the specified pool by getting its status and working with cache. 442 | # Pass two arguments: pool name and pool socket 443 | # Function returns: 444 | # 0 if the pool is invalid 445 | # 1 if the pool is OK 446 | function CheckPool() { 447 | local POOL_NAME=$1 448 | local POOL_SOCKET=$2 449 | if [[ -z ${POOL_NAME} ]] || [[ -z ${POOL_SOCKET} ]]; then 450 | PrintDebug "Error: Invalid arguments for CheckPool" 451 | return 0 452 | fi 453 | 454 | local STATUS_JSON 455 | STATUS_JSON=$(${S_BASH} "${STATUS_SCRIPT}" "${POOL_SOCKET}" ${STATUS_PATH}) 456 | local EXIT_CODE=$? 457 | if [[ ${EXIT_CODE} == 0 ]]; then 458 | # The exit code is OK, let's check the JSON data 459 | # JSON data example: 460 | # {"pool":"www2","process manager":"ondemand","start time":1578181845,"start since":117,"accepted conn":3,"listen queue":0,"max listen queue":0,"listen queue len":0,"idle processes":0,"active processes":1,"total processes":1,"max active processes":1,"max children reached":0,"slow requests":0} 461 | # We use basic regular expression here, i.e. we need to use \+ and not escape { and } 462 | if [[ -n $(echo "${STATUS_JSON}" | ${S_GREP} -G '^{.*\"pool\":\".\+\".*,\"process manager\":\".\+\".*}$') ]]; then 463 | PrintDebug "Status data for pool $POOL_NAME, socket $POOL_SOCKET, status path $STATUS_PATH is valid" 464 | 465 | local PROCESS_MANAGER 466 | PROCESS_MANAGER=$(echo "$STATUS_JSON" | $S_GREP -oP '"process manager":"\K([a-z]+)') 467 | if [[ -n $PROCESS_MANAGER ]]; then 468 | PrintDebug "Detected pool's process manager is $PROCESS_MANAGER" 469 | UpdatePoolInCache "$POOL_NAME" "$POOL_SOCKET" "$PROCESS_MANAGER" 470 | return 1 471 | else 472 | PrintDebug "Error: Failed to detect process manager of the pool" 473 | fi 474 | fi 475 | 476 | PrintDebug "Failed to validate status data for pool $POOL_NAME, socket $POOL_SOCKET, status path $STATUS_PATH" 477 | if [[ -n ${STATUS_JSON} ]]; then 478 | PrintDebug "Status script returned: $STATUS_JSON" 479 | fi 480 | return 0 481 | fi 482 | PrintDebug "Failed to get status for pool $POOL_NAME, socket $POOL_SOCKET, status path $STATUS_PATH" 483 | if [[ -n ${STATUS_JSON} ]]; then 484 | PrintDebug "Status script returned: $STATUS_JSON" 485 | fi 486 | return 0 487 | } 488 | 489 | #Sleeps for a specified predefined amount of time. Works only if "sleep mode" is enabled. 490 | function sleepNow() { 491 | if [[ -n $USE_SLEEP_TIMEOUT ]]; then 492 | PrintDebug "Debug: Sleep for $SLEEP_TIMEOUT sec" 493 | $S_SLEEP "$SLEEP_TIMEOUT" 494 | CheckExecutionTime 495 | fi 496 | } 497 | 498 | # Analysis of pool by name, scans the processes, and adds them to pending list for further checks 499 | function AnalyzePool() { 500 | local POOL_NAME=$1 501 | if [[ -z ${POOL_NAME} ]]; then 502 | PrintDebug "Invalid arguments for AnalyzePool" 503 | return 0 504 | fi 505 | 506 | local POOL_PID_LIST 507 | # shellcheck disable=SC2016 508 | POOL_PID_LIST=$(${S_PRINTF} '%s\n' "${PS_LIST[@]}" | $S_GREP -F -w "php-fpm: pool $POOL_NAME" | $S_AWK '{print $1}') 509 | local POOL_PID_ARGS="" 510 | while IFS= read -r POOL_PID; do 511 | if [[ -n $POOL_PID ]]; then 512 | POOL_PID_ARGS="$POOL_PID_ARGS -p $POOL_PID" 513 | fi 514 | done <<<"$POOL_PID_LIST" 515 | 516 | if [[ -n $POOL_PID_ARGS ]]; then 517 | #We search for socket or IP address and port 518 | #Socket example: 519 | #php-fpm7. 25897 root 9u unix 0x000000006509e31f 0t0 58381847 /run/php/php7.3-fpm.sock type=STREAM 520 | #IP example: 521 | #php-fpm7. 1110 default 0u IPv4 15760 0t0 TCP localhost:8002 (LISTEN) 522 | 523 | #Check all matching processes, because we may face a redirect (or a symlink?), examples: 524 | #php-fpm7. 1203 www-data 5u unix 0x000000006509e31f 0t0 15068771 type=STREAM 525 | #php-fpm7. 6086 www-data 11u IPv6 21771 0t0 TCP *:9000 (LISTEN) 526 | #php-fpm7. 1203 www-data 8u IPv4 15070917 0t0 TCP localhost.localdomain:23054->localhost.localdomain:postgresql (ESTABLISHED) 527 | #More info at https://github.com/rvalitov/zabbix-php-fpm/issues/12 528 | 529 | PrintDebug "Started analysis of pool $POOL_NAME, PID(s): $POOL_PID_ARGS" 530 | #Extract only important information: 531 | #Use -P to show port number instead of port name, see https://github.com/rvalitov/zabbix-php-fpm/issues/24 532 | #Use -n flag to show IP address and not convert it to domain name (like localhost) 533 | #Sometimes different PHP-FPM versions may have the same names of pools, so we need to consider that. 534 | # It's considered that a pair of pool name and socket must be unique. 535 | #Sorting is required, because uniq needs it 536 | local POOL_PARAMS_LIST 537 | # shellcheck disable=SC2086 538 | POOL_PARAMS_LIST=$($S_LSOF -n -P $POOL_PID_ARGS 2>/dev/null | $S_GREP -w -e "unix" -e "TCP" | $S_SORT -u | $S_UNIQ -f8) 539 | local FOUND_POOL="" 540 | while IFS= read -r pool; do 541 | if [[ -n $pool ]]; then 542 | PrintDebug "Checking process: $pool" 543 | local POOL_TYPE 544 | # shellcheck disable=SC2016 545 | POOL_TYPE=$(echo "${pool}" | $S_AWK '{print $5}') 546 | local POOL_SOCKET 547 | # shellcheck disable=SC2016 548 | POOL_SOCKET=$(echo "${pool}" | $S_AWK '{print $9}') 549 | if [[ -n $POOL_TYPE ]] && [[ -n $POOL_SOCKET ]]; then 550 | if [[ $POOL_TYPE == "unix" ]]; then 551 | #We have a socket here, test if it's actually a socket: 552 | if [[ -S $POOL_SOCKET ]]; then 553 | FOUND_POOL="1" 554 | PrintDebug "Found socket $POOL_SOCKET" 555 | AddPoolToPendingList "$POOL_NAME" "$POOL_SOCKET" 556 | else 557 | PrintDebug "Error: specified socket $POOL_SOCKET is not valid" 558 | fi 559 | elif [[ $POOL_TYPE == "IPv4" ]] || [[ $POOL_TYPE == "IPv6" ]]; then 560 | #We have a TCP connection here, check it: 561 | local CONNECTION_TYPE 562 | # shellcheck disable=SC2016 563 | CONNECTION_TYPE=$(echo "${pool}" | $S_AWK '{print $8}') 564 | if [[ $CONNECTION_TYPE == "TCP" ]]; then 565 | #The connection must have state LISTEN: 566 | local LISTEN 567 | LISTEN=$(echo "${pool}" | $S_GREP -F -w "(LISTEN)") 568 | if [[ -n $LISTEN ]]; then 569 | #Check and replace * to localhost if it's found. Asterisk means that the PHP listens on 570 | #all interfaces. 571 | FOUND_POOL="1" 572 | PrintDebug "Found TCP connection $POOL_SOCKET" 573 | POOL_SOCKET=${POOL_SOCKET/\*:/localhost:} 574 | AddPoolToPendingList "$POOL_NAME" "$POOL_SOCKET" 575 | else 576 | PrintDebug "Warning: expected connection state must be LISTEN, but it was not detected" 577 | fi 578 | else 579 | PrintDebug "Warning: expected connection type is TCP, but found $CONNECTION_TYPE" 580 | fi 581 | else 582 | PrintDebug "Unsupported type $POOL_TYPE, skipping" 583 | fi 584 | else 585 | PrintDebug "Warning: pool type or socket is empty" 586 | fi 587 | else 588 | PrintDebug "Error: failed to get process information. Probably insufficient privileges. Use sudo or run this script under root." 589 | fi 590 | done <<<"$POOL_PARAMS_LIST" 591 | 592 | if [[ -z ${FOUND_POOL} ]]; then 593 | PrintDebug "Error: failed to discover information for pool $POOL_NAME" 594 | fi 595 | else 596 | PrintDebug "Error: failed to find PID for pool $POOL_NAME" 597 | fi 598 | 599 | return 1 600 | } 601 | 602 | # Prints list of pools in pending list 603 | function PrintPendingList() { 604 | local COUNTER=1 605 | for POOL_ITEM in "${PENDING_LIST[@]}"; do 606 | local POOL_NAME 607 | # shellcheck disable=SC2016 608 | POOL_NAME=$(echo "$POOL_ITEM" | $S_AWK '{print $1}') 609 | local POOL_SOCKET 610 | # shellcheck disable=SC2016 611 | POOL_SOCKET=$(echo "$POOL_ITEM" | $S_AWK '{print $2}') 612 | if [[ -n "$POOL_NAME" ]] && [[ -n "$POOL_SOCKET" ]]; then 613 | PrintDebug "#$COUNTER $POOL_NAME $POOL_SOCKET" 614 | COUNTER=$(echo "$COUNTER + 1" | $S_BC) 615 | fi 616 | done 617 | } 618 | 619 | # Prints list of pools in cache 620 | function PrintCacheList() { 621 | local COUNTER=1 622 | for POOL_ITEM in "${CACHE[@]}"; do 623 | local POOL_NAME 624 | # shellcheck disable=SC2016 625 | POOL_NAME=$(echo "$POOL_ITEM" | $S_AWK '{print $1}') 626 | local POOL_SOCKET 627 | # shellcheck disable=SC2016 628 | POOL_SOCKET=$(echo "$POOL_ITEM" | $S_AWK '{print $2}') 629 | local PROCESS_MANAGER 630 | # shellcheck disable=SC2016 631 | PROCESS_MANAGER=$(echo "$POOL_ITEM" | $S_AWK '{print $3}') 632 | if [[ -n "$POOL_NAME" ]] && [[ -n "$POOL_SOCKET" ]] && [[ -n "$PROCESS_MANAGER" ]]; then 633 | PrintDebug "#$COUNTER $POOL_NAME $POOL_SOCKET $PROCESS_MANAGER" 634 | COUNTER=$(echo "$COUNTER + 1" | $S_BC) 635 | fi 636 | done 637 | } 638 | 639 | # Functions processes a pool by name: makes all required checks and adds it to cache, etc. 640 | function ProcessPool() { 641 | local POOL_NAME=$1 642 | local POOL_SOCKET=$2 643 | if [[ -z $POOL_NAME ]] || [[ -z $POOL_SOCKET ]]; then 644 | PrintDebug "Invalid arguments for ProcessPool" 645 | return 0 646 | fi 647 | 648 | PrintDebug "Processing pool $POOL_NAME $POOL_SOCKET" 649 | CheckPool "$POOL_NAME" "${POOL_SOCKET}" 650 | local POOL_STATUS=$? 651 | if [[ ${POOL_STATUS} -gt 0 ]]; then 652 | PrintDebug "Success: socket $POOL_SOCKET returned valid status data" 653 | else 654 | PrintDebug "Error: socket $POOL_SOCKET didn't return valid data" 655 | fi 656 | 657 | DeletePoolFromPendingList "$POOL_NAME" "$POOL_SOCKET" 658 | return 1 659 | } 660 | 661 | for ARG in "$@"; do 662 | if [[ ${ARG} == "debug" ]]; then 663 | DEBUG_MODE="1" 664 | echo "Debug mode enabled" 665 | elif [[ ${ARG} == "sleep" ]]; then 666 | USE_SLEEP_TIMEOUT="1" 667 | echo "Debug: Sleep timeout enabled" 668 | elif [[ ${ARG} == "nosleep" ]]; then 669 | MAX_EXECUTION_TIME="10000000" 670 | echo "Debug: Timeout checks disabled" 671 | elif [[ ${ARG} == /* ]]; then 672 | STATUS_PATH=${ARG} 673 | PrintDebug "Argument $ARG is interpreted as status path" 674 | else 675 | PrintDebug "Argument $ARG is unknown and skipped" 676 | fi 677 | done 678 | PrintDebug "Current user is $ACTIVE_USER" 679 | PrintDebug "Status path to be used: $STATUS_PATH" 680 | 681 | PrintDebug "Local directory is $LOCAL_DIR" 682 | if [[ ! -f ${STATUS_SCRIPT} ]]; then 683 | echo "Helper script $STATUS_SCRIPT not found" 684 | exit 1 685 | fi 686 | if [[ ! -r ${STATUS_SCRIPT} ]]; then 687 | echo "Helper script $STATUS_SCRIPT is not readable" 688 | exit 1 689 | fi 690 | PrintDebug "Helper script $STATUS_SCRIPT is reachable" 691 | 692 | # Loading cached data for pools. 693 | CACHE=() 694 | if [[ -r $RESULTS_CACHE_FILE ]]; then 695 | PrintDebug "Reading cache file of pools $RESULTS_CACHE_FILE..." 696 | mapfile -t CACHE < <(${S_CAT} "$RESULTS_CACHE_FILE") 697 | else 698 | PrintDebug "Cache file of pools $RESULTS_CACHE_FILE not found, skipping..." 699 | fi 700 | 701 | if [[ -n $DEBUG_MODE ]]; then 702 | PrintDebug "List of pools loaded from cache pools file:" 703 | PrintCacheList 704 | fi 705 | 706 | #Loading pending tasks 707 | PENDING_LIST=() 708 | if [[ -r $PENDING_FILE ]]; then 709 | PrintDebug "Reading file of pending pools $PENDING_FILE..." 710 | mapfile -t PENDING_LIST < <($S_CAT "$PENDING_FILE") 711 | else 712 | PrintDebug "List of pending pools $PENDING_FILE not found, skipping..." 713 | fi 714 | 715 | if [[ -n $DEBUG_MODE ]]; then 716 | PrintDebug "List of pools loaded from pending pools file:" 717 | PrintPendingList 718 | fi 719 | 720 | mapfile -t PS_LIST < <($S_PS ax | $S_GREP -F "php-fpm: pool " | $S_GREP -F -v "grep") 721 | # shellcheck disable=SC2016 722 | POOL_NAMES_LIST=$(${S_PRINTF} '%s\n' "${PS_LIST[@]}" | $S_AWK '{print $NF}' | $S_SORT -u) 723 | 724 | #Update pending list with pools that are active and running 725 | while IFS= read -r POOL_NAME; do 726 | AnalyzePool "$POOL_NAME" 727 | done <<<"$POOL_NAMES_LIST" 728 | 729 | if [[ -n $DEBUG_MODE ]]; then 730 | PrintDebug "Pending list generated:" 731 | PrintPendingList 732 | fi 733 | 734 | #Process pending list 735 | PrintDebug "Processing pools" 736 | 737 | for POOL_ITEM in "${PENDING_LIST[@]}"; do 738 | # shellcheck disable=SC2016 739 | POOL_NAME=$(echo "$POOL_ITEM" | $S_AWK '{print $1}') 740 | # shellcheck disable=SC2016 741 | POOL_SOCKET=$(echo "$POOL_ITEM" | $S_AWK '{print $2}') 742 | if [[ -n "$POOL_NAME" ]] && [[ -n "$POOL_SOCKET" ]]; then 743 | ProcessPool "$POOL_NAME" "$POOL_SOCKET" 744 | 745 | #Confirm that we run not too much time 746 | CheckExecutionTime 747 | 748 | #Used for debugging: 749 | sleepNow 750 | fi 751 | done 752 | 753 | SavePrintResults 754 | -------------------------------------------------------------------------------- /tests/all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Ramil Valitov ramilvalitov@gmail.com 3 | #https://github.com/rvalitov/zabbix-php-fpm 4 | #This script is used for testing 5 | 6 | ################################### START OF CONFIGURATION CONSTANTS 7 | 8 | # Number of pools, created for each ondemand, static and dynamic sockets. 9 | MAX_POOLS=3 10 | 11 | # Number of port based pools created for each PHP version 12 | MAX_PORTS=3 13 | 14 | # Starting port number for port based PHP pools 15 | MIN_PORT=49001 16 | 17 | # Maximum number of ports per PHP version, this value is used to define the available port range. 18 | MAX_PORTS_COUNT=100 19 | 20 | # Timeout in seconds that we put in the option "pm.process_idle_timeout" of configuration of ondemand PHP pools. 21 | ONDEMAND_TIMEOUT=60 22 | 23 | # Timeout in seconds that we put in the configuration of Zabbix agent 24 | ZABBIX_TIMEOUT=20 25 | 26 | # Maximum iterations to perform during sequential scans of pools, when the operation is time-consuming and requires 27 | # multiple calls to the discovery script. 28 | # This value should be big enough to be able to get information about all pools in the system. 29 | # It allows to exit from indefinite check loops. 30 | MAX_CHECKS=150 31 | 32 | ################################### END OF CONFIGURATION CONSTANTS 33 | 34 | # A random socket used for tests, this variable is defined when PHP pools are created 35 | TEST_SOCKET="" 36 | 37 | # The directory where the PHP socket files are located, for example, /var/run or /run. 38 | # This variable is used as cache, because it may be impossible to detect it when we start and stop the PHP-FPM. 39 | # Don't use this variable directly. Use function getRunPHPDirectory 40 | PHP_SOCKET_DIR="" 41 | 42 | # The directory where the PHP configuration files are located, for example, /etc/php or /etc/php5. 43 | # This variable is used as cache. So, don't use this variable directly. Use function getEtcPHPDirectory 44 | PHP_ETC_DIR="" 45 | 46 | # List of all services in the system. 47 | # This variable is used as cache. So, don't use this variable directly. Use function getPHPServiceName 48 | LIST_OF_SERVICES="" 49 | 50 | # Used for section folding in Travis CI 51 | SECTION_UNIQUE_ID="" 52 | 53 | #Parent directory where all cache files are located in the OS 54 | CACHE_ROOT="/var/cache" 55 | 56 | #Name of the private directory to store the cache files 57 | CACHE_DIR_NAME="zabbix-php-fpm" 58 | 59 | #Full path to directory to store cache files 60 | CACHE_DIRECTORY="$CACHE_ROOT/$CACHE_DIR_NAME" 61 | 62 | # ---------------------------------- 63 | # Colors 64 | # ---------------------------------- 65 | NOCOLOR='\033[0m' 66 | RED='\033[0;31m' 67 | GREEN='\033[0;32m' 68 | ORANGE='\033[0;33m' 69 | BLUE='\033[0;34m' 70 | PURPLE='\033[0;35m' 71 | CYAN='\033[0;36m' 72 | LIGHTGRAY='\033[0;37m' 73 | DARKGRAY='\033[1;30m' 74 | LIGHTRED='\033[1;31m' 75 | LIGHTGREEN='\033[1;32m' 76 | YELLOW='\033[1;33m' 77 | LIGHTBLUE='\033[1;34m' 78 | LIGHTPURPLE='\033[1;35m' 79 | LIGHTCYAN='\033[1;36m' 80 | WHITE='\033[1;37m' 81 | 82 | function printYellow() { 83 | local info=$1 84 | echo -e "${YELLOW}$info${NOCOLOR}" 85 | } 86 | 87 | function printRed() { 88 | local info=$1 89 | echo -e "${RED}$info${NOCOLOR}" 90 | } 91 | 92 | function printGreen() { 93 | local info=$1 94 | echo -e "${LIGHTGREEN}$info${NOCOLOR}" 95 | } 96 | 97 | function printSuccess() { 98 | local name=$1 99 | printGreen "✓ OK: test '$name' passed" 100 | } 101 | 102 | function printDebug() { 103 | local info=$1 104 | echo -e "${DARKGRAY}$info${NOCOLOR}" 105 | } 106 | 107 | function printAction() { 108 | local info=$1 109 | echo -e "${LIGHTBLUE}$info${NOCOLOR}" 110 | } 111 | 112 | function travis_fold_start() { 113 | local name=$1 114 | local info=$2 115 | local CURRENT_TIMING 116 | CURRENT_TIMING=$(date +%s%3N) 117 | SECTION_UNIQUE_ID="$name.$CURRENT_TIMING" 118 | echo -e "travis_fold:start:${SECTION_UNIQUE_ID}\033[33;1m${info}\033[0m" 119 | } 120 | 121 | function travis_fold_end() { 122 | echo -e "\ntravis_fold:end:${SECTION_UNIQUE_ID}\r" 123 | } 124 | 125 | function getUserParameters() { 126 | sudo find /etc/zabbix/ -name 'userparameter_php_fpm.conf' -type f 2>/dev/null | sort | head -n1 127 | } 128 | 129 | function restoreUserParameters() { 130 | PARAMS_FILE=$(getUserParameters) 131 | sudo rm -f "$PARAMS_FILE" 132 | sudo cp "$TRAVIS_BUILD_DIR/zabbix/userparameter_php_fpm.conf" "$(sudo find /etc/zabbix/ -name 'zabbix_agentd*.d' -type d 2>/dev/null | sort | head -n1)" 133 | } 134 | 135 | function AddSleepToConfig() { 136 | PARAMS_FILE=$(getUserParameters) 137 | sudo sed -i 's#.*zabbix_php_fpm_discovery.*#UserParameter=php-fpm.discover[*],sudo /etc/zabbix/zabbix_php_fpm_discovery.sh sleep $1#' "$PARAMS_FILE" 138 | travis_fold_start "AddSleepToConfig" "ⓘ New UserParameter file" 139 | sudo cat "$PARAMS_FILE" 140 | travis_fold_end 141 | restartService "zabbix-agent" 142 | sleep 2 143 | } 144 | 145 | function getPHPVersion() { 146 | TEST_STRING=$1 147 | PHP_VERSION=$(echo "$TEST_STRING" | grep -oP "(\d\.\d)") 148 | if [[ -z "$PHP_VERSION" ]]; then 149 | PHP_VERSION=$(echo "$TEST_STRING" | grep -oP "php(\d)" | grep -oP "(\d)") 150 | fi 151 | echo "$PHP_VERSION" 152 | if [[ -z "$PHP_VERSION" ]]; then 153 | return 1 154 | fi 155 | return 0 156 | } 157 | 158 | function getEtcPHPDirectory() { 159 | if [[ -n "$PHP_ETC_DIR" ]]; then 160 | echo "$PHP_ETC_DIR" 161 | return 0 162 | fi 163 | 164 | LIST_OF_DIRS=( 165 | "/etc/php/" 166 | "/etc/php5/" 167 | ) 168 | for PHP_TEST_DIR in "${LIST_OF_DIRS[@]}"; do 169 | if [[ -d "$PHP_TEST_DIR" ]]; then 170 | PHP_ETC_DIR=$PHP_TEST_DIR 171 | break 172 | fi 173 | done 174 | 175 | if [[ -n "$PHP_ETC_DIR" ]]; then 176 | echo "$PHP_ETC_DIR" 177 | return 0 178 | fi 179 | 180 | return 1 181 | } 182 | 183 | function getRunPHPDirectory() { 184 | if [[ -n "$PHP_SOCKET_DIR" ]]; then 185 | echo "$PHP_SOCKET_DIR" 186 | return 0 187 | fi 188 | 189 | LIST_OF_DIRS=( 190 | "/run/" 191 | "/var/run/" 192 | ) 193 | for PHP_TEST_DIR in "${LIST_OF_DIRS[@]}"; do 194 | RESULT_DIR=$(sudo find "$PHP_TEST_DIR" -name 'php*-fpm.sock' -type s -exec dirname {} \; 2>/dev/null | sort | head -n1) 195 | if [[ -d "$RESULT_DIR" ]]; then 196 | PHP_SOCKET_DIR="$RESULT_DIR/" 197 | break 198 | fi 199 | done 200 | 201 | if [[ -z "$PHP_SOCKET_DIR" ]]; then 202 | #Try to parse the location from default config 203 | PHP_DIR=$(getEtcPHPDirectory) 204 | EXIT_CODE=$? 205 | assertEquals "Failed to find PHP configuration directory" "0" "$EXIT_CODE" 206 | assertTrue "PHP configuration directory '$PHP_DIR' is not a directory" "[ -d $PHP_DIR ]" 207 | 208 | DEFAULT_CONF=$(sudo find "$PHP_DIR" -name "www.conf" -type f | uniq | head -n1) 209 | assertTrue "Failed to find default www.conf file inside '$PHP_DIR'" "[ -n $DEFAULT_CONF ]" 210 | 211 | DEFAULT_SOCKET=$(sudo grep -Po 'listen = (.+)' "$DEFAULT_CONF" | cut -d '=' -f2 | sed -e 's/^[ \t]*//') 212 | assertTrue "Failed to extract socket information from '$DEFAULT_CONF'" "[ -n $DEFAULT_SOCKET ]" 213 | 214 | RESULT_DIR=$(dirname "$DEFAULT_SOCKET") 215 | assertTrue "Directory '$RESULT_DIR' does not exist" "[ -d $RESULT_DIR ]" 216 | if [[ -d "$RESULT_DIR" ]]; then 217 | PHP_SOCKET_DIR="$RESULT_DIR/" 218 | fi 219 | fi 220 | 221 | if [[ -n "$PHP_SOCKET_DIR" ]]; then 222 | echo "$PHP_SOCKET_DIR" 223 | return 0 224 | fi 225 | 226 | return 1 227 | } 228 | 229 | copyPool() { 230 | ORIGINAL_FILE=$1 231 | POOL_NAME=$2 232 | POOL_SOCKET=$3 233 | POOL_TYPE=$4 234 | POOL_DIR=$(dirname "${ORIGINAL_FILE}") 235 | PHP_VERSION=$(getPHPVersion "$POOL_DIR") 236 | assertNotNull "Failed to detect PHP version from string '$POOL_DIR'" "$PHP_VERSION" 237 | 238 | NEW_POOL_FILE="$POOL_DIR/${POOL_NAME}.conf" 239 | sudo cp "$ORIGINAL_FILE" "$NEW_POOL_FILE" 240 | 241 | #Add status path 242 | sudo sed -i 's#;pm.status_path.*#pm.status_path = /php-fpm-status#' "$NEW_POOL_FILE" 243 | #Set pool manager 244 | sudo sed -i "s#pm = dynamic#pm = $POOL_TYPE#" "$NEW_POOL_FILE" 245 | #Socket 246 | sudo sed -i "s#listen =.*#listen = $POOL_SOCKET#" "$NEW_POOL_FILE" 247 | #Pool name 248 | sudo sed -i "s#\[www\]#[$POOL_NAME]#" "$NEW_POOL_FILE" 249 | 250 | if [[ $POOL_TYPE == "ondemand" ]]; then 251 | sudo sed -i "s#;pm.process_idle_timeout.*#pm.process_idle_timeout = ${ONDEMAND_TIMEOUT}s#" "$NEW_POOL_FILE" 252 | fi 253 | } 254 | 255 | getPHPServiceName() { 256 | PHP_VERSION=$1 257 | if [[ -z "$LIST_OF_SERVICES" ]]; then 258 | LIST_OF_SERVICES=$(sudo service --status-all 2>/dev/null | sort) 259 | fi 260 | 261 | LIST_OF_NAMES=( 262 | "php${PHP_VERSION}-fpm" 263 | "php-fpm" 264 | ) 265 | 266 | for SERVICE_NAME in "${LIST_OF_NAMES[@]}"; do 267 | RESULT=$(echo "$LIST_OF_SERVICES" | grep -F "$SERVICE_NAME") 268 | if [[ -n "$RESULT" ]]; then 269 | echo "$SERVICE_NAME" 270 | return 0 271 | fi 272 | done 273 | return 1 274 | } 275 | 276 | setupPool() { 277 | POOL_FILE=$1 278 | POOL_DIR=$(dirname "${POOL_FILE}") 279 | PHP_VERSION=$(getPHPVersion "$POOL_DIR") 280 | assertNotNull "Failed to detect PHP version from string '$POOL_DIR'" "$PHP_VERSION" 281 | 282 | PHP_RUN_DIR=$(getRunPHPDirectory) 283 | EXIT_CODE=$? 284 | assertEquals "Failed to find PHP run directory" "0" "$EXIT_CODE" 285 | assertTrue "PHP run directory '$PHP_RUN_DIR' is not a directory" "[ -d $PHP_RUN_DIR ]" 286 | 287 | PHP_DIR=$(getEtcPHPDirectory) 288 | EXIT_CODE=$? 289 | assertEquals "Failed to find PHP configuration directory" "0" "$EXIT_CODE" 290 | assertTrue "PHP configuration directory '$PHP_DIR' is not a directory" "[ -d $PHP_DIR ]" 291 | 292 | #Delete all active pools except www.conf: 293 | sudo find "$POOL_DIR" -name '*.conf' -type f -not -name 'www.conf' -exec rm -rf {} \; 294 | 295 | #Create new socket pools 296 | for ((c = 1; c <= MAX_POOLS; c++)); do 297 | POOL_NAME="socket$c" 298 | POOL_SOCKET="${PHP_RUN_DIR}php${PHP_VERSION}-fpm-${POOL_NAME}.sock" 299 | copyPool "$POOL_FILE" "$POOL_NAME" "$POOL_SOCKET" "static" 300 | if [[ -z $TEST_SOCKET ]]; then 301 | TEST_SOCKET="$POOL_SOCKET" 302 | fi 303 | done 304 | 305 | for ((c = 1; c <= MAX_POOLS; c++)); do 306 | POOL_NAME="dynamic$c" 307 | POOL_SOCKET="${PHP_RUN_DIR}php${PHP_VERSION}-fpm-${POOL_NAME}.sock" 308 | copyPool "$POOL_FILE" "$POOL_NAME" "$POOL_SOCKET" "dynamic" 309 | done 310 | 311 | for ((c = 1; c <= MAX_POOLS; c++)); do 312 | POOL_NAME="ondemand$c" 313 | POOL_SOCKET="${PHP_RUN_DIR}php${PHP_VERSION}-fpm-${POOL_NAME}.sock" 314 | copyPool "$POOL_FILE" "$POOL_NAME" "$POOL_SOCKET" "ondemand" 315 | done 316 | 317 | PHP_SERIAL_ID=$(sudo find "$PHP_DIR" -maxdepth 1 -mindepth 1 -type d | sort | grep -n -F "$PHP_VERSION" | head -n1 | cut -d : -f 1) 318 | #Create TCP port based pools 319 | #Division on 1 is required to convert from float to integer 320 | START_PORT=$(echo "($MIN_PORT + $PHP_SERIAL_ID * $MAX_PORTS_COUNT + 1)/1" | bc) 321 | for ((c = 1; c <= MAX_PORTS; c++)); do 322 | POOL_NAME="port$c" 323 | POOL_PORT=$(echo "($START_PORT + $c)/1" | bc) 324 | PORT_IS_BUSY=$(sudo lsof -i:"$POOL_PORT") 325 | assertNull "Port $POOL_PORT is busy" "$PORT_IS_BUSY" 326 | copyPool "$POOL_FILE" "$POOL_NAME" "$POOL_PORT" "static" 327 | done 328 | 329 | #Create TCP IPv4 localhost pool 330 | POOL_NAME="localhost" 331 | POOL_PORT=$(echo "($MIN_PORT + $PHP_SERIAL_ID * $MAX_PORTS_COUNT)/1" | bc) 332 | POOL_SOCKET="127.0.0.1:$POOL_PORT" 333 | PORT_IS_BUSY=$(sudo lsof -i:"$POOL_PORT") 334 | assertNull "Port $POOL_PORT is busy" "$PORT_IS_BUSY" 335 | copyPool "$POOL_FILE" "$POOL_NAME" "$POOL_SOCKET" "static" 336 | 337 | travis_fold_start "list_PHP$PHP_VERSION" "ⓘ List of configured PHP$PHP_VERSION pools" 338 | sudo ls -l "$POOL_DIR" 339 | travis_fold_end 340 | 341 | SERVICE_NAME=$(getPHPServiceName "$PHP_VERSION") 342 | assertNotNull "Failed to detect service name for PHP${PHP_VERSION}" "$SERVICE_NAME" 343 | printAction "Restarting service $SERVICE_NAME..." 344 | restartService "$SERVICE_NAME" 345 | sleep 3 346 | 347 | travis_fold_start "running_PHP$PHP_VERSION" "ⓘ List of running PHP$PHP_VERSION pools" 348 | E_SYSTEM_CONTROL=$(type -P systemctl) 349 | if [[ -x "$E_SYSTEM_CONTROL" ]]; then 350 | sudo systemctl -l status "$SERVICE_NAME.service" 351 | else 352 | sudo initctl list | grep -F "$SERVICE_NAME" 353 | fi 354 | travis_fold_end 355 | sleep 2 356 | } 357 | 358 | setupPools() { 359 | PHP_DIR=$(getEtcPHPDirectory) 360 | EXIT_CODE=$? 361 | assertEquals "Failed to find PHP configuration directory" "0" "$EXIT_CODE" 362 | assertTrue "PHP configuration directory '$PHP_DIR' is not a directory" "[ -d $PHP_DIR ]" 363 | 364 | PHP_LIST=$(sudo find "$PHP_DIR" -name 'www.conf' -type f) 365 | 366 | #Call to detect and cache PHP run directory, we need to call it before we stop all PHP-FPM 367 | PHP_RUN_DIR=$(getRunPHPDirectory) 368 | EXIT_CODE=$? 369 | assertEquals "Failed to find PHP run directory" "0" "$EXIT_CODE" 370 | assertTrue "PHP run directory '$PHP_RUN_DIR' is not a directory" "[ -d $PHP_RUN_DIR ]" 371 | 372 | #First we need to stop all PHP-FPM 373 | while IFS= read -r pool; do 374 | if [[ -n $pool ]]; then 375 | POOL_DIR=$(dirname "$pool") 376 | PHP_VERSION=$(getPHPVersion "$POOL_DIR") 377 | assertNotNull "Failed to detect PHP version from string '$POOL_DIR'" "$PHP_VERSION" 378 | SERVICE_NAME=$(getPHPServiceName "$PHP_VERSION") 379 | assertNotNull "Failed to detect service name for PHP${PHP_VERSION}" "$SERVICE_NAME" 380 | printAction "Stopping service $SERVICE_NAME..." 381 | stopService "$SERVICE_NAME" 382 | fi 383 | done <<<"$PHP_LIST" 384 | 385 | #Now we reconfigure them and restart 386 | while IFS= read -r pool; do 387 | if [[ -n $pool ]]; then 388 | setupPool "$pool" 389 | fi 390 | done <<<"$PHP_LIST" 391 | } 392 | 393 | getNumberOfPHPVersions() { 394 | PHP_DIR=$(getEtcPHPDirectory) 395 | EXIT_CODE=$? 396 | assertEquals "Failed to find PHP configuration directory" "0" "$EXIT_CODE" 397 | assertTrue "PHP configuration directory '$PHP_DIR' is not a directory" "[ -d $PHP_DIR ]" 398 | 399 | PHP_COUNT=$(sudo find "$PHP_DIR" -name 'www.conf' -type f | wc -l) 400 | echo "$PHP_COUNT" 401 | } 402 | 403 | function startOndemandPoolsCache() { 404 | PHP_DIR=$(getEtcPHPDirectory) 405 | EXIT_CODE=$? 406 | assertEquals "Failed to find PHP configuration directory" "0" "$EXIT_CODE" 407 | assertTrue "PHP configuration directory '$PHP_DIR' is not a directory" "[ -d $PHP_DIR ]" 408 | 409 | PHP_RUN_DIR=$(getRunPHPDirectory) 410 | EXIT_CODE=$? 411 | assertEquals "Failed to find PHP run directory" "0" "$EXIT_CODE" 412 | assertTrue "PHP run directory '$PHP_RUN_DIR' is not a directory" "[ -d $PHP_RUN_DIR ]" 413 | 414 | # We must start all the pools 415 | POOL_URL="/php-fpm-status" 416 | 417 | PHP_LIST=$(sudo find "$PHP_DIR" -name 'www.conf' -type f) 418 | while IFS= read -r pool; do 419 | if [[ -n $pool ]]; then 420 | POOL_DIR=$(dirname "$pool") 421 | PHP_VERSION=$(getPHPVersion "$POOL_DIR") 422 | assertNotNull "Failed to detect PHP version from string '$POOL_DIR'" "$PHP_VERSION" 423 | 424 | for ((c = 1; c <= MAX_POOLS; c++)); do 425 | POOL_NAME="ondemand$c" 426 | POOL_SOCKET="${PHP_RUN_DIR}php${PHP_VERSION}-fpm-${POOL_NAME}.sock" 427 | 428 | PHP_STATUS=$( 429 | SCRIPT_NAME=$POOL_URL \ 430 | SCRIPT_FILENAME=$POOL_URL \ 431 | QUERY_STRING=json \ 432 | REQUEST_METHOD=GET \ 433 | sudo cgi-fcgi -bind -connect "$POOL_SOCKET" 2>/dev/null 434 | ) 435 | assertNotNull "Failed to connect to $POOL_SOCKET" "$PHP_STATUS" 436 | done 437 | fi 438 | done <<<"$PHP_LIST" 439 | } 440 | 441 | getAnySocket() { 442 | PHP_DIR=$(getEtcPHPDirectory) 443 | EXIT_CODE=$? 444 | assertEquals "Failed to find PHP configuration directory" "0" "$EXIT_CODE" 445 | assertTrue "PHP configuration directory '$PHP_DIR' is not a directory" "[ -d $PHP_DIR ]" 446 | 447 | PHP_RUN_DIR=$(getRunPHPDirectory) 448 | EXIT_CODE=$? 449 | assertEquals "Failed to find PHP run directory" "0" "$EXIT_CODE" 450 | assertTrue "PHP run directory '$PHP_RUN_DIR' is not a directory" "[ -d $PHP_RUN_DIR ]" 451 | 452 | #Get any socket of PHP-FPM: 453 | PHP_FIRST=$(sudo find "$PHP_DIR" -name 'www.conf' -type f | sort | head -n1) 454 | assertNotNull "Failed to get PHP conf" "$PHP_FIRST" 455 | PHP_VERSION=$(getPHPVersion "$PHP_FIRST") 456 | assertNotNull "Failed to detect PHP version from string '$PHP_FIRST'" "$PHP_VERSION" 457 | PHP_POOL=$(sudo find "$PHP_RUN_DIR" -name "php${PHP_VERSION}*.sock" -type s 2>/dev/null | sort | head -n1) 458 | assertNotNull "Failed to get PHP${PHP_VERSION} socket" "$PHP_POOL" 459 | echo "$PHP_POOL" 460 | } 461 | 462 | getAnyPort() { 463 | PHP_PORT=$(sudo netstat -tulpn | grep -F "LISTEN" | grep -F "php-fpm" | head -n1 | awk '{print $4}' | rev | cut -d: -f1 | rev) 464 | assertNotNull "Failed to get PHP port" "$PHP_PORT" 465 | echo "$PHP_PORT" 466 | } 467 | 468 | function actionService() { 469 | local SERVICE_NAME=$1 470 | local SERVICE_ACTION=$2 471 | local SERVICE_INFO 472 | sleep 3 473 | SERVICE_INFO=$(sudo service "$SERVICE_NAME" $SERVICE_ACTION) 474 | STATUS=$? 475 | if [[ "$STATUS" -ne 0 ]]; then 476 | printRed "Failed to $SERVICE_ACTION service '$SERVICE_NAME':" 477 | echo "$SERVICE_INFO" 478 | fi 479 | sleep 3 480 | } 481 | 482 | function restartService() { 483 | local SERVICE_NAME=$1 484 | actionService "$SERVICE_NAME" "restart" 485 | } 486 | 487 | function stopService() { 488 | local SERVICE_NAME=$1 489 | actionService "$SERVICE_NAME" "stop" 490 | } 491 | 492 | oneTimeSetUp() { 493 | printAction "Started job $TRAVIS_JOB_NAME" 494 | 495 | travis_fold_start "host_info" "ⓘ Host information" 496 | nslookup localhost 497 | sudo ifconfig 498 | sudo cat /etc/hosts 499 | travis_fold_end 500 | 501 | printAction "Copying Zabbix files..." 502 | #Install files: 503 | sudo cp "$TRAVIS_BUILD_DIR/zabbix/zabbix_php_fpm_discovery.sh" "/etc/zabbix" 504 | sudo cp "$TRAVIS_BUILD_DIR/zabbix/zabbix_php_fpm_status.sh" "/etc/zabbix" 505 | sudo cp "$TRAVIS_BUILD_DIR/zabbix/userparameter_php_fpm.conf" "$(sudo find /etc/zabbix/ -name 'zabbix_agentd*.d' -type d | sort | head -n1)" 506 | sudo chmod +x /etc/zabbix/zabbix_php_fpm_discovery.sh 507 | sudo chmod +x /etc/zabbix/zabbix_php_fpm_status.sh 508 | 509 | #Configure Zabbix: 510 | echo 'zabbix ALL=NOPASSWD: /etc/zabbix/zabbix_php_fpm_discovery.sh,/etc/zabbix/zabbix_php_fpm_status.sh' | sudo EDITOR='tee -a' visudo 511 | sudo sed -i "s#.* Timeout=.*#Timeout = $ZABBIX_TIMEOUT#" "/etc/zabbix/zabbix_agentd.conf" 512 | 513 | travis_fold_start "zabbix_agent" "ⓘ Zabbix agent configuration" 514 | sudo cat "/etc/zabbix/zabbix_agentd.conf" 515 | travis_fold_end 516 | 517 | restartService "zabbix-agent" 518 | 519 | printAction "Setup PHP-FPM..." 520 | 521 | #Setup PHP-FPM pools: 522 | setupPools 523 | 524 | printAction "All done, starting tests..." 525 | } 526 | 527 | #Called before every test 528 | setUp() { 529 | #Delete all cache files 530 | if [[ -d "$CACHE_DIRECTORY" ]]; then 531 | sudo find "$CACHE_DIRECTORY" -type f -exec rm '{}' \; 532 | fi 533 | } 534 | 535 | #Called after every test 536 | tearDown() { 537 | restoreUserParameters 538 | sleep 2 539 | restartService "zabbix-agent" 540 | sleep 2 541 | } 542 | 543 | testZabbixGetInstalled() { 544 | ZABBIX_GET=$(type -P zabbix_get) 545 | assertNotNull "Utility zabbix-get not installed" "$ZABBIX_GET" 546 | printSuccess "${FUNCNAME[0]}" 547 | } 548 | 549 | testZabbixAgentVersion() { 550 | #Example: 4.4 551 | REQUESTED_VERSION=$(echo "$TRAVIS_JOB_NAME" | grep -i -F "zabbix" | head -n1 | cut -d "@" -f1 | cut -d " " -f2) 552 | INSTALLED_VERSION=$(zabbix_agentd -V | grep -F "zabbix" | head -n1 | rev | cut -d " " -f1 | rev | cut -d "." -f1,2) 553 | assertSame "Requested version $REQUESTED_VERSION and installed version $INSTALLED_VERSION of Zabbix agent do not match" "$REQUESTED_VERSION" "$INSTALLED_VERSION" 554 | printSuccess "${FUNCNAME[0]}" 555 | } 556 | 557 | testZabbixGetVersion() { 558 | #Example: 4.4 559 | REQUESTED_VERSION=$(echo "$TRAVIS_JOB_NAME" | grep -i -F "zabbix" | head -n1 | cut -d "@" -f1 | cut -d " " -f2) 560 | INSTALLED_VERSION=$(zabbix_get -V | grep -F "zabbix" | head -n1 | rev | cut -d " " -f1 | rev | cut -d "." -f1,2) 561 | assertSame "Requested version $REQUESTED_VERSION and installed version $INSTALLED_VERSION of zabbix_get do not match" "$REQUESTED_VERSION" "$INSTALLED_VERSION" 562 | printSuccess "${FUNCNAME[0]}" 563 | } 564 | 565 | testNonRootUserPrivilegesDiscovery() { 566 | #Run the script under non root user 567 | DATA=$(sudo -u zabbix "/etc/zabbix/zabbix_php_fpm_discovery.sh") 568 | IS_OK=$(echo "$DATA" | grep -F 'Insufficient privileges') 569 | assertNotNull "The discovery script must not work for non root user" "$IS_OK" 570 | printSuccess "${FUNCNAME[0]}" 571 | } 572 | 573 | testNonRootUserPrivilegesStatus() { 574 | #Run the script under non root user 575 | assertNotNull "Test socket is not defined" "$TEST_SOCKET" 576 | DATA=$(sudo -u zabbix "/etc/zabbix/zabbix_php_fpm_status.sh" "$TEST_SOCKET" "/php-fpm-status") 577 | IS_OK=$(echo "$DATA" | grep -F 'Insufficient privileges') 578 | assertNotNull "The status script must not work for non root user" "$IS_OK" 579 | printSuccess "${FUNCNAME[0]}" 580 | } 581 | 582 | testPHPIsRunning() { 583 | IS_OK=$(sudo ps ax | grep -F "php-fpm: pool " | grep -F -v "grep" | head -n1) 584 | assertNotNull "No running PHP-FPM instances found" "$IS_OK" 585 | printSuccess "${FUNCNAME[0]}" 586 | } 587 | 588 | testStatusScriptSocket() { 589 | assertNotNull "Test socket is not defined" "$TEST_SOCKET" 590 | DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_status.sh" "$TEST_SOCKET" "/php-fpm-status") 591 | IS_OK=$(echo "$DATA" | grep -F '{"pool":"') 592 | assertNotNull "Failed to get status from pool $TEST_SOCKET: $DATA" "$IS_OK" 593 | printGreen "Success test of $TEST_SOCKET" 594 | printSuccess "${FUNCNAME[0]}" 595 | } 596 | 597 | testStatusScriptPort() { 598 | PHP_PORT=$(getAnyPort) 599 | PHP_POOL="127.0.0.1:$PHP_PORT" 600 | 601 | #Make the test: 602 | DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_status.sh" "$PHP_POOL" "/php-fpm-status") 603 | IS_OK=$(echo "$DATA" | grep -F '{"pool":"') 604 | assertNotNull "Failed to get status from pool $PHP_POOL: $DATA" "$IS_OK" 605 | printGreen "Success test of $PHP_POOL" 606 | printSuccess "${FUNCNAME[0]}" 607 | } 608 | 609 | testZabbixStatusSocket() { 610 | DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.status["$TEST_SOCKET","/php-fpm-status"]) 611 | IS_OK=$(echo "$DATA" | grep -F '{"pool":"') 612 | assertNotNull "Failed to get status from pool $PHP_POOL: $DATA" "$IS_OK" 613 | printGreen "Success test of $PHP_POOL" 614 | printSuccess "${FUNCNAME[0]}" 615 | } 616 | 617 | testZabbixStatusPort() { 618 | PHP_PORT=$(getAnyPort) 619 | PHP_POOL="127.0.0.1:$PHP_PORT" 620 | 621 | DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.status["$PHP_POOL","/php-fpm-status"]) 622 | IS_OK=$(echo "$DATA" | grep -F '{"pool":"') 623 | assertNotNull "Failed to get status from pool $PHP_POOL: $DATA" "$IS_OK" 624 | printGreen "Success test of $PHP_POOL" 625 | printSuccess "${FUNCNAME[0]}" 626 | } 627 | 628 | testDiscoverScriptReturnsData() { 629 | DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "/php-fpm-status") 630 | IS_OK=$(echo "$DATA" | grep -F '{"data":[{"{#POOLNAME}"') 631 | assertNotNull "Discover script failed: $DATA" "$IS_OK" 632 | printSuccess "${FUNCNAME[0]}" 633 | } 634 | 635 | testDiscoverScriptDebug() { 636 | DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "nosleep" "/php-fpm-status") 637 | NUMBER_OF_ERRORS=$(echo "$DATA" | grep -o -F 'Error:' | wc -l) 638 | PHP_COUNT=$(getNumberOfPHPVersions) 639 | if [[ $PHP_COUNT != "$NUMBER_OF_ERRORS" ]]; then 640 | ERRORS_LIST=$(echo "$DATA" | grep -F 'Error:') 641 | printYellow "Errors list:" 642 | printYellow "$ERRORS_LIST" 643 | travis_fold_start "testDiscoverScriptDebug_full" "ⓘ Full output" 644 | echo "$DATA" 645 | travis_fold_end 646 | fi 647 | assertEquals "Discover script errors mismatch" "$PHP_COUNT" "$NUMBER_OF_ERRORS" 648 | printSuccess "${FUNCNAME[0]}" 649 | } 650 | 651 | testZabbixDiscoverReturnsData() { 652 | DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"]) 653 | IS_OK=$(echo "$DATA" | grep -F '{"data":[{"{#POOLNAME}"') 654 | assertNotNull "Discover script failed: $DATA" "$IS_OK" 655 | printSuccess "${FUNCNAME[0]}" 656 | } 657 | 658 | testDiscoverScriptSleep() { 659 | DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status") 660 | CHECK_OK_COUNT=$(echo "$DATA" | grep -o -F "execution time OK" | wc -l) 661 | STOP_OK_COUNT=$(echo "$DATA" | grep -o -F "stop required" | wc -l) 662 | 663 | printYellow "Success time checks: $CHECK_OK_COUNT" 664 | printYellow "Stop time checks: $STOP_OK_COUNT" 665 | 666 | if [[ $CHECK_OK_COUNT -lt 1 ]] || [[ $STOP_OK_COUNT -lt 1 ]]; then 667 | travis_fold_start "ScriptSleep" "ⓘ Zabbix response" 668 | echo "$DATA" 669 | travis_fold_end 670 | fi 671 | assertTrue "No success time checks detected" "[ $CHECK_OK_COUNT -gt 0 ] || [ $STOP_OK_COUNT -eq 1 ]" 672 | assertTrue "No success stop checks detected" "[ $STOP_OK_COUNT -gt 0 ]" 673 | printSuccess "${FUNCNAME[0]}" 674 | } 675 | 676 | testZabbixDiscoverSleep() { 677 | #Add sleep 678 | AddSleepToConfig 679 | 680 | testZabbixDiscoverReturnsData 681 | printSuccess "${FUNCNAME[0]}" 682 | } 683 | 684 | testDiscoverScriptRunDuration() { 685 | START_TIME=$(date +%s%N) 686 | DATA=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status") 687 | END_TIME=$(date +%s%N) 688 | ELAPSED_TIME=$(echo "($END_TIME - $START_TIME)/1000000" | bc) 689 | CHECK_OK_COUNT=$(echo "$DATA" | grep -o -F "execution time OK" | wc -l) 690 | STOP_OK_COUNT=$(echo "$DATA" | grep -o -F "stop required" | wc -l) 691 | MAX_TIME=$(echo "$ZABBIX_TIMEOUT * 1000" | bc) 692 | 693 | printYellow "Elapsed time $ELAPSED_TIME ms" 694 | printYellow "Success time checks: $CHECK_OK_COUNT" 695 | printYellow "Stop time checks: $STOP_OK_COUNT" 696 | 697 | assertTrue "The script worked for too long" "[ $ELAPSED_TIME -lt $MAX_TIME ]" 698 | printSuccess "${FUNCNAME[0]}" 699 | } 700 | 701 | testZabbixDiscoverRunDuration() { 702 | #Add sleep 703 | AddSleepToConfig 704 | 705 | START_TIME=$(date +%s%N) 706 | DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"]) 707 | END_TIME=$(date +%s%N) 708 | ELAPSED_TIME=$(echo "($END_TIME - $START_TIME)/1000000" | bc) 709 | MAX_TIME=$(echo "$ZABBIX_TIMEOUT * 1000" | bc) 710 | 711 | printYellow "Elapsed time $ELAPSED_TIME ms" 712 | 713 | assertTrue "The script worked for too long" "[ $ELAPSED_TIME -lt $MAX_TIME ]" 714 | printSuccess "${FUNCNAME[0]}" 715 | } 716 | 717 | testDiscoverScriptDoubleRun() { 718 | DATA_FIRST=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status") 719 | DATA_SECOND=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status") 720 | 721 | assertNotEquals "Multiple discovery routines provide the same results: $DATA_FIRST" "$DATA_FIRST" "$DATA_SECOND" 722 | printSuccess "${FUNCNAME[0]}" 723 | } 724 | 725 | testZabbixDiscoverDoubleRun() { 726 | #Add sleep 727 | AddSleepToConfig 728 | 729 | DATA_FIRST=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"]) 730 | DATA_SECOND=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"]) 731 | 732 | assertNotEquals "Multiple discovery routines provide the same results: $DATA_FIRST" "$DATA_FIRST" "$DATA_SECOND" 733 | printSuccess "${FUNCNAME[0]}" 734 | } 735 | 736 | function discoverAllZabbix() { 737 | DATA_OLD=$1 738 | DATA_COUNT=$2 739 | 740 | if [[ -z $DATA_COUNT ]]; then 741 | DATA_COUNT=0 742 | fi 743 | 744 | DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"]) 745 | if [[ -n "$DATA" ]] && [[ -n "$DATA_OLD" ]] && [[ "$DATA_OLD" == "$DATA" ]]; then 746 | echo "$DATA" 747 | return 0 748 | else 749 | DATA_COUNT=$(echo "$DATA_COUNT + 1" | bc) 750 | if [[ $DATA_COUNT -gt $MAX_CHECKS ]]; then 751 | printYellow "Data old:" 752 | printDebug "$DATA_OLD" 753 | printYellow "Data new:" 754 | printDebug "$DATA" 755 | return 1 756 | fi 757 | discoverAllZabbix "$DATA" "$DATA_COUNT" 758 | STATUS=$? 759 | return $STATUS 760 | fi 761 | } 762 | 763 | checkNumberOfPools() { 764 | POOL_TYPE=$1 765 | CHECK_COUNT=$2 766 | 767 | DATA=$(discoverAllZabbix) 768 | STATUS=$? 769 | if [[ $STATUS -ne 0 ]]; then 770 | echo "$DATA" 771 | return 1 772 | fi 773 | assertEquals "Failed to discover all data when checking pools '$POOL_TYPE'" "0" "$STATUS" 774 | 775 | NUMBER_OF_POOLS=$(echo "$DATA" | grep -o -F "{\"{#POOLNAME}\":\"$POOL_TYPE" | wc -l) 776 | PHP_COUNT=$(getNumberOfPHPVersions) 777 | if [[ -n "$CHECK_COUNT" ]] && [[ "$CHECK_COUNT" -ge 0 ]]; then 778 | POOLS_BY_DESIGN="$CHECK_COUNT" 779 | else 780 | POOLS_BY_DESIGN=$(echo "$PHP_COUNT * $MAX_POOLS" | bc) 781 | fi 782 | assertEquals "Number of '$POOL_TYPE' pools mismatch" "$POOLS_BY_DESIGN" "$NUMBER_OF_POOLS" 783 | echo "$DATA" 784 | return 0 785 | } 786 | 787 | testZabbixDiscoverNumberOfSocketPools() { 788 | local DATA 789 | DATA=$(checkNumberOfPools "socket") 790 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 791 | echo "$DATA" 792 | travis_fold_end 793 | printSuccess "${FUNCNAME[0]}" 794 | } 795 | 796 | testZabbixDiscoverNumberOfDynamicPools() { 797 | local DATA 798 | DATA=$(checkNumberOfPools "dynamic") 799 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 800 | echo "$DATA" 801 | travis_fold_end 802 | printSuccess "${FUNCNAME[0]}" 803 | } 804 | 805 | testZabbixDiscoverNumberOfOndemandPoolsCold() { 806 | local DATA 807 | #If the pools are not started then we have 0 here: 808 | DATA=$(checkNumberOfPools "ondemand" 0) 809 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 810 | echo "$DATA" 811 | travis_fold_end 812 | printSuccess "${FUNCNAME[0]}" 813 | } 814 | 815 | testZabbixDiscoverNumberOfOndemandPoolsHot() { 816 | startOndemandPoolsCache 817 | local DATA 818 | DATA=$(checkNumberOfPools "ondemand") 819 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 820 | echo "$DATA" 821 | travis_fold_end 822 | printSuccess "${FUNCNAME[0]}" 823 | } 824 | 825 | testZabbixDiscoverNumberOfOndemandPoolsCache() { 826 | startOndemandPoolsCache 827 | 828 | printAction "Empty cache test..." 829 | INITIAL_DATA=$(checkNumberOfPools "ondemand") 830 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 831 | echo "$INITIAL_DATA" 832 | travis_fold_end 833 | 834 | WAIT_TIMEOUT=$(echo "$ONDEMAND_TIMEOUT * 2" | bc) 835 | sleep "$WAIT_TIMEOUT" 836 | 837 | printAction "Full cache test..." 838 | CACHED_DATA=$(checkNumberOfPools "ondemand") 839 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 840 | echo "$CACHED_DATA" 841 | travis_fold_end 842 | 843 | assertEquals "Data mismatch" "$INITIAL_DATA" "$CACHED_DATA" 844 | printSuccess "${FUNCNAME[0]}" 845 | } 846 | 847 | testZabbixDiscoverNumberOfIPPools() { 848 | PHP_COUNT=$(getNumberOfPHPVersions) 849 | local DATA 850 | DATA=$(checkNumberOfPools "localhost" "$PHP_COUNT") 851 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 852 | echo "$DATA" 853 | travis_fold_end 854 | printSuccess "${FUNCNAME[0]}" 855 | } 856 | 857 | testZabbixDiscoverNumberOfPortPools() { 858 | local DATA 859 | DATA=$(checkNumberOfPools "port") 860 | travis_fold_start "${FUNCNAME[0]}" "ⓘ Zabbix response" 861 | echo "$DATA" 862 | travis_fold_end 863 | printSuccess "${FUNCNAME[0]}" 864 | } 865 | 866 | #This test should be last in Zabbix tests 867 | testDiscoverScriptManyPools() { 868 | #Create lots of pools 869 | MAX_POOLS=20 870 | MAX_PORTS=20 871 | setupPools 872 | 873 | testDiscoverScriptReturnsData 874 | printSuccess "${FUNCNAME[0]}" 875 | } 876 | 877 | testZabbixDiscoverManyPools() { 878 | testZabbixDiscoverReturnsData 879 | printSuccess "${FUNCNAME[0]}" 880 | } 881 | 882 | testDiscoverScriptManyPoolsRunDuration() { 883 | MAX_RUNS=5 884 | for ((c = 1; c <= MAX_RUNS; c++)); do 885 | printAction "Run #$c..." 886 | testDiscoverScriptRunDuration 887 | done 888 | printSuccess "${FUNCNAME[0]}" 889 | } 890 | 891 | testZabbixDiscoverManyPoolsRunDuration() { 892 | MAX_RUNS=5 893 | for ((c = 1; c <= MAX_RUNS; c++)); do 894 | printAction "Run #$c..." 895 | testZabbixDiscoverRunDuration 896 | done 897 | printSuccess "${FUNCNAME[0]}" 898 | } 899 | 900 | # Load shUnit2. 901 | . shunit2 902 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------