├── composer.json ├── icingaexchange.yml ├── .travis.yml ├── LICENSE ├── .gitignore ├── CHANGELOG.md ├── README.md └── check_php /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cytopia/check_php", 3 | "description": "Nagios or Icinga plugin to check for php startup errors.", 4 | "type": "library", 5 | "keywords": ["nagios", "nagios-plugin", "icinga", "icinga2", "php", "php-error"], 6 | "homepage": "https://github.com/cytopia/check_php", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name" : "Patrick Plocke", 11 | "homepage": "https://github.com/cytopia", 12 | "role": "Developer" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /icingaexchange.yml: -------------------------------------------------------------------------------- 1 | name: check_php 2 | description: "file:///README.md" 3 | url: "https://github.com/cytopia/check_php" 4 | tags: PHP, Security 5 | vendor: cytopia 6 | target: Operating System 7 | type: Plugin 8 | license: MIT 9 | releases: 10 | - 11 | name: 0.7 12 | description: "0.7 Release" 13 | files: 14 | - 15 | name: check_php 16 | url: "file:///check_php" 17 | description: "Check for PHP errors, sec updates and php.ini settings" 18 | checksum: 31ca5f07a7f390bcf3d806e1c14eb324 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: sh 2 | 3 | before_script: 4 | - sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty-backports restricted main universe" 5 | - sudo add-apt-repository -y ppa:ondrej/php 6 | - sudo apt-get update -qq 7 | - sudo apt-get install -qq shellcheck 8 | - sudo apt-get install -qq php5.6 9 | 10 | script: 11 | - shellcheck --shell=sh check_php 12 | - sh check_php 13 | - sh check_php -s w 14 | - sh check_php -s e 15 | - sh check_php -u w || true 16 | - sh check_php -u e || true 17 | - sh check_php -c max_execution_time 0 w 18 | - sh check_php -c max_execution_time 0 e 19 | - sh check_php -m json w 20 | - sh check_php -m json e 21 | - sh check_php -s e -u e -m json e -c max_execution_time 0 e || true 22 | - sh check_php -V 23 | - sh check_php -h 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 cytopia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###################################### 2 | # CUSTOM 3 | ###################################### 4 | 5 | build/* 6 | !build/.keepme 7 | 8 | 9 | ###################################### 10 | # GENERIC 11 | ###################################### 12 | 13 | ###### std ###### 14 | .lock 15 | *.log 16 | 17 | ###### patches/diffs ###### 18 | *.patch 19 | *.diff 20 | *.orig 21 | *.rej 22 | 23 | 24 | ###################################### 25 | # Operating Systems 26 | ###################################### 27 | 28 | ###### OSX ###### 29 | ._* 30 | .DS* 31 | .Spotlight-V100 32 | .Trashes 33 | 34 | ###### Windows ###### 35 | Thumbs.db 36 | ehthumbs.db 37 | Desktop.ini 38 | $RECYCLE.BIN/ 39 | *.lnk 40 | 41 | 42 | ###################################### 43 | # Editors 44 | ###################################### 45 | 46 | ###### Sublime ###### 47 | *.sublime-workspace 48 | *.sublime-project 49 | 50 | ###### Eclipse ###### 51 | .classpath 52 | .buildpath 53 | .project 54 | .settings/ 55 | 56 | ###### Netbeans ###### 57 | nbproject/private/ 58 | 59 | ###### Intellij IDE ###### 60 | .idea/ 61 | .idea_modules/ 62 | 63 | ###### vim ###### 64 | *.swp 65 | *.swo 66 | *~ 67 | 68 | ###### TextMate ###### 69 | .tm_properties 70 | *.tmproj 71 | 72 | ###### BBEdit ###### 73 | *.bbprojectd 74 | *.bbproject 75 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Version 0.8 (unreleased) 2 | ----------- 3 | 4 | 5 | Version 0.7 6 | ----------- 7 | - [Fix] Fixed check for PHP startup-errors 8 | 9 | 10 | Version 0.6 11 | ----------- 12 | 13 | - [Fix] Also check 4er and 7er PHP versions against updates 14 | 15 | 16 | Version 0.5 17 | ----------- 18 | 19 | - [Enh] Enhance documentation 20 | - [Enh] Add to Icinga/Nagios Exchange 21 | 22 | Version 0.4 23 | ----------- 24 | 25 | - [Enh] Performance data: min+max values 26 | - [Enh] Performance data: warn+crit thresholds 27 | - [Enh] Added ability to check for blacklisted PHP modules 28 | - [Fix] Performance data: fixed error and warning count 29 | 30 | Version 0.3 31 | ----------- 32 | 33 | - [Enh] Always display current PHP version in nagios output 34 | - [Enh] Choose severity level for all checks (error or warning) 35 | - [Enh] Remote checks now also check for wget, curl or fetch and only require one of them 36 | 37 | Version 0.2 38 | ----------- 39 | 40 | - [Enh] Warn on PHP startup errors (instead of error) by default if no severity is specified 41 | - [Enh] Check against PHP startup errors by default (without any arguments) 42 | - [Enh] Check against compiled modules 43 | - [Enh] Check for php.ini misconfiguration 44 | - [Enh] Performance data 45 | 46 | Version 0.1 47 | ----------- 48 | 49 | - [Enh] Check for PHP startup Errors 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # check_php 2 | 3 | check_php is a POSIX compliant nagios plugin that will check for PHP startup errors (`-s`), missing PHP modules (`-m`), misconfigured directives in php.ini (`-c`) and for available PHP updates (`-u`). This plugin supports performance data (error and warning counts over time) and long output (exact detail about all problems). 4 | 5 | [![Build Status](https://travis-ci.org/cytopia/check_php.svg?branch=master)](https://travis-ci.org/cytopia/check_php) 6 | [![Latest Stable Version](https://poser.pugx.org/cytopia/check_php/v/stable)](https://packagist.org/packages/cytopia/check_php) 7 | [![Total Downloads](https://poser.pugx.org/cytopia/check_php/downloads)](https://packagist.org/packages/cytopia/check_php) 8 | [![Latest Unstable Version](https://poser.pugx.org/cytopia/check_php/v/unstable)](https://packagist.org/packages/cytopia/check_php) 9 | [![License](https://poser.pugx.org/cytopia/check_php/license)](http://opensource.org/licenses/MIT) 10 | [![POSIX](https://img.shields.io/badge/posix-100%25-brightgreen.svg)](https://en.wikipedia.org/?title=POSIX) 11 | [![Type](https://img.shields.io/badge/type-%2Fbin%2Fsh-red.svg)](https://en.wikipedia.org/?title=Bourne_shell) 12 | 13 | [Nagios Configuration](#1-nagios-configuration) | 14 | [Icinga2 Configuration](#2-icinga2-configuration) | 15 | [Usage](#3-usage) | 16 | [Examples](#4-examples) | 17 | [License](#5-license) | 18 | [Contributors](#6-contributors) | 19 | [Awesome](#7-awesome) 20 | 21 | --- 22 | 23 | | [![Awesome-Nagios-Plugins](https://raw.githubusercontent.com/cytopia/awesome-nagios-plugins/master/doc/img/awesome-nagios.png)](https://github.com/cytopia/awesome-nagios-plugins) | Find more plugins at [Awesome Nagios](https://github.com/cytopia/awesome-nagios-plugins) | 24 | |---|---| 25 | | [![Icinga Exchange](https://raw.githubusercontent.com/cytopia/awesome-nagios-plugins/master/doc/img/icinga.png)](https://exchange.icinga.com/cytopia) | **Find more plugins at [Icinga Exchange](https://exchange.icinga.com/cytopia)** | 26 | | [![Nagios Exchange](https://raw.githubusercontent.com/cytopia/awesome-nagios-plugins/master/doc/img/nagios.png)](https://exchange.nagios.org/directory/Owner/cytopia/1) | **Find more plugins at [Nagios Exchange](https://exchange.nagios.org/directory/Owner/cytopia/1)** | 27 | 28 | --- 29 | 30 | ##### Requirements 31 | | Program | Required | Description | 32 | | ------------- | ------------- | -------- | 33 | | bourne shell (sh) | yes | The whole script is written in pure bourne shell (sh) and is 100% Posix compliant | 34 | | [check_by_ssh](https://www.monitoring-plugins.org/doc/man/check_by_ssh.html) | yes | This nagios plugin is used as a wrapper to check on remote hosts | 35 | | wget, curl or fetch | Optional | Either one of them is required if you want to check against PHP updates. (`-u`) | 36 | 37 | ##### Features 38 | * Check for PHP startup errors 39 | * Check for PHP updates (inside minor versions and patch levels) 40 | * Check for missing PHP modules 41 | * Check for blacklisted PHP modules and throw err/warn if they are compiled in 42 | * Check for expected php.ini config directives (e.g.: date.timezone must be "Europe/Berlin", etc) 43 | * Each check can specify its own severity (warning or error) 44 | 45 | ##### Motivation 46 | If you have to take care about many servers which have PHP installed you can use this plugin to make sure that all servers or all groups of server use the same configuration with the same compiled modules and are always up to date. 47 | 48 | 49 | ## 1. Nagios Configuration 50 | 51 | ### 1.1 Command definition 52 | In order to check php on remote servers you will need to make use of `check_by_ssh`. 53 | ```bash 54 | name: check_by_ssh_php 55 | command: $USER1$/check_by_ssh -H $HOSTADDRESS$ -t 60 -l "$USER17$" -C "$USER22$/check_php $ARG1$" 56 | ``` 57 | ### 1.2 Service definition 58 | In the above command definition there is only one argument variable assigned to `check_php`: `$ARG1`. So you can easily assign all required arguments to this single variable in the service definition: 59 | ```bash 60 | check command: check_by_ssh_php 61 | $ARG1$: -s e -u w -m curl e -m gettext e -m openssl e -m json e 62 | ``` 63 | 64 | ## 2. Icinga2 Configuration 65 | 66 | ### 2.1 Command definition 67 | ```javascript 68 | /* 69 | * Check PHP health 70 | */ 71 | object CheckCommand "php" { 72 | import "plugin-check-command" 73 | 74 | command = [ PluginDir + "/check_php" ] 75 | 76 | arguments = { 77 | "-s" = { 78 | value = "$php_startup$" 79 | description = "Check for PHP startup errors and display warning or error if any exists. Allowed values are 'w' for warnings and 'e' for critical errors." 80 | } 81 | "-u" = { 82 | value = "$php_updates$" 83 | description = "Check for updated PHP version online. Allowed values are 'w' for warnings and 'e' for critical errors. This check requires wget, curl or fetch." 84 | } 85 | "-p" = { 86 | value = "$php_binary$" 87 | description = "Optional path to PHP binary. This argument allows to define a certain PHP binary to be checked. If none is defined, the default PHP version will be used." 88 | } 89 | "-d" = { 90 | value = "$php_delimiter$" 91 | description = "Delimiter for multi-value arguments." 92 | } 93 | "-m" = { 94 | value = "$php_modules$" 95 | description = "Check for required modules." 96 | repeat_key = true 97 | } 98 | "-b" = { 99 | value = "$php_blacklist$" 100 | description = "Check for blacklisted modules." 101 | repeat_key = true 102 | } 103 | "-c" = { 104 | value = "$php_config$" 105 | description = "Check PHP setting directives that diverge from the given default value." 106 | repeat_key = true 107 | } 108 | "-v" = { 109 | set_if = "$php_verbose$" 110 | description = "Enable verbose mode." 111 | } 112 | } 113 | } 114 | ``` 115 | 116 | ### 2.2 Service definition example (using apply) 117 | ```javascript 118 | /* 119 | * PHP Health 120 | */ 121 | apply Service "php-" for (php => config in host.vars.php) { 122 | check_command = "php" 123 | // Assuming your PHP setup doesn't change too often, we don't 124 | // bother to check twice a day only. 125 | check_interval = 12h 126 | 127 | display_name = "PHP " + php 128 | notes = "Checks currently installed PHP " + php + " health." 129 | 130 | // Service variables from php definition. 131 | vars += config 132 | vars.php_delimiter = "|" 133 | if ( config.php_modules ) { 134 | vars.php_modules = [] 135 | for (key => value in config.php_modules) { 136 | vars.php_modules += [ key + vars.php_delimiter + value ] 137 | } 138 | } 139 | if ( config.php_blacklist ) { 140 | vars.php_blacklist = [] 141 | for (key => value in config.php_blacklist) { 142 | vars.php_blacklist += [ key + vars.php_delimiter + value ] 143 | } 144 | } 145 | if ( config.php_config ) { 146 | vars.php_config = [] 147 | for (key => value in config.php_config) { 148 | vars.php_config += [ key + vars.php_delimiter + value["default"] + vars.php_delimiter + value["severity"] ] 149 | } 150 | } 151 | 152 | // Application rules. 153 | assign where host.name = NodeName && host.vars.php 154 | } 155 | ``` 156 | 157 | ### 2.3 Host object definition 158 | ```javascript 159 | object Host "node.example.com" { 160 | 161 | // Other settings. 162 | vars.php[ "7.1" ] = { 163 | php_binary = "/opt/php/7.1/bin/php" 164 | php_updates = "w" 165 | php_startup = "e" 166 | php_modules = { 167 | intl = "w" 168 | mbstring = "w" 169 | soap = "w" 170 | apcu = "w" 171 | memcached = "w" 172 | geoip = "w" 173 | mongodb = "w" 174 | imagick = "w" 175 | redis = "w" 176 | openssl = "w" 177 | xml = "w" 178 | json = "w" 179 | curl = "w" 180 | } 181 | php_blacklist = { 182 | mcrypt = "w" 183 | } 184 | php_config = { 185 | "date.timezone" = { 186 | "default" = "Europe/Berlin" 187 | "severity" = "w" 188 | } 189 | } 190 | } 191 | } 192 | ``` 193 | 194 | 195 | ## 3. Usage 196 | 197 | Each argument allows you to specify which severity should be triggered (``), where `w` triggers a warning and `e` triggers an error. 198 | Arguments that can be used multiple times (`-m` and `-c`) can of course use different severities each time. All severities will be aggregated and the highest severity (error > warning) will determine the final state. 199 | 200 | ```bash 201 | Usage: check_php [-s ] [-u ] [-m ] [-b [-c ] [-p ] [-d ] [-v] 202 | check_php -h 203 | check_php -V 204 | 205 | Nagios plugin that will check if PHP exists, for PHP startup errors, 206 | missing modules, misconfigured directives and available updates. 207 | 208 | -s [single] Check for PHP startup errors and display 209 | nagios warning or error if any exists. 210 | Warning: -s w 211 | Error: -s e 212 | 213 | -u [single] Check for updated PHP version online. (requires wget, curl or fetch) 214 | Will only check for patch updates and will not notify if your current version 215 | PHP 5.5 and there is already PHP 5.6 out there. 216 | 217 | -m [multiple] Require compiled PHP module and display 218 | nagios warning/error if the module was not compiled against PHP. 219 | Use multiple times to check against multiple modules. 220 | Example: -m "mysql" w -m "mysqli" e 221 | 222 | -b [multiple] Check PHP for modules that should not be compiled in and display 223 | nagios warning/error if the module is compiled against PHP. 224 | Use multiple times to check for multiple blacklisted modules. 225 | Example: -b "imagick" w -b "tidy" e 226 | 227 | -c [multiple] Check for misconfigured directives in php.ini and display 228 | nagios warning/error if the configuration does not match. 229 | Use multiple times to check against multiple configurations. 230 | Example: -c "date.timezone" "Europe/Berlin" e 231 | 232 | -p [optional] Define the path to the PHP binary that shall be used. 233 | If no value is given, the current user's default PHP version will be checked. 234 | Example: -p "/usr/bin/php" 235 | 236 | -d [optional] Delimiter used to concatenate arguments of the above options 237 | that require multiple values. 238 | Example: -d "|" -m "mysql|w" -b "mcrypt|w" -c "date.timezone|Europe/Berlin|e" 239 | 240 | -v Be verbose (Show PHP Version and Zend Engine Version) 241 | 242 | -h Display help 243 | 244 | -V Display version 245 | ``` 246 | 247 | 248 | ## 4. Examples 249 | 250 | Checking against prefered timezone and compiled module `mysql` 251 | 252 | ```bash 253 | $ check_php -c "date.timezone" "Europe/Berlin" e -m mysql e 254 | [ERR] PHP 5.6.16 has errors: Missing module(s) | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; 255 | [CRITICAL] Module: "mysql" not available 256 | [OK] Config "date.timezone" = "Europe/Berlin" 257 | ``` 258 | 259 | Checking for PHP startup errors 260 | 261 | ```bash 262 | $ check_php -s w 263 | [WARN] PHP 5.6.16 has warning: Startup errors | 'OK'=0;;;; 'Errors'=0;;;; 'Warnings'=1;;;; 'Unknown'=0;;;; 264 | [WARNING] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226/test' - dlopen(/usr/local/Cellar/php56/5.6.14/lib/php/extensions/no-debug-non-zts-20131226/test, 9): image not found in Unknown on line 0 265 | ``` 266 | 267 | Combine multiple module checks 268 | 269 | ```bash 270 | $ check_php -m mysql e -m mysqli w -m mbstring w 271 | [OK] PHP 5.6.16 is healthy | 'OK'=1;;;; 'Errors'=0;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; 272 | [OK] Module: "mysql" available 273 | [OK] Module: "mysqli" available 274 | [OK] Module: "mbstring" available 275 | ``` 276 | 277 | Checking for PHP Updates (OK) 278 | ```bash 279 | $ check_php -u e 280 | [OK] PHP 5.6.16 is healthy | 'OK'=1;;;; 'Errors'=0;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; 281 | [OK] No PHP startup errors 282 | [OK] PHP Version 5.6.14 up to date. 283 | ``` 284 | 285 | Checking for PHP Updates (Updates available) 286 | ```bash 287 | $ check_php -u e 288 | [ERR] PHP 5.6.13 has errors: Updates available | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=-;;;; 'Unknown'=0;;;; 289 | [OK] No PHP startup errors 290 | [CRITICAL] PHP Version 5.6.13 too old. Latest: 5.6.14. 291 | ``` 292 | 293 | Checking for PHP Updates (Able to differentiate between PHP 5.4, 5.5 and 5.6) 294 | ```bash 295 | $ check_php -u e 296 | [ERR] PHP 5.5.1 has errors: Updates available | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; 297 | [OK] No PHP startup errors 298 | [CRITICAL] PHP Version 5.5.1 too old. Latest: 5.5.30. 299 | ``` 300 | 301 | A lot of options combined 302 | ```bash 303 | $ check_php -s w -m mysql e -m mbstring e -m xml e -c date.timezone 'Europe/Berlin' e -c session.cookie_secure "On" e -u e -v 304 | [ERR] PHP 5.6.14 has errors: Wrong config | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;; 305 | [OK] No PHP startup errors 306 | [OK] PHP Version 5.6.14 up to date. 307 | [OK] Module: "mysql" available 308 | [OK] Module: "mbstring" available 309 | [OK] Module: "xml" available 310 | [OK] Config "date.timezone" = "Europe/Berlin" 311 | [CRITICAL] Config "session.cookie_secure" = "Off", excpected: "On" 312 | PHP 5.6.14 313 | Zend Engine v2.6.0 314 | ``` 315 | 316 | 317 | ## 5. License 318 | 319 | [![license](https://poser.pugx.org/cytopia/check_php/license)](http://opensource.org/licenses/mit) 320 | 321 | 322 | ## 6. Contributors 323 | 324 | * [cytopia](https://github.com/cytopia) 325 | * [MarioSteinitz](https://github.com/MarioSteinitz) 326 | 327 | 328 | ## 7. Awesome 329 | 330 | Added by the following [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) lists: 331 | 332 | * [awesome-nagios-plugins](https://github.com/cytopia/awesome-nagios-plugins) 333 | -------------------------------------------------------------------------------- /check_php: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | ################################################################################ 5 | # 6 | # V A R I A B L E S 7 | # 8 | ################################################################################ 9 | INFO_AUTHOR="cytopia " 10 | INFO_GPGKEY="0x695128A2" 11 | INFO_LICENSE="MIT" 12 | INFO_NAME="check_php" 13 | INFO_DATE="2018-11-04" 14 | INFO_VERSION="0.8" 15 | 16 | 17 | # Check for performance data: 18 | # http://nagios.sourceforge.net/docs/3_0/pluginapi.html 19 | # Nagios error codes 20 | EXIT_OK=0 21 | EXIT_WARN=1 22 | EXIT_ERR=2 23 | EXIT_UNKNOWN=3 24 | 25 | 26 | if ! command -v php > /dev/null 2>&1 ; then 27 | printf "[UNKNOWN] PHP not found.\n" 28 | exit $EXIT_UNKNOWN 29 | fi 30 | 31 | PHP="$(which php)" 32 | 33 | 34 | 35 | ################################################################################ 36 | # 37 | # F U N C T I O N S 38 | # 39 | ################################################################################ 40 | 41 | ############################################################ 42 | # Misc Functions 43 | ############################################################ 44 | 45 | print_usage() { 46 | printf "Usage: %s [-s ] [-u ] [-m ] [-b [-c ] [ -p ] [ -d ] [-v]\n" "${INFO_NAME}" 47 | printf " %s -h\n" "${INFO_NAME}" 48 | printf " %s -V\n\n" "${INFO_NAME}" 49 | printf "Nagios plugin that will check if PHP exists, for PHP startup errors,\n" 50 | printf "missing modules, misconfigured directives and available updates.\n\n" 51 | printf " -s [single] Check for PHP startup errors and display\n" 52 | printf " nagios warning or error if any exists.\n" 53 | printf " Warning: -s w\n" 54 | printf " Error: -s e\n\n" 55 | printf " -u [single] Check for updated PHP version online. (requires wget, curl or fetch)\n" 56 | printf " Will only check for patch updates and will not notify if your current version\n" 57 | printf " PHP 5.5 and there is already PHP 5.6 out there.\n\n" 58 | printf " -m [multiple] Require compiled PHP module and display\n" 59 | printf " nagios warning/error if the module was not compiled against PHP.\n" 60 | printf " Use multiple times to check against multiple modules.\n" 61 | printf " Example: -m \"mysql\" w -m \"mysqli\" e\n\n" 62 | printf " -b [multiple] Check PHP for modules that should not be compiled in and display\n" 63 | printf " nagios warning/error if the module is compiled against PHP.\n" 64 | printf " Use multiple times to check for multiple blacklisted modules.\n" 65 | printf " Example: -b \"imagick\" w -b \"tidy\" e\n\n" 66 | printf " -c [multiple] Check for misconfigured directives in php.ini and display\n" 67 | printf " nagios warning/error if the configuration does not match.\n" 68 | printf " Use multiple times to check against multiple configurations.\n" 69 | printf " Example: -c \"date.timezone\" w -c \"Europe/Berlin\" e\n\n" 70 | printf " -p [optional] Define the path to the PHP binary that shall be used.\n" 71 | printf " If no value is given, the current user's default PHP version will be checked.\n\n" 72 | printf " -d [optional] Delimiter used to concatenate arguments of the above options\n" 73 | printf " that require multiple values.\n" 74 | printf " Example: -d \"|\" -m \"mysqli|w\" -b \"mcrypt|w\" -c \"date.timezone|Europe/Berlin|e\"\n\n" 75 | printf " -v Be verbose (Show PHP Version and Zend Engine Version)\n\n" 76 | printf " -h Display help\n\n" 77 | printf " -V Display version\n" 78 | } 79 | 80 | print_version() { 81 | printf "Version: %s %s (%s)\n" "${INFO_NAME}" "${INFO_VERSION}" "${INFO_DATE}" 82 | printf "Author: %s (%s)\n" "${INFO_AUTHOR}" "${INFO_GPGKEY}" 83 | printf "License: %s\n" "${INFO_LICENSE}" 84 | } 85 | 86 | merge_text() { 87 | CURR_TEXT="$1" 88 | NEXT_TEXT="$2" 89 | SEPARATOR="$3" 90 | 91 | if [ "$SEPARATOR" = "" ]; then 92 | SEPARATOR="\n" 93 | fi 94 | 95 | if [ "$CURR_TEXT" = "" ]; then 96 | CURR_TEXT="$NEXT_TEXT" 97 | else 98 | CURR_TEXT="${CURR_TEXT}${SEPARATOR}${NEXT_TEXT}" 99 | fi 100 | echo "${CURR_TEXT}" 101 | } 102 | 103 | merge_exit_codes() { 104 | CURR_EXIT="$1" 105 | NEXT_EXIT="$2" 106 | 107 | if [ "$CURR_EXIT" = "0" ]; then 108 | CURR_EXIT="$NEXT_EXIT" 109 | elif [ "$CURR_EXIT" = "1" ]; then 110 | if [ "$NEXT_EXIT" = "0" ]; then 111 | CURR_EXIT="1" 112 | elif [ "$NEXT_EXIT" = "1" ]; then 113 | CURR_EXIT="1" 114 | elif [ "$NEXT_EXIT" = "2" ]; then 115 | CURR_EXIT="2" 116 | elif [ "$NEXT_EXIT" = "3" ]; then # UNKNOWN -> WARNING 117 | CURR_EXIT="1" 118 | fi 119 | elif [ "$CURR_EXIT" = "2" ]; then 120 | CURR_EXIT="2" 121 | elif [ "$CURR_EXIT" = "3" ]; then 122 | if [ "$NEXT_EXIT" = "0" ]; then 123 | CURR_EXIT="3" 124 | elif [ "$NEXT_EXIT" = "1" ]; then 125 | CURR_EXIT="1" 126 | elif [ "$NEXT_EXIT" = "2" ]; then 127 | CURR_EXIT="2" 128 | elif [ "$NEXT_EXIT" = "3" ]; then # UNKNOWN -> WARNING 129 | CURR_EXIT="3" 130 | fi 131 | fi 132 | echo "$CURR_EXIT" 133 | return $CURR_EXIT 134 | } 135 | 136 | get_php_version() { 137 | 138 | # Current installed version 139 | CMD="$PHP -v 2>/dev/null | grep -oE '^PHP\s[0-9]+\.[0-9]+\.[0-9]+' | awk '{ print \$2}'" 140 | PHP_VERSION="$(eval "$CMD")" 141 | 142 | echo "$PHP_VERSION" 143 | } 144 | 145 | check_version() { 146 | # Current installed version 147 | PHP_VERSION="$(get_php_version)" 148 | 149 | PHP_MAJOR="$(echo "$PHP_VERSION" | awk -F'[.]' '{print $1}')" 150 | PHP_MINOR="$(echo "$PHP_VERSION" | awk -F'[.]' '{print $2}')" 151 | PHP_PATCH="$(echo "$PHP_VERSION" | awk -F'[.]' '{print $3}')" 152 | 153 | # Latest available versions 154 | if command -v wget >/dev/null 2>&1; then 155 | PHP_LATEST="$(wget -qO- "https://secure.php.net/releases/index.php?json&version=${PHP_MAJOR}&max=100" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -n -k1,1 -k2,2 -k3,3 -u -r)" 156 | elif command -v curl >/dev/null 2>&1; then 157 | PHP_LATEST="$(curl --silent "https://secure.php.net/releases/index.php?json&version=${PHP_MAJOR}&max=100" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -n -k1,1 -k2,2 -k3,3 -u -r)" 158 | elif command -v fetch >/dev/null 2>&1; then 159 | PHP_LATEST="$(fetch --no-verify-hostname --no-verify-peer --quiet --output=- "https://secure.php.net/releases/index.php?json&version=${PHP_MAJOR}&max=100" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -n -k1,1 -k2,2 -k3,3 -u -r)" 160 | else 161 | echo "[UNKNOW] - check version requires wget, curl or fetch" 162 | exit "$EXIT_UNKNOWN" 163 | fi 164 | 165 | 166 | for v in $PHP_LATEST; do 167 | 168 | PHP_LATEST_MAJOR="$(echo "$v" | awk -F'[.]' '{print $1}')" 169 | PHP_LATEST_MINOR="$(echo "$v" | awk -F'[.]' '{print $2}')" 170 | PHP_LATEST_PATCH="$(echo "$v" | awk -F'[.]' '{print $3}')" 171 | 172 | # Get Major version 173 | if [ "$PHP_LATEST_MAJOR" = "$PHP_MAJOR" ]; then 174 | # Get Minor version 175 | if [ "$PHP_LATEST_MINOR" = "$PHP_MINOR" ]; then 176 | # Get Patch version 177 | if [ "$PHP_LATEST_PATCH" -gt "$PHP_PATCH" ]; then 178 | echo "PHP Version $PHP_VERSION too old. Latest: ${PHP_LATEST_MAJOR}.${PHP_LATEST_MINOR}.${PHP_LATEST_PATCH}." 179 | return 2 180 | elif [ "$PHP_LATEST_PATCH" -eq "$PHP_PATCH" ]; then 181 | echo "PHP Version $PHP_VERSION up to date." 182 | return 0 183 | else 184 | echo "PHP Version $PHP_VERSION too new. Latest: ${PHP_LATEST_MAJOR}.${PHP_LATEST_MINOR}.${PHP_LATEST_PATCH}." 185 | return 3 186 | fi 187 | fi 188 | fi 189 | done 190 | 191 | echo "No PHP Version found online. Your version: $PHP_VERSION" 192 | return 3 193 | 194 | } 195 | 196 | 197 | # Make sure not to display any errors to stdout 198 | # and store them in a variable to output it in a formated way. 199 | check_startup_errors() { 200 | CMD="$PHP -d display_errors=stderr -d display_startup_errors=1 -v 3>&1 1>&2 2>&3 1>/dev/null" 201 | ERR="$(eval "$CMD")" 202 | 203 | if [ "$ERR" != "" ]; then 204 | echo "$ERR" 205 | return 1 206 | else 207 | echo "No PHP startup errors" 208 | return 0 209 | fi 210 | } 211 | 212 | check_configurration() { 213 | CONFIG="$1" 214 | VALUE="$2" 215 | 216 | CMD="$PHP -i 2>/dev/null | grep '^${CONFIG}\s' | awk 'BEGIN { FS = \"=>\" } ; {print \$NF}' | xargs" 217 | CURRENT="$(eval "$CMD")" 218 | 219 | if [ "$VALUE" = "$CURRENT" ]; then 220 | echo "Config \"$CONFIG\" = \"$VALUE\"" 221 | return $EXIT_OK 222 | else 223 | echo "Config \"$CONFIG\" = \"$CURRENT\", excpected: \"$VALUE\"" 224 | return $EXIT_ERR 225 | fi 226 | } 227 | 228 | check_module() { 229 | MODULE="$1" 230 | CMD="$PHP -m 2>/dev/null | grep -cE '^${MODULE}$'" 231 | CNT="$(eval "$CMD")" 232 | 233 | if [ "$CNT" = "1" ]; then 234 | echo "Module: \"$MODULE\" available" 235 | return $EXIT_OK 236 | elif [ "$CNT" -gt "1" ]; then 237 | echo "Multiple \"$MODULE\" found: $(eval "$CMD")" 238 | return $EXIT_WARN 239 | else 240 | echo "Module: \"$MODULE\" not available" 241 | return $EXIT_ERR 242 | fi 243 | } 244 | 245 | check_blacklisted_module() { 246 | MODULE="$1" 247 | CMD="$PHP -m 2>/dev/null | grep -cE '^${MODULE}$'" 248 | CNT="$(eval "$CMD")" 249 | 250 | if [ "$CNT" = "0" ]; then 251 | echo "Blacklisted module: \"$MODULE\" not available" 252 | return $EXIT_OK 253 | else 254 | echo "Blacklisted module: \"$MODULE\" available, but not allowed" 255 | return $EXIT_ERR 256 | fi 257 | } 258 | 259 | # Fetch PHP 260 | # --------- 261 | # Checks the given arguments for a '-p' option and sets the PHP 262 | # variable accordingly. 263 | fetch_php() { 264 | while test -n "$1"; do 265 | case "$1" in 266 | # PHP binary otion. 267 | -p) 268 | shift 269 | PHP="$1" 270 | 271 | # Whether the given PHP binary doesn't exist. 272 | if [ ! -x "$PHP" ]; then 273 | echo "PHP binary not found at \"$PHP\" for option \"-p\"." 274 | exit $EXIT_UNKNOWN 275 | fi 276 | 277 | break 278 | ;; 279 | esac 280 | shift 281 | done 282 | } 283 | 284 | # Get delimiter 285 | # ------------- 286 | # Checks the given arguments for a '-d' option and sets the DELIMITER 287 | # variable accordingly. 288 | get_delimiter() { 289 | while test -n "$1"; do 290 | case "$1" in 291 | # Delimiter. 292 | -d) 293 | shift 294 | DELIMITER="$1" 295 | 296 | break 297 | ;; 298 | esac 299 | shift 300 | done 301 | } 302 | 303 | ################################################################################ 304 | # 305 | # E N T R Y P O I N T 306 | # 307 | ################################################################################ 308 | 309 | 310 | ############################################################ 311 | # Parameter 312 | ############################################################ 313 | 314 | 315 | 316 | if [ "$1" = "-h" ]; then 317 | print_usage 318 | exit $EXIT_OK 319 | elif [ "$1" = "-V" ]; then 320 | print_version 321 | exit $EXIT_OK 322 | fi 323 | 324 | # Check for PHP binary option 325 | fetch_php "$@" 326 | 327 | # Check for delimiter 328 | DELIMITER="" 329 | get_delimiter "$@" 330 | 331 | # Extended Status Message 332 | MSG_STARTUP="" 333 | MSG_UPDATE="" 334 | MSG_MODULE="" 335 | MSG_M_BLACKLIST="" 336 | MSG_CONFIG="" 337 | MSG_VERBOSE="" 338 | 339 | # Info for normal Status message if there is an error/warning 340 | HAS_STARTUP_ERROR="" 341 | HAS_UPDATE_ERROR="" 342 | HAS_MODULE_ERROR="" 343 | HAS_M_BLACKLIST_ERROR="" 344 | HAS_CONFIG_ERROR="" 345 | 346 | # Count warnings and errors for performance data 347 | CNT_ALL="0" 348 | CNT_OK="0" 349 | CNT_ERROR="0" 350 | CNT_WARNING="0" 351 | 352 | 353 | # Final exit code 354 | NAGIOS_EXIT="$EXIT_OK" 355 | 356 | 357 | while test -n "$1"; do 358 | case "$1" in 359 | 360 | # ---- 1. Evaluate startup errors 361 | -s) 362 | # Get next arg in list (Exit code) 363 | shift 364 | SEVERITY="$1" 365 | 366 | # Check valid exit code 367 | if [ "$SEVERITY" != "w" ] && [ "$SEVERITY" != "e" ]; then 368 | echo "Invalid value \"$SEVERITY\" for option \"-s\"." 369 | exit $EXIT_UNKNOWN 370 | fi 371 | 372 | # Execute Command 373 | MSG_STARTUP="$(check_startup_errors)" 374 | TMP_EXIT="$?" 375 | 376 | # Merge exit codes 377 | if [ "$TMP_EXIT" != "0" ]; then 378 | if [ "$SEVERITY" = "e" ]; then 379 | CNT_ERROR=$((CNT_ERROR+1)) 380 | MSG_STARTUP="[CRITICAL] ${MSG_STARTUP}" 381 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "2")" 382 | else 383 | CNT_WARNING=$((CNT_WARNING+1)) 384 | MSG_STARTUP="[WARNING] ${MSG_STARTUP}" 385 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "1")" 386 | fi 387 | HAS_STARTUP_ERROR="true" 388 | else 389 | CNT_OK=$((CNT_OK+1)) 390 | MSG_STARTUP="[OK] ${MSG_STARTUP}" 391 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "0")" 392 | fi 393 | CNT_ALL=$((CNT_ALL+1)) 394 | ;; 395 | 396 | 397 | # ---- 2. Evaluate php update version 398 | -u) 399 | # Get next arg in list (Exit code) 400 | shift 401 | SEVERITY="$1" 402 | 403 | # Check valid exit code 404 | if [ "$SEVERITY" != "w" ] && [ "$SEVERITY" != "e" ]; then 405 | echo "Invalid value \"$SEVERITY\" for option \"-u\"." 406 | exit $EXIT_UNKNOWN 407 | fi 408 | 409 | # execute command 410 | MSG_UPDATE="$(check_version)" 411 | TMP_EXIT="$?" 412 | 413 | # Merge exit codes 414 | if [ "$TMP_EXIT" != "0" ]; then 415 | if [ "$SEVERITY" = "e" ]; then 416 | CNT_ERROR=$((CNT_ERROR+1)) 417 | MSG_UPDATE="[CRITICAL] ${MSG_UPDATE}" 418 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "2")" 419 | else 420 | CNT_WARNING=$((CNT_WARNING+1)) 421 | MSG_UPDATE="[WARNING] ${MSG_UPDATE}" 422 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "1")" 423 | fi 424 | HAS_UPDATE_ERROR="true" 425 | else 426 | CNT_OK=$((CNT_OK+1)) 427 | MSG_UPDATE="[OK] ${MSG_UPDATE}" 428 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "0")" 429 | fi 430 | CNT_ALL=$((CNT_ALL+1)) 431 | ;; 432 | 433 | 434 | # ---- 3 Evaluate missing modules 435 | -m) 436 | # Get next arg in list (Module name) 437 | shift 438 | MODULE="$1" 439 | 440 | if [ -z "$DELIMITER" ]; then 441 | # Get next arg in list (Exit code) 442 | shift 443 | SEVERITY="$1" 444 | else 445 | MODULE=$(echo "$1" | awk -F"$DELIMITER" '{print $1}') 446 | SEVERITY=$(echo "$1" | awk -F"$DELIMITER" '{print $2}') 447 | fi 448 | 449 | # Check valid exit code 450 | if [ "$SEVERITY" != "w" ] && [ "$SEVERITY" != "e" ]; then 451 | echo "Invalid severity value \"$SEVERITY\" for option \"-m\" and module \"$MODULE\"." 452 | exit $EXIT_UNKNOWN 453 | fi 454 | 455 | # Execute Command 456 | TMP_TEXT="$(check_module "$MODULE")" 457 | TMP_EXIT="$?" 458 | 459 | # Merge exit codes 460 | if [ "$TMP_EXIT" != "0" ]; then 461 | if [ "$SEVERITY" = "e" ]; then 462 | CNT_ERROR=$((CNT_ERROR+1)) 463 | MSG_MODULE="$(merge_text "${MSG_MODULE}" "[CRITICAL] $TMP_TEXT")" 464 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "2")" 465 | else 466 | CNT_WARNING=$((CNT_WARNING+1)) 467 | MSG_MODULE="$(merge_text "${MSG_MODULE}" "[WARNING] $TMP_TEXT")" 468 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "1")" 469 | fi 470 | HAS_MODULE_ERROR="true" 471 | else 472 | CNT_OK=$((CNT_OK+1)) 473 | MSG_MODULE="$(merge_text "${MSG_MODULE}" "[OK] $TMP_TEXT")" 474 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "0")" 475 | fi 476 | CNT_ALL=$((CNT_ALL+1)) 477 | ;; 478 | 479 | # ---- 4 Evaluate blacklisted modules 480 | -b) 481 | # Get next arg in list (Module name) 482 | shift 483 | MODULE="$1" 484 | 485 | if [ -z "$DELIMITER" ]; then 486 | # Get next arg in list (Exit code) 487 | shift 488 | SEVERITY="$1" 489 | else 490 | MODULE=$(echo "$1" | awk -F"$DELIMITER" '{print $1}') 491 | SEVERITY=$(echo "$1" | awk -F"$DELIMITER" '{print $2}') 492 | fi 493 | 494 | # Check valid exit code 495 | if [ "$SEVERITY" != "w" ] && [ "$SEVERITY" != "e" ]; then 496 | echo "Invalid severity \"$SEVERITY\" for option \"-b\" and module \"$MODULE\"." 497 | exit $EXIT_UNKNOWN 498 | fi 499 | 500 | 501 | # Execute Command 502 | TMP_TEXT="$(check_blacklisted_module "$MODULE")" 503 | TMP_EXIT="$?" 504 | 505 | # Merge exit codes 506 | if [ "$TMP_EXIT" != "0" ]; then 507 | if [ "$SEVERITY" = "e" ]; then 508 | CNT_ERROR=$((CNT_ERROR+1)) 509 | MSG_M_BLACKLIST="$(merge_text "${MSG_M_BLACKLIST}" "[CRITICAL] $TMP_TEXT")" 510 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "2")" 511 | else 512 | CNT_WARNING=$((CNT_WARNING+1)) 513 | MSG_M_BLACKLIST="$(merge_text "${MSG_M_BLACKLIST}" "[WARNING] $TMP_TEXT")" 514 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "1")" 515 | fi 516 | HAS_M_BLACKLIST_ERROR="true" 517 | else 518 | CNT_OK=$((CNT_OK+1)) 519 | MSG_M_BLACKLIST="$(merge_text "${MSG_M_BLACKLIST}" "[OK] $TMP_TEXT")" 520 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "0")" 521 | fi 522 | CNT_ALL=$((CNT_ALL+1)) 523 | ;; 524 | 525 | 526 | # ---- 5. Evaluate wrong configuration 527 | -c) 528 | # Get next arg in list (Config name) 529 | shift 530 | CONFIG="$1" 531 | 532 | if [ -z "$DELIMITER" ]; then 533 | # Get next arg in list (Config value) 534 | shift 535 | VALUE="$1" 536 | 537 | # Get next arg in list (Exit code) 538 | shift 539 | SEVERITY="$1" 540 | else 541 | CONFIG=$(echo "$1" | awk -F"$DELIMITER" '{print $1}') 542 | VALUE=$(echo "$1" | awk -F"$DELIMITER" '{print $2}') 543 | SEVERITY=$(echo "$1" | awk -F"$DELIMITER" '{print $3}') 544 | fi 545 | 546 | # Check valid exit code 547 | if [ "$SEVERITY" != "w" ] && [ "$SEVERITY" != "e" ]; then 548 | echo "Invalid severity \"$SEVERITY\" for option \"-c\" and directive \"$CONFIG\"." 549 | exit $EXIT_UNKNOWN 550 | fi 551 | 552 | # execute command 553 | TMP_TEXT="$(check_configurration "$CONFIG" "$VALUE")" 554 | TMP_EXIT="$?" 555 | 556 | # Merge exit codes 557 | if [ "$TMP_EXIT" != "0" ]; then 558 | if [ "$SEVERITY" = "e" ]; then 559 | CNT_ERROR=$((CNT_ERROR+1)) 560 | MSG_CONFIG="$(merge_text "${MSG_CONFIG}" "[CRITICAL] $TMP_TEXT")" 561 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "2")" 562 | else 563 | CNT_WARNING=$((CNT_WARNING+1)) 564 | MSG_CONFIG="$(merge_text "${MSG_CONFIG}" "[WARNING] $TMP_TEXT")" 565 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "1")" 566 | fi 567 | HAS_CONFIG_ERROR="true" 568 | else 569 | CNT_OK=$((CNT_OK+1)) 570 | MSG_CONFIG="$(merge_text "${MSG_CONFIG}" "[OK] $TMP_TEXT")" 571 | NAGIOS_EXIT="$(merge_exit_codes "$NAGIOS_EXIT" "0")" 572 | fi 573 | CNT_ALL=$((CNT_ALL+1)) 574 | ;; 575 | 576 | # ---- Be verbose 577 | -v) 578 | CMD="$PHP -v 2>/dev/null | grep -E '(^PHP)|(^Zend)' | awk -F'[,]' '{print \$1}' | awk -F'[(]' '{print \$1}' | awk -F'[-]' '{print \$1}'" 579 | MSG_VERBOSE="$(eval "$CMD")" 580 | ;; 581 | 582 | -V) 583 | print_version 584 | exit $EXIT_OK 585 | ;; 586 | 587 | # ---- PHP binary 588 | -p) 589 | # The binary option is checked earlier. So just shift 590 | # the path and move on. 591 | shift 592 | ;; 593 | 594 | # ---- With delimiter 595 | -d) 596 | # The delimiter option is checked earlier. So just shift 597 | # the delimiter and move on. 598 | shift 599 | ;; 600 | 601 | *) 602 | printf "Unknown argument: %s\n" "$1" 603 | print_usage 604 | exit $EXIT_UNKNOWN 605 | ;; 606 | esac 607 | shift 608 | done 609 | 610 | 611 | 612 | 613 | ############################################################ 614 | # Get information and Check PHP 615 | ############################################################ 616 | 617 | PHPV="$(get_php_version)" 618 | INFO="" 619 | if [ "$HAS_STARTUP_ERROR" != "" ]; then 620 | INFO="$(merge_text "${INFO}" "Startup error(s)" ", ")" 621 | fi 622 | if [ "$HAS_UPDATE_ERROR" != "" ]; then 623 | INFO="$(merge_text "${INFO}" "Updates available" ", ")" 624 | fi 625 | if [ "$HAS_MODULE_ERROR" != "" ]; then 626 | INFO="$(merge_text "${INFO}" "Missing module(s)" ", ")" 627 | fi 628 | if [ "$HAS_M_BLACKLIST_ERROR" != "" ]; then 629 | INFO="$(merge_text "${INFO}" "Blacklisted module(s)" ", ")" 630 | fi 631 | if [ "$HAS_CONFIG_ERROR" != "" ]; then 632 | INFO="$(merge_text "${INFO}" "Wrong config" ", ")" 633 | fi 634 | 635 | 636 | #### Performance Data 637 | # @see http://docs.icinga.org/latest/en/perfdata.html 638 | # 'label'=value[UOM];[warn];[crit];[min];[max] 639 | 640 | if [ "$NAGIOS_EXIT" = "$EXIT_OK" ]; then 641 | printf "%s | %s\n" "[OK] PHP ${PHPV} is healthy" "'OK'=${CNT_OK};;;0;${CNT_ALL} 'Errors'=${CNT_ERROR};1;1;0;${CNT_ALL} 'Warnings'=${CNT_WARNING};1;;0;${CNT_ALL} 'Unknown'=0;;;0;${CNT_ALL}" 642 | elif [ "$NAGIOS_EXIT" = "$EXIT_WARN" ]; then 643 | printf "%s: %s | %s\n" "[WARN] PHP ${PHPV} has warnings" "${INFO}" "'OK'=${CNT_OK};;;0;${CNT_ALL} 'Errors'=${CNT_ERROR};1;1;0;${CNT_ALL} 'Warnings'=${CNT_WARNING};1;;0;${CNT_ALL} 'Unknown'=0;;;0;${CNT_ALL}" 644 | elif [ "$NAGIOS_EXIT" = "$EXIT_ERR" ]; then 645 | printf "%s: %s | %s\n" "[ERROR] PHP ${PHPV} has errors" "${INFO}" "'OK'=${CNT_OK};;;0;${CNT_ALL} 'Errors'=${CNT_ERROR};1;1;0;${CNT_ALL} 'Warnings'=${CNT_WARNING};1;;0;${CNT_ALL} 'Unknown'=0;;;0;${CNT_ALL}" 646 | else 647 | printf "%s: %s | %s\n" "[UNKNOWN] PHP ${PHPV} is at unknown state - check extended info." "${INFO}" "OK'=0;;;0;${CNT_ALL} 'Errors'=${CNT_ERROR};1;1;0;${CNT_ALL} 'Warnings'=${CNT_WARNING};1;;0;${CNT_ALL} 'Unknown'=1;;;0;${CNT_ALL}" 648 | fi 649 | 650 | if [ "$MSG_STARTUP" != "" ]; then echo "$MSG_STARTUP"; fi 651 | if [ "$MSG_UPDATE" != "" ]; then echo "$MSG_UPDATE"; fi 652 | if [ "$MSG_MODULE" != "" ]; then echo "$MSG_MODULE"; fi 653 | if [ "$MSG_M_BLACKLIST" != "" ]; then echo "$MSG_M_BLACKLIST"; fi # Blacklisted Modules 654 | if [ "$MSG_CONFIG" != "" ]; then echo "$MSG_CONFIG"; fi 655 | if [ "$MSG_VERBOSE" != "" ]; then echo "$MSG_VERBOSE"; fi 656 | 657 | exit "$NAGIOS_EXIT" 658 | --------------------------------------------------------------------------------