mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 16:04:35 +02:00
Apply "Squiz" code style on old (pre-2014) files
This commit is contained in:
@@ -1,52 +1,56 @@
|
||||
<?php
|
||||
include("includes/defaults.inc.php");
|
||||
include("config.php");
|
||||
require 'includes/defaults.inc.php';
|
||||
require 'config.php';
|
||||
|
||||
$basepath = $config['rrd_dir'].'/';
|
||||
$basepath = $config['rrd_dir'].'/';
|
||||
|
||||
$files = (getDirectoryTree($basepath));
|
||||
$files = (getDirectoryTree($basepath));
|
||||
|
||||
$count = count($files);
|
||||
$count = count($files);
|
||||
|
||||
if ($config['rrdcached'])
|
||||
{
|
||||
$rrdcached = " --daemon " . $config['rrdcached'];
|
||||
if ($config['rrdcached']) {
|
||||
$rrdcached = ' --daemon '.$config['rrdcached'];
|
||||
}
|
||||
|
||||
echo $count." Files \n";
|
||||
$start = date('U');
|
||||
$i = 0;
|
||||
foreach ($files as $file) {
|
||||
fixRdd($file);
|
||||
$i++;
|
||||
if ((date('U') - $start) > 1) {
|
||||
echo (round((($i / $count) * 100), 2)."% \r");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getDirectoryTree($outerDir, &$files=array())
|
||||
{
|
||||
$dirs = array_diff(scandir($outerDir), array( '.', '..' ));
|
||||
foreach ($dirs as $d) {
|
||||
if (is_dir($outerDir.'/'.$d)) {
|
||||
getDirectoryTree($outerDir.'/'.$d, $files);
|
||||
}
|
||||
else {
|
||||
if (preg_match('/^[\d]+.rrd$/', $d)) {
|
||||
array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'.$d));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo($count . " Files \n");
|
||||
$start = date("U");
|
||||
$i = 0;
|
||||
foreach ($files as $file){
|
||||
fixRdd($file);
|
||||
$i++;
|
||||
if (date("U") - $start > 1)
|
||||
echo(round(($i / $count) * 100, 2) . "% \r");
|
||||
}
|
||||
return $files;
|
||||
|
||||
function getDirectoryTree( $outerDir, &$files = array()){
|
||||
|
||||
$dirs = array_diff( scandir( $outerDir ), Array( ".", ".." ) );
|
||||
foreach ( $dirs as $d ){
|
||||
if (is_dir($outerDir."/".$d) ){
|
||||
getDirectoryTree($outerDir.'/'. $d, $files);
|
||||
}else{
|
||||
if (preg_match('/^[\d]+.rrd$/', $d))
|
||||
array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'. $d));
|
||||
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
}//end getDirectoryTree()
|
||||
|
||||
|
||||
function fixRdd($file){
|
||||
global $config;
|
||||
global $rrdcached;
|
||||
$fileC = shell_exec( "{$config['rrdtool']} dump $file $rrdcached" );
|
||||
function fixRdd($file)
|
||||
{
|
||||
global $config;
|
||||
global $rrdcached;
|
||||
$fileC = shell_exec("{$config['rrdtool']} dump $file $rrdcached");
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
|
||||
$first = <<<FIRST
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
$first = <<<FIRST
|
||||
<ds>
|
||||
<name> INDISCARDS </name>
|
||||
<type> DERIVE </type>
|
||||
@@ -54,9 +58,9 @@ $first = <<<FIRST
|
||||
<min> 0.0000000000e+00 </min>
|
||||
<max> 1.2500000000e+10 </max>
|
||||
<!-- PDP Status -->
|
||||
<last_ds> UNKN </last_ds>
|
||||
<value> 0.0000000000e+00 </value>
|
||||
<unknown_sec> 0 </unknown_sec>
|
||||
<last_ds> UNKN </last_ds>
|
||||
<value> 0.0000000000e+00 </value>
|
||||
<unknown_sec> 0 </unknown_sec>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> OUTDISCARDS </name>
|
||||
@@ -65,9 +69,9 @@ $first = <<<FIRST
|
||||
<min> 0.0000000000e+00 </min>
|
||||
<max> 1.2500000000e+10 </max>
|
||||
<!-- PDP Status -->
|
||||
<last_ds> UNKN </last_ds>
|
||||
<value> 0.0000000000e+00 </value>
|
||||
<unknown_sec> 0 </unknown_sec>
|
||||
<last_ds> UNKN </last_ds>
|
||||
<value> 0.0000000000e+00 </value>
|
||||
<unknown_sec> 0 </unknown_sec>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> INUNKNOWNPROTOS </name>
|
||||
@@ -128,20 +132,18 @@ $first = <<<FIRST
|
||||
<!-- Round Robin Archives -->
|
||||
FIRST;
|
||||
|
||||
|
||||
|
||||
$second = <<<SECOND
|
||||
<ds>
|
||||
<primary_value> 0.0000000000e+00 </primary_value>
|
||||
<secondary_value> NaN </secondary_value>
|
||||
<value> NaN </value>
|
||||
<unknown_datapoints> 0 </unknown_datapoints>
|
||||
$second = <<<SECOND
|
||||
<ds>
|
||||
<primary_value> 0.0000000000e+00 </primary_value>
|
||||
<secondary_value> NaN </secondary_value>
|
||||
<value> NaN </value>
|
||||
<unknown_datapoints> 0 </unknown_datapoints>
|
||||
</ds>
|
||||
<ds>
|
||||
<primary_value> 0.0000000000e+00 </primary_value>
|
||||
<secondary_value> NaN </secondary_value>
|
||||
<value> NaN </value>
|
||||
<unknown_datapoints> 0 </unknown_datapoints>
|
||||
<ds>
|
||||
<primary_value> 0.0000000000e+00 </primary_value>
|
||||
<secondary_value> NaN </secondary_value>
|
||||
<value> NaN </value>
|
||||
<unknown_datapoints> 0 </unknown_datapoints>
|
||||
</ds>
|
||||
<ds>
|
||||
<primary_value> 0.0000000000e+00 </primary_value>
|
||||
@@ -173,35 +175,28 @@ $second = <<<SECOND
|
||||
<value> NaN </value>
|
||||
<unknown_datapoints> 0 </unknown_datapoints>
|
||||
</ds>
|
||||
</cdp_prep>
|
||||
</cdp_prep>
|
||||
SECOND;
|
||||
|
||||
$third = <<<THIRD
|
||||
$third = <<<THIRD
|
||||
<v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v></row>
|
||||
THIRD;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
if (!preg_match('/DISCARDS/', $fileC)) {
|
||||
$fileC = str_replace('<!-- Round Robin Archives -->', $first, $fileC);
|
||||
$fileC = str_replace('</cdp_prep>', $second, $fileC);
|
||||
$fileC = str_replace('</row>', $third, $fileC);
|
||||
$tmpfname = tempnam('/tmp', 'OBS');
|
||||
file_put_contents($tmpfname, $fileC);
|
||||
@unlink($file);
|
||||
$newfile = preg_replace('/(\d+)\.rrd/', 'port-\\1.rrd', $file);
|
||||
@unlink($newfile);
|
||||
shell_exec($config['rrdtool']." restore $tmpfname $newfile");
|
||||
unlink($tmpfname);
|
||||
}
|
||||
|
||||
}//end fixRdd()
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
if (!preg_match('/DISCARDS/', $fileC)){
|
||||
$fileC = str_replace('<!-- Round Robin Archives -->', $first, $fileC);
|
||||
$fileC = str_replace('</cdp_prep>', $second, $fileC);
|
||||
$fileC = str_replace('</row>', $third, $fileC);
|
||||
$tmpfname = tempnam("/tmp", "OBS");
|
||||
file_put_contents($tmpfname, $fileC);
|
||||
@unlink($file);
|
||||
$newfile = preg_replace("/(\d+)\.rrd/", "port-\\1.rrd", $file);
|
||||
@unlink($newfile);
|
||||
shell_exec($config['rrdtool'] . " restore $tmpfname $newfile");
|
||||
unlink($tmpfname);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
?>
|
||||
|
||||
echo "\n";
|
||||
|
||||
@@ -1,79 +1,81 @@
|
||||
<?php
|
||||
include("includes/defaults.inc.php");
|
||||
include("config.php");
|
||||
require 'includes/defaults.inc.php';
|
||||
require 'config.php';
|
||||
|
||||
$basepath = $config['rrd_dir'].'/';
|
||||
$basepath = $config['rrd_dir'].'/';
|
||||
|
||||
$files = (sensor_getDirectoryTree($basepath));
|
||||
$files = (sensor_getDirectoryTree($basepath));
|
||||
|
||||
$count = count($files);
|
||||
$count = count($files);
|
||||
|
||||
echo($count . " Files \n");
|
||||
$start = date("U");
|
||||
$i = 0;
|
||||
foreach ($files as $file){
|
||||
sensor_fixRdd($file);
|
||||
$i++;
|
||||
if (date("U") - $start > 1)
|
||||
echo(round(($i / $count) * 100, 2) . "% \r");
|
||||
}
|
||||
echo $count." Files \n";
|
||||
$start = date('U');
|
||||
$i = 0;
|
||||
|
||||
function sensor_getDirectoryTree( $outerDir, &$files = array()){
|
||||
|
||||
$dirs = array_diff( scandir( $outerDir ), Array( ".", ".." ) );
|
||||
foreach ( $dirs as $d ){
|
||||
if (is_dir($outerDir."/".$d) ){
|
||||
sensor_getDirectoryTree($outerDir.'/'. $d, $files);
|
||||
} else {
|
||||
if ((preg_match('/^fan-.*.rrd$/', $d)) ||
|
||||
(preg_match('/^current-.*.rrd$/', $d)) ||
|
||||
(preg_match('/^freq-.*.rrd$/', $d)) ||
|
||||
(preg_match('/^humidity-.*.rrd$/', $d)) ||
|
||||
(preg_match('/^volt-.*.rrd$/', $d)) ||
|
||||
(preg_match('/^temp-.*.rrd$/', $d)) )
|
||||
array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'. $d));
|
||||
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
sensor_fixRdd($file);
|
||||
$i++;
|
||||
if ((date('U') - $start) > 1) {
|
||||
echo (round((($i / $count) * 100), 2)."% \r");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function sensor_fixRdd($file){
|
||||
global $config;
|
||||
global $rrdcached;
|
||||
$fileC = shell_exec( "{$config['rrdtool']} dump $file $rrdcached");
|
||||
if (preg_match('/<name> fan/', $fileC))
|
||||
{
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r fan:sensor");
|
||||
rename($file,str_replace('/fan-','/fanspeed-',$file));
|
||||
}
|
||||
elseif (preg_match('/<name> volt/', $fileC))
|
||||
{
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r volt:sensor");
|
||||
rename($file,str_replace('/volt-','/voltage-',$file));
|
||||
}
|
||||
elseif (preg_match('/<name> current/', $fileC))
|
||||
{
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r current:sensor");
|
||||
}
|
||||
elseif (preg_match('/<name> freq/', $fileC))
|
||||
{
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r freq:sensor");
|
||||
rename($file,str_replace('/freq-','/frequency-',$file));
|
||||
}
|
||||
elseif (preg_match('/<name> humidity/', $fileC))
|
||||
{
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r humidity:sensor");
|
||||
}
|
||||
elseif (preg_match('/<name> temp/', $fileC))
|
||||
{
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r temp:sensor");
|
||||
rename($file,str_replace('/temp-','/temperature-',$file));
|
||||
}
|
||||
}
|
||||
function sensor_getDirectoryTree($outerDir, &$files=array())
|
||||
{
|
||||
|
||||
echo("\n");
|
||||
$dirs = array_diff(scandir($outerDir), array( '.', '..' ));
|
||||
foreach ($dirs as $d) {
|
||||
if (is_dir($outerDir.'/'.$d)) {
|
||||
sensor_getDirectoryTree($outerDir.'/'.$d, $files);
|
||||
}
|
||||
else {
|
||||
if ((preg_match('/^fan-.*.rrd$/', $d))
|
||||
|| (preg_match('/^current-.*.rrd$/', $d))
|
||||
|| (preg_match('/^freq-.*.rrd$/', $d))
|
||||
|| (preg_match('/^humidity-.*.rrd$/', $d))
|
||||
|| (preg_match('/^volt-.*.rrd$/', $d))
|
||||
|| (preg_match('/^temp-.*.rrd$/', $d))
|
||||
) {
|
||||
array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'.$d));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
return $files;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function sensor_fixRdd($file)
|
||||
{
|
||||
global $config;
|
||||
global $rrdcached;
|
||||
$fileC = shell_exec("{$config['rrdtool']} dump $file $rrdcached");
|
||||
if (preg_match('/<name> fan/', $fileC)) {
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r fan:sensor");
|
||||
rename($file, str_replace('/fan-', '/fanspeed-', $file));
|
||||
}
|
||||
else if (preg_match('/<name> volt/', $fileC)) {
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r volt:sensor");
|
||||
rename($file, str_replace('/volt-', '/voltage-', $file));
|
||||
}
|
||||
else if (preg_match('/<name> current/', $fileC)) {
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r current:sensor");
|
||||
}
|
||||
else if (preg_match('/<name> freq/', $fileC)) {
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r freq:sensor");
|
||||
rename($file, str_replace('/freq-', '/frequency-', $file));
|
||||
}
|
||||
else if (preg_match('/<name> humidity/', $fileC)) {
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r humidity:sensor");
|
||||
}
|
||||
else if (preg_match('/<name> temp/', $fileC)) {
|
||||
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r temp:sensor");
|
||||
rename($file, str_replace('/temp-', '/temperature-', $file));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo "\n";
|
||||
|
||||
Reference in New Issue
Block a user