mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Datastores to object oriented code, using the Laravel IoC container Change instantiation better DI move OpenTSDB Small re-orgs remove unused stuff Fix graphs and other scripts Use DI for all except rrd fix up connection error handling Add tests, fix up a "few" things Add Config::forget() Style fixes Don't reference legacy code remove accidental code paste Add datastores phpunit groups some tests * rebase fixes * some test fixes * shorter tests * shorter tests * Don't except when rrdtool can't be started. * restore tests * fix rrd tests * fix iterable change upstream * fix isValidDataset * fix invalid data bug * fix mysql incorrect ds * fix issue with data that is too long * use regular data_update() * Use log facade * OpenTSDB mis-ordered arguments fix * Making a singleton with different options makes different singletons. Just use the global config settings to disable datastores. * only filter tags for datastores that won't it don't modify the tags permanently * Update copyrights to include original authors. * Stats for all datastores * Fix mysql sends different rrd / other ds names * fix snmp last stats not initialized remove unused function * remove unused function and move single use function closer to its use * InfluxDB does not need to update null or U values. Skip write if all fields are empty * Fix smart value checks * fix style issues
124 lines
4.1 KiB
PHP
124 lines
4.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\RRDRecursiveFilterIterator;
|
|
use LibreNMS\Validator;
|
|
use RecursiveDirectoryIterator;
|
|
use RecursiveIteratorIterator;
|
|
|
|
class RrdCheck extends BaseValidation
|
|
{
|
|
protected static $RUN_BY_DEFAULT = false;
|
|
|
|
/**
|
|
* 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 = $this->test($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";
|
|
}
|
|
|
|
/**
|
|
* Run rrdtool info on a file path
|
|
*
|
|
* @param string $path Path to pass to rrdtool info
|
|
* @param string $stdOutput Variable to recieve the output of STDOUT
|
|
* @param string $stdError Variable to recieve the output of STDERR
|
|
*
|
|
* @return int exit code
|
|
*
|
|
**/
|
|
private function test($path, &$stdOutput, &$stdError)
|
|
{
|
|
//rrdtool info <escaped rrd path>
|
|
$command = Config::get('rrdtool') . ' info ' . escapeshellarg($path);
|
|
$process = proc_open(
|
|
$command,
|
|
array (
|
|
0 => array('pipe', 'r'),
|
|
1 => array('pipe', 'w'),
|
|
2 => array('pipe', 'w'),
|
|
),
|
|
$pipes
|
|
);
|
|
|
|
if (!is_resource($process)) {
|
|
throw new \RuntimeException('Could not create a valid process');
|
|
}
|
|
|
|
$status = proc_get_status($process);
|
|
while ($status['running']) {
|
|
usleep(2000); // Sleep 2000 microseconds or 2 milliseconds
|
|
$status = proc_get_status($process);
|
|
}
|
|
|
|
$stdOutput = stream_get_contents($pipes[1]);
|
|
$stdError = stream_get_contents($pipes[2]);
|
|
proc_close($process);
|
|
return $status['exitcode'];
|
|
}
|
|
}
|