check_php

[sh] Nagios plugin for PHP to check for startup errors, missing modules, wrong php.ini configurations and PHP updates.

check_php

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).

Build Status Latest Stable Version Total Downloads Latest Unstable Version License POSIX Type

Nagios Configuration | Usage | Examples | License | Awesome


Awesome-Nagios-Plugins Find more plugins at Awesome Nagios
Icinga Exchange Find more plugins at Icinga Exchange
Nagios Exchange Find more plugins at Nagios Exchange

Requirements
Program Required Description
bourne shell (sh) yes The whole script is written in pure bourne shell (sh) and is 100% Posix compliant
check_by_ssh yes This nagios plugin is used as a wrapper to check on remote hosts
wget, curl or fetch Optional Either one of them is required if you want to check against PHP updates. (-u)
Features
  • Check for PHP startup errors
  • Check for PHP updates (inside minor versions and patch levels)
  • Check for missing PHP modules
  • Check for blacklisted PHP modules and throw err/warn if they are compiled in
  • Check for expected php.ini config directives (e.g.: date.timezone must be "Europe/Berlin", etc)
  • Each check can specify its own severity (warning or error)
Motivation

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.

1. Nagios Configuration

Command definition

In order to check php on remote servers you will need to make use of check_by_ssh.

name:    check_by_ssh_php
command: $USER1$/check_by_ssh -H $HOSTADDRESS$ -t 60 -l "$USER17$" -C "$USER22$/check_php $ARG1$"

Service definition

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:

check command: check_by_ssh_php
$ARG1$:        -s e -u w -m curl e -m gettext e -m openssl e -m json e

2. Usage

Each argument allows you to specify which severity should be triggered (`), wherewtriggers a warning andetriggers an error. Arguments that can be used multiple times (-mand-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.

Usage: check_php [-s ] [-u ] [-m ] [-b  [-c ] [-v]
       check_php -h
       check_php -V

Nagios plugin that will check if PHP exists, for PHP startup errors,
missing modules, misconfigured directives and available updates.

  -s                [single] Check for PHP startup errors and display
                         nagios warning or error if any exists.
                         Warning:  -s w
                         Error:    -s e

  -u                [single] Check for updated PHP version online. (requires wget, curl or fetch)
                         Will only check for patch updates and will not notify if your current version
                         PHP 5.5 and there is already PHP 5.6 out there.

  -m       [multiple] Require compiled PHP module and display
                         nagios warning/error if the module was not compiled against PHP.
                         Use multiple times to check against multiple modules.
                         Example: -m "mysql" w -m "mysqli" e

  -b       [multiple] Check PHP for modules that should not be compiled in and display
                         nagios warning/error if the module is compiled against PHP.
                         Use multiple times to check for multiple blacklisted modules.
                         Example: -b "imagick" w -b "tidy" e

  -c   [multiple] Check for misconfigured directives in php.ini and display
                         nagios warning/error if the configuration does not match.
                         Use multiple times to check against multiple configurations.
                         Example: -c "date.timezone" w -c "Europe/Berlin" e

  -v                     Be verbose (Show PHP Version and Zend Engine Version)

  -h                     Display help

  -V                     Display version

3. Examples

Checking against prefered timezone and compiled module mysql

$ check_php -c "date.timezone" "Europe/Berlin" e -m mysql e
[ERR] PHP 5.6.16 has errors: Missing module(s) | OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;;
[CRITICAL] Module: "mysql" not available
[OK]       Config "date.timezone" = "Europe/Berlin"

Checking for PHP startup errors

$ check_php -s w
[WARN] PHP 5.6.16 has warning: Startup errors | OK'=0;;;; 'Errors'=0;;;; 'Warnings'=1;;;; 'Unknown'=0;;;;
[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

Combine multiple module checks

$ check_php -m mysql e -m mysqli w -m mbstring w
[OK] PHP 5.6.16 is healthy | 'OK'=1;;;; 'Errors'=0;;;; 'Warnings'=0;;;; 'Unknown'=0;;;;
[OK]       Module: "mysql" available
[OK]       Module: "mysqli" available
[OK]       Module: "mbstring" available

Checking for PHP Updates (OK)

$ check_php -u e
[OK] PHP 5.6.16 is healthy | 'OK'=1;;;; 'Errors'=0;;;; 'Warnings'=0;;;; 'Unknown'=0;;;;
[OK]       No PHP startup errors
[OK]       PHP Version 5.6.14 up to date.

Checking for PHP Updates (Updates available)

$ check_php -u e
[ERR] PHP 5.6.13 has errors: Updates available | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=-;;;; 'Unknown'=0;;;;
[OK]       No PHP startup errors
[CRITICAL] PHP Version 5.6.13 too old. Latest: 5.6.14.

Checking for PHP Updates (Able to differentiate between PHP 5.4, 5.5 and 5.6)

$ check_php -u e
[ERR] PHP 5.5.1 has errors: Updates available | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;;
[OK]       No PHP startup errors
[CRITICAL] PHP Version 5.5.1 too old. Latest: 5.5.30.

A lot of options combined

$ 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
[ERR] PHP 5.6.14 has errors: Wrong config | 'OK'=0;;;; 'Errors'=1;;;; 'Warnings'=0;;;; 'Unknown'=0;;;;
[OK]       No PHP startup errors
[OK]       PHP Version 5.6.14 up to date.
[OK]       Module: "mysql" available
[OK]       Module: "mbstring" available
[OK]       Module: "xml" available
[OK]       Config "date.timezone" = "Europe/Berlin"
[CRITICAL] Config "session.cookie_secure" = "Off", excpected: "On"
PHP 5.6.14
Zend Engine v2.6.0

4. License

license

5. Awesome

Added by the following Awesome lists: