Add ./validate.php -m rrdcheck

This will loop through rrd files and highlight any corrupt files.
This commit is contained in:
KHobbits
2016-02-01 23:29:37 +00:00
parent cf55f4efd6
commit 92a7e5796d
2 changed files with 97 additions and 0 deletions

View File

@@ -1366,3 +1366,65 @@ function dnslookup($device,$type=false,$return=false) {
$record = dns_get_record($device['hostname'],$type);
return $record[0][$return];
}//end dnslookup
/**
* Reursive Filter Iterator to iterate directories and locate .rrd files.
*
**/
class RRDReursiveFilterIterator extends \RecursiveFilterIterator {
public function accept() {
$filename = $this->current()->getFilename();
if ($filename[0] === '.') {
// Ignore hidden files and directories
return false;
}
if ($this->isDir()) {
// We want to search into directories
return true;
}
// Matches files with .rrd in the filename.
// We are only searching rrd folder, but there could be other files and we don't want to cause a stink.
return strpos($filename, '.rrd') !== false;
}
}
/**
* 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
*
**/
function rrdtest($path, &$stdOutput, &$stdError) {
//rrdtool info <escaped rrd path>
$command = $config['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']) {
$status = proc_get_status($process);
}
$stdOutput = stream_get_contents($pipes[1]);
$stdError = stream_get_contents($pipes[2]);
proc_close($process);
return $status['exitcode'];
}