feature: Show composer status in web validate. (#8181)

* Show composer status in web validate.
Don't duplicate in validate.php

* Create variable to check if a group has been completed.
No longer skips database checks.
Extract a base class.
Fix locate_binary and find_executable issues (mostly exposed by lack of db)

* Update Validator.php
This commit is contained in:
Tony Murray
2018-02-27 09:57:20 -06:00
committed by Neil Lathwood
parent f57e92102a
commit 3c3fbd3731
20 changed files with 218 additions and 165 deletions

View File

@@ -14,10 +14,13 @@
*/
use LibreNMS\Config;
use LibreNMS\ValidationResult;
use LibreNMS\Validator;
chdir(__DIR__); // cwd to the directory containing this script
ini_set('display_errors', 1);
require_once 'includes/common.php';
require_once 'includes/functions.php';
require_once 'includes/dbFacile.php';
@@ -39,6 +42,7 @@ if (isset($options['h'])) {
Default groups:
- configuration: checks various config settings are correct
- database: checks the database for errors
- dependencies: checks that all required libraries are installed and up-to-date
- disk: checks for disk space and other disk related issues
- php: check that various PHP modules and functions exist
- poller: check that the poller and discovery are running properly
@@ -92,13 +96,12 @@ if (str_contains(`tail config.php`, '?>')) {
// Composer checks
if (!file_exists('vendor/autoload.php')) {
print_fail('Composer has not been run, dependencies are missing', 'composer install --no-dev');
$pre_checks_failed = true;
exit;
}
if (!str_contains(shell_exec('php scripts/composer_wrapper.php --version'), 'Composer version')) {
print_fail("No composer available, please install composer", "https://getcomposer.org/");
$pre_checks_failed = true;
}
// init autoloading
require_once 'vendor/autoload.php';
$dep_check = shell_exec('php scripts/composer_wrapper.php install --no-dev --dry-run');
preg_match_all('/Installing ([^ ]+\/[^ ]+) \(/', $dep_check, $dep_missing);
@@ -113,6 +116,12 @@ if (!empty($dep_outdated[0])) {
print_list($dep_outdated[1], "\t %s\n");
}
$validator = new Validator();
$validator->validate(array('dependencies'));
if ($validator->getGroupStatus('dependencies') == ValidationResult::FAILURE) {
$pre_checks_failed = true;
}
if ($pre_checks_failed) {
exit;
}
@@ -122,13 +131,11 @@ require 'includes/init.php';
// make sure install_dir is set correctly, or the next includes will fail
if (!file_exists(Config::get('install_dir').'/config.php')) {
$suggested = realpath(__DIR__ . '/../..');
$suggested = realpath(__DIR__);
print_fail('$config[\'install_dir\'] is not set correctly.', "It should probably be set to: $suggested");
exit;
}
$validator = new Validator();
// Connect to MySQL
try {
@@ -160,7 +167,7 @@ $validator->validate($modules, isset($options['s'])||!empty($modules));
function print_header($versions)
{
$output = ob_get_clean();
ob_end_clean();
@ob_end_clean();
echo <<< EOF
====================================