mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* refactor: convert validations to modules to prep for gui integration * accidentally dropped, schema update * fix accidental output to webui * mention discovery-wrapper.py and re-arrange. * refine some fix statements * rename the Config validation group to Configuration. * fix some scrutinizer issues remove as many local functions from validator.php as possible move extensions from pre-check remove duplicate timezone check looks like there is some db schema differences between mariadb 10.1 and 10.2, investigating * mariadb version diff take2 * Check schema version first for database. Remove stop to go back to command line for install docs. Add helpful link when there is no devices added to /addhost * fix incorrect validation for empty string defaults * Fix style * Add additional file permissions checks * catch exception and fail for invalid timezone Change visuals a bit. * add php version warning * fix space
93 lines
3.1 KiB
PHP
93 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* RrdCheck.php
|
|
*
|
|
* Scan RRD files for errors.
|
|
*
|
|
* 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 2017 Tony Murray
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
*/
|
|
|
|
namespace LibreNMS\Validations;
|
|
|
|
use LibreNMS\Config;
|
|
use LibreNMS\Interfaces\ValidationGroup;
|
|
use LibreNMS\RRDRecursiveFilterIterator;
|
|
use LibreNMS\Validator;
|
|
use RecursiveDirectoryIterator;
|
|
use RecursiveIteratorIterator;
|
|
|
|
class RrdCheck implements ValidationGroup
|
|
{
|
|
/**
|
|
* Validate this module.
|
|
* To return ValidationResults, call ok, warn, fail, or result methods on the $validator
|
|
*
|
|
* @param Validator $validator
|
|
*/
|
|
public function validate(Validator $validator)
|
|
{
|
|
// Loop through the rrd_dir
|
|
$rrd_directory = new RecursiveDirectoryIterator(Config::get('rrd_dir'));
|
|
// Filter out any non rrd files
|
|
$rrd_directory_filter = new RRDRecursiveFilterIterator($rrd_directory);
|
|
$rrd_iterator = new RecursiveIteratorIterator($rrd_directory_filter);
|
|
$rrd_total = iterator_count($rrd_iterator);
|
|
$rrd_iterator->rewind(); // Rewind iterator in case iterator_count left iterator in unknown state
|
|
|
|
echo "\nScanning " . $rrd_total . " rrd files in " . Config::get('rrd_dir') . "...\n";
|
|
|
|
// Count loops so we can push status to the user
|
|
$loopcount = 0;
|
|
$screenpad = 0;
|
|
|
|
foreach ($rrd_iterator as $filename => $file) {
|
|
$rrd_test_result = rrdtest($filename, $output, $error);
|
|
|
|
$loopcount++;
|
|
if (($loopcount % 50) == 0) {
|
|
//This lets us update the previous status update without spamming in most consoles
|
|
echo "\033[" . $screenpad . "D";
|
|
$test_status = 'Status: ' . $loopcount . '/' . $rrd_total;
|
|
echo $test_status;
|
|
$screenpad = strlen($test_status);
|
|
}
|
|
|
|
// A non zero result means there was some kind of error
|
|
if ($rrd_test_result > 0) {
|
|
echo "\033[" . $screenpad . "D";
|
|
$validator->fail('Error parsing "' . $filename . '" RRD ' . trim($error));
|
|
$screenpad = 0;
|
|
}
|
|
}
|
|
|
|
echo "\033[" . $screenpad . "D";
|
|
echo "Status: " . $loopcount . "/" . $rrd_total . " - Complete\n";
|
|
}
|
|
|
|
/**
|
|
* Returns if this test should be run by default or not.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isDefault()
|
|
{
|
|
return false;
|
|
}
|
|
}
|