mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
move svn upgrade scripts to separate directory
git-svn-id: http://www.observium.org/svn/observer/trunk@1852 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -96,17 +96,17 @@ if (file_exists('.svn'))
|
||||
|
||||
if ($db_rev+0 < 1223)
|
||||
{
|
||||
include("fix-events.php"); ## Fix events table (needs to copy some data around, so needs script)
|
||||
include('upgrade-scripts/fix-events.php'); ## Fix events table (needs to copy some data around, so needs script)
|
||||
}
|
||||
|
||||
if ($db_rev+0 < 1656)
|
||||
{
|
||||
include('fix-port-rrd.php'); ## Rewrites all port RRDs. Nothing will work without this after 1656
|
||||
include('upgrade-scripts/fix-port-rrd.php'); ## Rewrites all port RRDs. Nothing will work without this after 1656
|
||||
}
|
||||
|
||||
if ($db_rev+0 < 1757)
|
||||
{
|
||||
include('fix-sensor-rrd.php'); ## Rewrites all sensor RRDs. Nothing will work without this after 1757
|
||||
include('upgrade-scripts/fix-sensor-rrd.php'); ## Rewrites all sensor RRDs. Nothing will work without this after 1757
|
||||
}
|
||||
|
||||
if ($dbu_rev+0 > $db_rev)
|
||||
|
20
upgrade-scripts/fix-events.php
Executable file
20
upgrade-scripts/fix-events.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
mysql_query("ALTER TABLE `eventlog` DROP `id`");
|
||||
mysql_query("ALTER TABLE `eventlog` ADD `event_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
|
||||
|
||||
$s = "SELECT * FROM eventlog";
|
||||
$q = mysql_query($s);
|
||||
while ($event = mysql_fetch_array($q))
|
||||
{
|
||||
if ($event['interface'])
|
||||
{
|
||||
mysql_query("UPDATE `eventlog` SET `interface` = NULL, `type` = 'interface', `reference` = '".$event['interface']."' WHERE `event_id` = '".$event['event_id']."'");
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
mysql_query("ALTER TABLE `eventlog` DROP `interface`");
|
||||
|
||||
?>
|
207
upgrade-scripts/fix-port-rrd.php
Executable file
207
upgrade-scripts/fix-port-rrd.php
Executable file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
include("includes/defaults.inc.php");
|
||||
include("config.php");
|
||||
|
||||
$basepath = $config['rrd_dir'].'/';
|
||||
|
||||
$files = (getDirectoryTree($basepath));
|
||||
|
||||
$count = count($files);
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
|
||||
function fixRdd($file){
|
||||
global $config;
|
||||
global $rrdcached;
|
||||
$fileC = shell_exec( "{$config['rrdtool']} dump $file $rrdcached" );
|
||||
|
||||
#---------------------------------------------------------------------------------------------------------
|
||||
|
||||
$first = <<<FIRST
|
||||
<ds>
|
||||
<name> INDISCARDS </name>
|
||||
<type> DERIVE </type>
|
||||
<minimal_heartbeat> 600 </minimal_heartbeat>
|
||||
<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>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> OUTDISCARDS </name>
|
||||
<type> DERIVE </type>
|
||||
<minimal_heartbeat> 600 </minimal_heartbeat>
|
||||
<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>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> INUNKNOWNPROTOS </name>
|
||||
<type> DERIVE </type>
|
||||
<minimal_heartbeat> 600 </minimal_heartbeat>
|
||||
<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>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> INBROADCASTPKTS </name>
|
||||
<type> DERIVE </type>
|
||||
<minimal_heartbeat> 600 </minimal_heartbeat>
|
||||
<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>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> OUTBROADCASTPKTS </name>
|
||||
<type> DERIVE </type>
|
||||
<minimal_heartbeat> 600 </minimal_heartbeat>
|
||||
<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>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> INMULTICASTPKTS </name>
|
||||
<type> DERIVE </type>
|
||||
<minimal_heartbeat> 600 </minimal_heartbeat>
|
||||
<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>
|
||||
</ds>
|
||||
<ds>
|
||||
<name> OUTMULTICASTPKTS </name>
|
||||
<type> DERIVE </type>
|
||||
<minimal_heartbeat> 600 </minimal_heartbeat>
|
||||
<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>
|
||||
</ds>
|
||||
|
||||
<!-- 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>
|
||||
</ds>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</cdp_prep>
|
||||
SECOND;
|
||||
|
||||
$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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
?>
|
||||
|
84
upgrade-scripts/fix-sensor-rrd.php
Normal file
84
upgrade-scripts/fix-sensor-rrd.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
include("includes/defaults.inc.php");
|
||||
include("config.php");
|
||||
|
||||
$basepath = $config['rrd_dir'].'/';
|
||||
|
||||
$files = (sensor_getDirectoryTree($basepath));
|
||||
|
||||
$count = count($files);
|
||||
|
||||
if ($config['rrdcached'])
|
||||
{
|
||||
$rrdcached = " --daemon " . $config['rrdcached'];
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user