├── .gitignore ├── .travis.yml ├── Check ├── Check.php ├── CheckChain.php ├── CheckInterface.php ├── DiscUsageCheck.php ├── DoctrineDbalCheck.php ├── HttpServiceCheck.php ├── MemcacheCheck.php ├── PhpExtensionsCheck.php ├── ProcessActiveCheck.php ├── RabbitMQCheck.php ├── RedisCheck.php ├── Runner.php ├── SecurityAdvisoryCheck.php └── WritableDirectoryCheck.php ├── Exception └── CheckFailedException.php ├── LICENSE ├── README.md ├── Result └── CheckResult.php ├── Tests ├── Check │ ├── CheckChainTest.php │ └── PhpExtensionsCheckTest.php └── bootstrap.php ├── composer.json └── phpunit.xml.dist /.gitignore: -------------------------------------------------------------------------------- 1 | /phpunit.xml 2 | composer.lock 3 | composer.phar 4 | vendor/ 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.3 4 | - 5.4 5 | - 5.5 6 | 7 | before_script: 8 | - composer update 9 | -------------------------------------------------------------------------------- /Check/Check.php: -------------------------------------------------------------------------------- 1 | getName(), $message, $status); 33 | } 34 | } -------------------------------------------------------------------------------- /Check/CheckChain.php: -------------------------------------------------------------------------------- 1 | $check) { 17 | $this->addCheck($serviceId, $check); 18 | } 19 | } 20 | 21 | /** 22 | * @param string $serviceId 23 | * @param CheckInterface $check 24 | */ 25 | public function addCheck($serviceId, CheckInterface $check) 26 | { 27 | $this->checks[$serviceId] = $check; 28 | } 29 | 30 | /** 31 | * @return array 32 | */ 33 | public function getChecks() 34 | { 35 | return $this->checks; 36 | } 37 | 38 | /** 39 | * @return array 40 | */ 41 | public function getAvailableChecks() 42 | { 43 | return array_keys($this->checks); 44 | } 45 | 46 | /** 47 | * @throws \InvalidArgumentException 48 | * @param string $id 49 | * @return \Liip\Monitor\Check\CheckInterface 50 | */ 51 | public function getCheckById($id) 52 | { 53 | if (!isset($this->checks[$id])) { 54 | throw new \InvalidArgumentException(sprintf("Check with id: %s doesn't exist", $id)); 55 | } 56 | 57 | return $this->checks[$id]; 58 | } 59 | 60 | /** 61 | * @param string $name 62 | * @return array 63 | */ 64 | public function getChecksByGroup($name) 65 | { 66 | $checks = array(); 67 | 68 | foreach ($this->checks as $id => $check) { 69 | if ($check->getGroup() === $name) { 70 | $checks[] = $id; 71 | } 72 | } 73 | 74 | return $checks; 75 | } 76 | 77 | /** 78 | * @return array 79 | */ 80 | public function getGroups() 81 | { 82 | $groups = array(); 83 | 84 | foreach ($this->checks as $check) { 85 | 86 | if (!in_array($check->getGroup(), $groups)) { 87 | $groups[] = $check->getGroup(); 88 | } 89 | } 90 | 91 | return $groups; 92 | } 93 | } -------------------------------------------------------------------------------- /Check/CheckInterface.php: -------------------------------------------------------------------------------- 1 | maxDiscUsage = (int)$maxDiscUsage; 21 | $this->path = $path; 22 | } 23 | 24 | public function check() 25 | { 26 | $df = disk_free_space($this->path); 27 | $dt = disk_total_space($this->path); 28 | $du = $dt - $df; 29 | $dp = ($du / $dt) * 100; 30 | 31 | if ($dp >= $this->maxDiscUsage) { 32 | return $this->buildResult(sprintf('KO - Disc usage too high: %2d percentage.', $dp), CheckResult::CRITICAL); 33 | } 34 | return $this->buildResult('OK', CheckResult::OK); 35 | } 36 | 37 | public function getName() 38 | { 39 | return "Disc Usage Health"; 40 | } 41 | } -------------------------------------------------------------------------------- /Check/DoctrineDbalCheck.php: -------------------------------------------------------------------------------- 1 | manager = $manager; 24 | $this->connectionName = $connectionName; 25 | } 26 | 27 | public function check() 28 | { 29 | try { 30 | $connection = $this->manager->getConnection($this->connectionName); 31 | $connection->fetchColumn('SELECT 1'); 32 | $result = $this->buildResult('OK', CheckResult::OK); 33 | } catch (\Exception $e) { 34 | $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL); 35 | } 36 | 37 | return $result; 38 | } 39 | 40 | public function getName() 41 | { 42 | return "Doctrine DBAL Connnection"; 43 | } 44 | } -------------------------------------------------------------------------------- /Check/HttpServiceCheck.php: -------------------------------------------------------------------------------- 1 | host = $host; 43 | $this->port = $port; 44 | $this->path = $path; 45 | $this->statusCode = $statusCode; 46 | $this->content = $content; 47 | } 48 | 49 | /** 50 | * @see Liip\MonitorBundle\Check\CheckInterface::check() 51 | */ 52 | public function check() 53 | { 54 | $fp = @fsockopen($this->host, $this->port, $errno, $errstr, 10); 55 | if (!$fp) { 56 | $result = $this->buildResult(sprintf('No http service running at host %s on port %s', $this->host, $this->port), CheckResult::CRITICAL); 57 | } else { 58 | $header = "GET {$this->path} HTTP/1.1\r\n"; 59 | $header .= "Host: {$this->host}\r\n"; 60 | $header .= "Connection: close\r\n\r\n"; 61 | fputs($fp, $header); 62 | $str = ''; 63 | while (!feof($fp)) { 64 | $str .= fgets($fp, 1024); 65 | } 66 | fclose($fp); 67 | 68 | if ($this->statusCode && strpos($str, "HTTP/1.1 {$this->statusCode}") !== 0) { 69 | $result = $this->buildResult("Status code {$this->statusCode} does not match in response from {$this->host}:{$this->port}{$this->path}", CheckResult::CRITICAL); 70 | } elseif ($this->content && !strpos($str, $this->content)) { 71 | $result = $this->buildResult("Content {$this->content} not found in response from {$this->host}:{$this->port}{$this->path}", CheckResult::CRITICAL); 72 | } else { 73 | $result = $this->buildResult('OK', CheckResult::OK); 74 | } 75 | } 76 | 77 | return $result; 78 | } 79 | 80 | /** 81 | * @see Liip\MonitorBundle\Check\Check::getName() 82 | */ 83 | public function getName() 84 | { 85 | return 'Http Service ('.$this->host.')'; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Check/MemcacheCheck.php: -------------------------------------------------------------------------------- 1 | host = $host; 28 | $this->port = $port; 29 | } 30 | 31 | /** 32 | * @see Liip\MonitorBundle\Check\CheckInterface::check() 33 | */ 34 | public function check() 35 | { 36 | try { 37 | if (class_exists(('\Memcache'))) { 38 | $memcache = new \Memcache(); 39 | $memcache->addServer($this->host, $this->port); 40 | $stats = @$memcache->getExtendedStats(); 41 | } elseif (class_exists('\Memcached')) { 42 | $memcached = new \Memcached(); 43 | $memcached->addServer($this->host, $this->port); 44 | $stats = @$memcached->getStats(); 45 | } else { 46 | throw new CheckFailedException( 47 | 'No PHP extension (\Memcache or \Memcached) installed' 48 | ); 49 | } 50 | 51 | $available = $stats[$this->host . ':' . $this->port] !== false; 52 | if (!$available && !@$memcache->connect($this->host, $this->port)) { 53 | throw new CheckFailedException(sprintf( 54 | 'No memcache server running at host %s on port %s', 55 | $this->host, 56 | $this->port 57 | )); 58 | } 59 | $result = $this->buildResult('OK', CheckResult::OK); 60 | } catch (\Exception $e) { 61 | $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL); 62 | } 63 | 64 | return $result; 65 | } 66 | 67 | /** 68 | * @see Liip\MonitorBundle\Check\Check::getName() 69 | */ 70 | public function getName() 71 | { 72 | return 'Memcache'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Check/PhpExtensionsCheck.php: -------------------------------------------------------------------------------- 1 | extensions = $extensions; 19 | } 20 | 21 | /** 22 | * @see Liip\MonitorBundle\Check\CheckInterface::check() 23 | */ 24 | public function check() 25 | { 26 | try { 27 | $notLoaded = array(); 28 | foreach ($this->extensions as $extension) { 29 | if (!extension_loaded($extension)) { 30 | $notLoaded[] = $extension; 31 | } 32 | } 33 | 34 | if (count($notLoaded) > 0) { 35 | throw new CheckFailedException(sprintf('The following extensions are not loaded: "%s"', implode('", "', $notLoaded))); 36 | } 37 | 38 | return $this->buildResult('OK', CheckResult::OK); 39 | } catch (\Exception $e) { 40 | return $this->buildResult(sprintf('KO - %s', $e->getMessage()), CheckResult::CRITICAL); 41 | } 42 | } 43 | 44 | /** 45 | * @see Liip\MonitorBundle\Check\CheckInterface::getName() 46 | */ 47 | public function getName() 48 | { 49 | return "PHP Extensions Health Check"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Check/ProcessActiveCheck.php: -------------------------------------------------------------------------------- 1 | command = $command; 19 | } 20 | 21 | /** 22 | * @see Liip\MonitorBundle\Check\CheckInterface::check() 23 | */ 24 | public function check() 25 | { 26 | try { 27 | exec('ps -ef | grep ' . escapeshellarg($this->command) . ' | grep -v grep', $output, $return); 28 | if ($return == 1) { 29 | throw new CheckFailedException(sprintf('There is no process running containing "%s"', $this->command)); 30 | } 31 | $result = $this->buildResult('OK', CheckResult::OK); 32 | } catch (\Exception $e) { 33 | $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL); 34 | } 35 | 36 | return $result; 37 | } 38 | 39 | /** 40 | * @see Liip\MonitorBundle\Check\Check::getName() 41 | */ 42 | public function getName() 43 | { 44 | return 'Process Active: ' . $this->command; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Check/RabbitMQCheck.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | class RabbitMQCheck extends Check 18 | { 19 | /** 20 | * @var string 21 | */ 22 | protected $host; 23 | 24 | /** 25 | * @var integer 26 | */ 27 | protected $port; 28 | 29 | /** 30 | * Construct. 31 | * 32 | * @param string $host 33 | * @param integer $port 34 | * @param string $user 35 | * @param string $password 36 | * @param string $vhost 37 | */ 38 | public function __construct( 39 | $host = 'localhost', 40 | $port = 5672, 41 | $user = 'guest', 42 | $password = 'guest', 43 | $vhost = '/' 44 | ) 45 | { 46 | $this->host = $host; 47 | $this->port = $port; 48 | $this->user = $user; 49 | $this->password = $password; 50 | $this->vhost = $vhost; 51 | } 52 | 53 | /** 54 | * {@inheritdoc} 55 | * @see \Liip\MonitorBundle\Check\CheckInterface::check() 56 | */ 57 | public function check() 58 | { 59 | try { 60 | $conn = new AMQPConnection( 61 | $this->host, 62 | $this->port, 63 | $this->user, 64 | $this->password, 65 | $this->vhost 66 | ); 67 | $ch = $conn->channel(); 68 | $result = $this->buildResult('OK', CheckResult::OK); 69 | } catch (\Exception $e) { 70 | $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL); 71 | } 72 | 73 | return $result; 74 | } 75 | 76 | /** 77 | * {@inheritdoc} 78 | * @see \Liip\MonitorBundle\Check\Check::getName() 79 | */ 80 | public function getName() 81 | { 82 | return 'RabbitMQ'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Check/RedisCheck.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | class RedisCheck extends Check 18 | { 19 | /** 20 | * @var string 21 | */ 22 | protected $host; 23 | 24 | /** 25 | * @var integer 26 | */ 27 | protected $port; 28 | 29 | /** 30 | * Construct. 31 | * 32 | * @param string $host 33 | * @param integer $port 34 | */ 35 | public function __construct($host = 'localhost', $port = 6379) 36 | { 37 | $this->host = $host; 38 | $this->port = $port; 39 | } 40 | 41 | /** 42 | * {@inheritdoc} 43 | * @see \Liip\MonitorBundle\Check\CheckInterface::check() 44 | */ 45 | public function check() 46 | { 47 | try { 48 | $client = new Client(array( 49 | 'host' => $this->host, 50 | 'port' => $this->port, 51 | )); 52 | if (!$client->ping()) { 53 | throw new CheckFailedException( 54 | sprintf( 55 | 'No Redis server running at host %s on port %s', 56 | $this->host, 57 | $this->port 58 | ) 59 | ); 60 | } 61 | $result = $this->buildResult('OK', CheckResult::OK); 62 | } catch (\Exception $e) { 63 | $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL); 64 | } 65 | 66 | return $result; 67 | } 68 | 69 | /** 70 | * {@inheritdoc} 71 | * @see \Liip\MonitorBundle\Check\Check::getName() 72 | */ 73 | public function getName() 74 | { 75 | return 'Redis'; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Check/Runner.php: -------------------------------------------------------------------------------- 1 | chain = $chain; 17 | } 18 | 19 | /** 20 | * @param string $checkId 21 | * @return \Liip\Monitor\Result\CheckResult 22 | */ 23 | public function runCheckById($checkId) 24 | { 25 | return $this->runCheck($this->chain->getCheckById($checkId)); 26 | } 27 | 28 | /** 29 | * @param \Liip\Monitor\Check\CheckInterface $checkService 30 | * @return \Liip\Monitor\Result\CheckResult 31 | */ 32 | public function runCheck(CheckInterface $checkService) 33 | { 34 | return $checkService->check(); 35 | } 36 | 37 | /** 38 | * @return array 39 | */ 40 | public function runAllChecks() 41 | { 42 | $results = array(); 43 | foreach ($this->chain->getChecks() as $id => $checkService) { 44 | $results[$id] = $this->runCheck($checkService); 45 | } 46 | 47 | return $results; 48 | } 49 | 50 | /** 51 | * @return array 52 | */ 53 | public function runAllChecksByGroup() 54 | { 55 | $results = array(); 56 | $groups = $this->chain->getGroups(); 57 | 58 | foreach ($groups as $group) { 59 | $results[$group] = CheckResult::OK; 60 | } 61 | 62 | foreach ($this->chain->getChecks() as $id => $checkService) { 63 | $check = $this->runCheck($checkService); 64 | if ($check->getStatus() > $results[$checkService->getGroup()]) { 65 | $results[$checkService->getGroup()] = $check; 66 | } 67 | } 68 | 69 | return $results; 70 | } 71 | } -------------------------------------------------------------------------------- /Check/SecurityAdvisoryCheck.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | class SecurityAdvisoryCheck extends Check 16 | { 17 | /** 18 | * @var string 19 | */ 20 | protected $lockFilePath; 21 | 22 | /** 23 | * @var SecurityChecker 24 | */ 25 | protected $securityChecker; 26 | 27 | /** 28 | * @param SecurityChecker $securityChecker 29 | * @param string $lockFilePath 30 | */ 31 | public function __construct(SecurityChecker $securityChecker, $lockFilePath) 32 | { 33 | $this->securityChecker = $securityChecker; 34 | $this->lockFilePath = $lockFilePath; 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | public function check() 41 | { 42 | try { 43 | $advisories = $this->checkSymfonyAdvisories(); 44 | if (empty($advisories)) { 45 | $result = $this->buildResult('OK', CheckResult::OK); 46 | } else { 47 | $result = $this->buildResult('Advisories for ' . count($advisories) . ' packages', CheckResult::WARNING); 48 | } 49 | } catch (\Exception $e) { 50 | $result = $this->buildResult($e->getMessage(), CheckResult::UNKNOWN); 51 | } 52 | 53 | return $result; 54 | } 55 | 56 | private function checkSymfonyAdvisories() 57 | { 58 | if (!file_exists($this->lockFilePath)) { 59 | throw new CheckFailedException("No composer lock file found"); 60 | } 61 | 62 | $alerts = $this->securityChecker->check($this->lockFilePath, 'json'); 63 | 64 | return json_decode($alerts); 65 | } 66 | 67 | /** 68 | * {@inheritdoc} 69 | */ 70 | public function getName() 71 | { 72 | return 'Security advisory'; 73 | } 74 | } -------------------------------------------------------------------------------- /Check/WritableDirectoryCheck.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class WritableDirectoryCheck extends Check 15 | { 16 | /** 17 | * @var array 18 | */ 19 | protected $directories; 20 | 21 | /** 22 | * Construct. 23 | * 24 | * @param array $directories 25 | */ 26 | public function __construct($directories) 27 | { 28 | $this->directories = $directories; 29 | } 30 | 31 | /** 32 | * @see Liip\MonitorBundle\Check\CheckInterface::check() 33 | */ 34 | public function check() 35 | { 36 | try { 37 | $notWritable = array(); 38 | 39 | foreach ($this->directories as $dir) { 40 | if (!is_writable($dir)) { 41 | $notWritable[] = $dir; 42 | } 43 | } 44 | 45 | if (count($notWritable) > 0) { 46 | throw new CheckFailedException(sprintf('The following directories are not writable: "%s"', implode('", "', $notWritable))); 47 | } 48 | 49 | $result = $this->buildResult('OK', CheckResult::OK); 50 | 51 | } catch (\Exception $e) { 52 | $result = $this->buildResult($e->getMessage(), CheckResult::CRITICAL); 53 | } 54 | 55 | return $result; 56 | } 57 | 58 | /** 59 | * @see Liip\MonitorBundle\Check\CheckInterface::getName() 60 | */ 61 | public function getName() 62 | { 63 | return 'Writable directory'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Exception/CheckFailedException.php: -------------------------------------------------------------------------------- 1 | extensions = $extensions; 104 | } 105 | 106 | public function check() 107 | { 108 | try { 109 | foreach ($this->extensions as $extension) { 110 | if (!extension_loaded($extension)) { 111 | throw new CheckFailedException(sprintf('Extension %s not loaded', $extension)); 112 | } 113 | } 114 | return $this->buildResult('OK', CheckResult::OK); 115 | } catch (\Exception $e) { 116 | return $this->buildResult(sprintf('KO - %s', $e->getMessage()), CheckResult::CRITICAL); 117 | } 118 | } 119 | 120 | public function getName() 121 | { 122 | return "PHP Extensions Health Check"; 123 | } 124 | } 125 | 126 | Once you implemented the class then it's time to register the check service with your runner: 127 | 128 | $checkChain = new \Liip\Monitor\Check\CheckChain(); 129 | $runner = new \Liip\Monitor\Check\Runner($checkChain); 130 | 131 | $phpExtensionCheck = new \Acme\Hello\Check\PhpExtensionsCheck(array('apc', 'memcached')); 132 | $checkChain->addCheck('php_extension_check', $phpExtensionCheck); 133 | 134 | Finally to run health checks use: 135 | 136 | $runner->runAllChecks() // runs all checks 137 | $runner->runCheckById('php_extension_check'); // runs an individual check by id 138 | 139 | To get a list of available checks use: 140 | 141 | $chain->getAvailableChecks(); 142 | 143 | ### CheckResult values ### 144 | 145 | These values has been taken from the [nagios documentation](http://nagiosplug.sourceforge.net/developer-guidelines.html#RETURNCODES) : 146 | 147 | * ``CheckResult::OK`` - The plugin was able to check the service and it appeared to be functioning properly 148 | * ``CheckResult::WARNING`` - The plugin was able to check the service, but it appeared to be above some "warning" 149 | threshold or did not appear to be working properly 150 | * ``CheckResult::CRITICAL`` - The plugin detected that either the service was not running or it was above some "critical" threshold 151 | * ``CheckResult::UNKNOWN`` - Invalid command line arguments were supplied to the plugin or low-level failures 152 | internal to the plugin (such as unable to fork, or open a tcp socket) that prevent it 153 | from performing the specified operation. Higher-level errors (such as name resolution 154 | errors, socket timeouts, etc) are outside of the control of plugins and should generally 155 | NOT be reported as UNKNOWN states. 156 | 157 | As you can see our constructor will take an array with the names of the extensions our 158 | application requires. Then on the `check` method it will iterate over that array to 159 | test for each of the extensions. If there are no problems then the check will return a 160 | `CheckResult` object with a message (`OK` in our case) and the result status 161 | (`CheckResult::SUCCESS` in our case). As you can see this is as easy as it gets. 162 | 163 | # Contributions # 164 | 165 | Fork this project, add a health check and then open a pull request. 166 | 167 | # Note to contributors # 168 | 169 | BY CONTRIBUTING TO THE LiipMonitor SOURCE CODE REPOSITORY YOU AGREE TO LICENSE YOUR CONTRIBUTION 170 | UNDER THE TERMS OF THE MIT LICENSE AS SPECIFIED IN THE 'LICENSE' FILE IN THIS DIRECTORY. 171 | -------------------------------------------------------------------------------- /Result/CheckResult.php: -------------------------------------------------------------------------------- 1 | checkName = $checkName; 24 | $this->message = $message; 25 | $this->status = $status; 26 | } 27 | 28 | /** 29 | * @return string 30 | */ 31 | public function getCheckName() 32 | { 33 | return $this->checkName; 34 | } 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getMessage() 40 | { 41 | return $this->message; 42 | } 43 | 44 | /** 45 | * @return integer 46 | */ 47 | public function getStatus() 48 | { 49 | return $this->status; 50 | } 51 | 52 | /** 53 | * @return array 54 | */ 55 | public function toArray() 56 | { 57 | return array( 58 | 'checkName' => $this->checkName, 59 | 'message' => $this->message, 60 | 'status' => $this->status, 61 | 'status_name' => $this->getStatusName() 62 | ); 63 | } 64 | 65 | /** 66 | * @return string 67 | */ 68 | public function getStatusName() 69 | { 70 | $list = self::getStatusList(); 71 | 72 | if (!isset($list[$this->getStatus()])) { 73 | return 'n/a'; 74 | } 75 | 76 | return $list[$this->getStatus()]; 77 | } 78 | 79 | /** 80 | * @static 81 | * @return array 82 | */ 83 | public static function getStatusList() 84 | { 85 | return array( 86 | self::OK => 'check_result_ok', 87 | self::WARNING => 'check_result_warning', 88 | self::CRITICAL => 'check_result_critical', 89 | self::UNKNOWN => 'check_result_unknown', 90 | ); 91 | } 92 | } -------------------------------------------------------------------------------- /Tests/Check/CheckChainTest.php: -------------------------------------------------------------------------------- 1 | getMock('Liip\Monitor\Check\CheckInterface'); 13 | 14 | $checkChain = new CheckChain(); 15 | $checkChain->addCheck('foo', $check); 16 | 17 | $this->assertEquals(1, count($checkChain->getChecks())); 18 | $this->assertInstanceOf('Liip\Monitor\Check\CheckInterface', $checkChain->getCheckById('foo')); 19 | } 20 | 21 | /** 22 | * @expectedException \InvalidArgumentException 23 | */ 24 | public function testExceptionInGetCheckById() 25 | { 26 | $checkChain = new CheckChain(); 27 | $checkChain->getCheckById('fake'); 28 | } 29 | 30 | public function testCheckGroups() 31 | { 32 | $checkOne = $check = $this->getMock('Liip\Monitor\Check\CheckInterface'); 33 | 34 | $checkOne 35 | ->expects($this->exactly(2)) 36 | ->method('getGroup') 37 | ->will($this->returnValue('foo')) 38 | ; 39 | 40 | $checkTwo = $check = $this->getMock('Liip\Monitor\Check\CheckInterface'); 41 | 42 | $checkTwo 43 | ->expects($this->exactly(2)) 44 | ->method('getGroup') 45 | ->will($this->returnValue('bar')) 46 | ; 47 | 48 | $checkChain = new CheckChain(); 49 | $checkChain->addCheck('foo_id', $checkOne); 50 | $checkChain->addCheck('bar_id', $checkTwo); 51 | 52 | $this->assertEquals(array('foo', 'bar'), $checkChain->getGroups()); 53 | } 54 | } -------------------------------------------------------------------------------- /Tests/Check/PhpExtensionsCheckTest.php: -------------------------------------------------------------------------------- 1 | check(); 14 | 15 | $this->assertInstanceOf('Liip\Monitor\Result\CheckResult', $result); 16 | $this->assertEquals(CheckResult::OK, $result->getStatus()); 17 | } 18 | 19 | public function testCheckUnknownExtensions() 20 | { 21 | $check = new PhpExtensionsCheck(array('SPL', 'unknown1', 'unknown2')); 22 | $result = $check->check(); 23 | 24 | $this->assertInstanceOf('Liip\Monitor\Result\CheckResult', $result); 25 | $this->assertEquals(CheckResult::CRITICAL, $result->getStatus()); 26 | $this->assertNotContains('SPL', $result->getMessage()); 27 | $this->assertContains('unknown1', $result->getMessage()); 28 | $this->assertContains('unknown2', $result->getMessage()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | =5.3.3" 23 | }, 24 | "require-dev": { 25 | "sensiolabs/security-checker": "dev-master" 26 | }, 27 | "suggest": { 28 | "sensiolabs/security-checker": "Required for Security Advisory Checker", 29 | "predis/predis": "Required for Redis Checker", 30 | "videlalvaro/php-amqplib": "Required for RabbitMQ Checker" 31 | }, 32 | "autoload": { 33 | "psr-0": { "Liip\\Monitor": "" } 34 | }, 35 | "target-dir": "Liip/Monitor", 36 | "extra": { 37 | "branch-alias": { 38 | "dev-master": "1.0-dev" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ./Tests 7 | 8 | 9 | 10 | 11 | 12 | ./ 13 | 14 | ./Tests/ 15 | ./DataFixtures/ 16 | ./Resources/ 17 | 18 | 19 | 20 | 21 | --------------------------------------------------------------------------------