Skip to content

Commit

Permalink
feature: Show composer status in web validate. (librenms#8181)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
murrant authored and laf committed Feb 27, 2018
1 parent f57e921 commit 3c3fbd3
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 165 deletions.
14 changes: 14 additions & 0 deletions LibreNMS/Interfaces/ValidationGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ public function validate(Validator $validator);
* @return bool
*/
public function isDefault();

/**
* Returns true if this group has been run
*
* @return bool
*/
public function isCompleted();

/**
* Mark this group as completed
*
* @return void
*/
public function markCompleted();
}
64 changes: 64 additions & 0 deletions LibreNMS/Validations/BaseValidation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* BaseValidation.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 Tony Murray
* @author Tony Murray <[email protected]>
*/

namespace LibreNMS\Validations;

use LibreNMS\Interfaces\ValidationGroup;

abstract class BaseValidation implements ValidationGroup
{
protected $completed = false;
protected static $RUN_BY_DEFAULT = true;

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return static::$RUN_BY_DEFAULT;
}

/**
* Returns true if this group has been run
*
* @return bool
*/
public function isCompleted()
{
return $this->completed ;
}

/**
* Mark this group as completed
*
* @return void
*/
public function markCompleted()
{
$this->completed = true;
}
}
13 changes: 1 addition & 12 deletions LibreNMS/Validations/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
namespace LibreNMS\Validations;

use LibreNMS\Config;
use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\Validator;

class Configuration implements ValidationGroup
class Configuration extends BaseValidation
{
/**
* Validate this module.
Expand All @@ -44,14 +43,4 @@ public function validate(Validator $validator)
$validator->warn('You have the old alerting system enabled - this is to be deprecated on the 1st of June 2015: https://groups.google.com/forum/#!topic/librenms-project/1llxos4m0p4');
}
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return true;
}
}
13 changes: 1 addition & 12 deletions LibreNMS/Validations/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
namespace LibreNMS\Validations;

use LibreNMS\Config;
use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\ValidationResult;
use LibreNMS\Validator;
use Symfony\Component\Yaml\Yaml;

class Database implements ValidationGroup
class Database extends BaseValidation
{
public function validate(Validator $validator)
{
Expand Down Expand Up @@ -308,14 +307,4 @@ private function indexToSql($index_data)

return sprintf($index, $columns);
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return true;
}
}
68 changes: 68 additions & 0 deletions LibreNMS/Validations/Dependencies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Dependencies.php
*
* Checks libraries
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 Tony Murray
* @author Tony Murray <[email protected]>
*/

namespace LibreNMS\Validations;

use LibreNMS\ValidationResult;
use LibreNMS\Validator;

class Dependencies extends BaseValidation
{
/**
* Validate this module.
* To return ValidationResults, call ok, warn, fail, or result methods on the $validator
*
* @param Validator $validator
*/
public function validate(Validator $validator)
{
$composer_output = trim(shell_exec($validator->getBaseDir() . '/scripts/composer_wrapper.php --version'));
$found = preg_match('/Composer version ([.0-9]+)/', $composer_output, $matches);

if (!$found) {
$validator->fail("No composer available, please install composer", "https://getcomposer.org/");
return;
} else {
$validator->ok("Composer Version: " . $matches[1]);
}

$dep_check = shell_exec($validator->getBaseDir() . '/scripts/composer_wrapper.php install --no-dev --dry-run');
preg_match_all('/Installing ([^ ]+\/[^ ]+) \(/', $dep_check, $dep_missing);
if (!empty($dep_missing[0])) {
$result = ValidationResult::fail("Missing dependencies!", "composer install --no-dev");
$result->setList("Dependencies", $dep_missing[1]);
$validator->result($result);
}
preg_match_all('/Updating ([^ ]+\/[^ ]+) \(/', $dep_check, $dep_outdated);
if (!empty($dep_outdated[0])) {
$result = ValidationResult::fail("Outdated dependencies", "composer install --no-dev");
$result->setList("Dependencies", $dep_outdated[1]);
}

if (empty($dep_missing[0]) && empty($dep_outdated[0])) {
$validator->ok("Dependencies up-to-date.");
}
}
}
13 changes: 1 addition & 12 deletions LibreNMS/Validations/Disk.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
namespace LibreNMS\Validations;

use LibreNMS\Config;
use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\Validator;

class Disk implements ValidationGroup
class Disk extends BaseValidation
{
/**
* Validate this module.
Expand All @@ -56,14 +55,4 @@ public function validate(Validator $validator)
$validator->fail("Disk space where $rrd_dir is located is empty!!!");
}
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return true;
}
}
15 changes: 3 additions & 12 deletions LibreNMS/Validations/DistributedPoller.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
namespace LibreNMS\Validations;

use LibreNMS\Config;
use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\Validator;

class DistributedPoller implements ValidationGroup
class DistributedPoller extends BaseValidation
{
protected static $RUN_BY_DEFAULT = false;

/**
* Validate this module.
* To return ValidationResults, call ok, warn, fail, or result methods on the $validator
Expand Down Expand Up @@ -74,14 +75,4 @@ public function validate(Validator $validator)
Rrd::checkRrdcached($validator);
}
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return false;
}
}
14 changes: 2 additions & 12 deletions LibreNMS/Validations/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
namespace LibreNMS\Validations;

use LibreNMS\Config;
use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\Validator;

class Mail implements ValidationGroup
class Mail extends BaseValidation
{
protected static $RUN_BY_DEFAULT = false;

/**
* Validate this module.
Expand Down Expand Up @@ -79,14 +79,4 @@ public function validate(Validator $validator)
}
}//end if
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return false;
}
}
13 changes: 1 addition & 12 deletions LibreNMS/Validations/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
namespace LibreNMS\Validations;

use LibreNMS\Config;
use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\ValidationResult;
use LibreNMS\Validator;

class Php implements ValidationGroup
class Php extends BaseValidation
{
/**
* Validate this module.
Expand Down Expand Up @@ -161,14 +160,4 @@ private function checkTimezone(Validator $validator)
}
}
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return true;
}
}
13 changes: 1 addition & 12 deletions LibreNMS/Validations/Poller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@

namespace LibreNMS\Validations;

use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\ValidationResult;
use LibreNMS\Validator;

class Poller implements ValidationGroup
class Poller extends BaseValidation
{
/**
* Validate this module.
Expand Down Expand Up @@ -145,14 +144,4 @@ private function checkLastDiscovered(Validator $validator)
);
}
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return true;
}
}
18 changes: 6 additions & 12 deletions LibreNMS/Validations/Programs.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
namespace LibreNMS\Validations;

use LibreNMS\Config;
use LibreNMS\Interfaces\ValidationGroup;
use LibreNMS\Validator;

class Programs implements ValidationGroup
class Programs extends BaseValidation
{
/**
* Validate this module.
Expand Down Expand Up @@ -99,16 +98,11 @@ public function findExecutable($bin)
return Config::get($bin);
}

return is_executable(locate_binary($bin));
}
$located = locate_binary($bin);
if (is_executable($located)) {
return $located;
}

/**
* Returns if this test should be run by default or not.
*
* @return bool
*/
public function isDefault()
{
return true;
return false;
}
}
Loading

0 comments on commit 3c3fbd3

Please sign in to comment.