mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
more code cleanups, modify renamehost to also take a source parameter so we can build a renamehost function into the web gui some day
git-svn-id: http://www.observium.org/svn/observer/trunk@1980 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -62,13 +62,13 @@ if (is_array($oids))
|
||||
|
||||
### FIXME this stuff is foul
|
||||
|
||||
if ($entry['entPhySensorScale'] == "nano") { $divisor = "1000000000"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "micro") { $divisor = "1000000"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "milli") { $divisor = "1000"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "units") { $divisor = "1"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "kilo") { $divisor = "1"; $multiplier = "1000"; }
|
||||
if ($entry['entPhySensorScale'] == "mega") { $divisor = "1"; $multiplier = "1000000"; }
|
||||
if ($entry['entPhySensorScale'] == "giga") { $divisor = "1"; $multiplier = "1000000000"; }
|
||||
if ($entry['entPhySensorScale'] == "nano") { $divisor = "1000000000"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "micro") { $divisor = "1000000"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "milli") { $divisor = "1000"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "units") { $divisor = "1"; $multiplier = "1"; }
|
||||
if ($entry['entPhySensorScale'] == "kilo") { $divisor = "1"; $multiplier = "1000"; }
|
||||
if ($entry['entPhySensorScale'] == "mega") { $divisor = "1"; $multiplier = "1000000"; }
|
||||
if ($entry['entPhySensorScale'] == "giga") { $divisor = "1"; $multiplier = "1000000000"; }
|
||||
|
||||
if (is_numeric($entry['entPhySensorPrecision']) && $entry['entPhySensorPrecision'] > "0") { $divisor = $divisor . str_pad('', $entry['entPhySensorPrecision'], "0"); }
|
||||
$current = $current * $multiplier / $divisor;
|
||||
|
||||
@@ -21,7 +21,7 @@ if ($device['os'] == "junos")
|
||||
$usage_oid = ".1.3.6.1.4.1.2636.3.1.13.1.8." . $index;
|
||||
$descr = $entry['jnxOperatingDescr'];
|
||||
$usage = $entry['jnxOperatingBuffer'];
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
|
||||
{
|
||||
discover_mempool($valid_mempool, $device, $index, "junos", $descr, "1", NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
if (!$os)
|
||||
{
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.15")) { $os = "fortigate"; }
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.101.1")) { $os = "fortigate"; }
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.15")) { $os = "fortigate"; }
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.12356.101.1")) { $os = "fortigate"; }
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
if (!$os)
|
||||
{
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.674.3224.1")) { $os = "screenos"; }
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.3224")) { $os = "screenos"; }
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.674.3224.1")) { $os = "screenos"; }
|
||||
if (strstr($sysObjectId, ".1.3.6.1.4.1.3224")) { $os = "screenos"; }
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -34,7 +34,7 @@ foreach (explode("\n", $ports) as $entry)
|
||||
}
|
||||
|
||||
if (empty($ifDescr)) { $nullintf = 1; }
|
||||
if ($device['os'] == "catos" && strstr($if, "vlan") ) { $nullintf = 1; }
|
||||
if ($device['os'] == "catos" && strstr($if, "vlan")) { $nullintf = 1; }
|
||||
if ($device['os'] == "vmware" && preg_match("/Device ([a-z0-9]+) at .*/", $ifDescr, $matches)) { $ifDescr = $matches[1]; }
|
||||
$ifDescr = fixifName($ifDescr);
|
||||
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = 1; }
|
||||
|
||||
@@ -41,7 +41,7 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
|
||||
|
||||
#echo("|".$descr."|");
|
||||
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
|
||||
{
|
||||
discover_processor($valid_processor, $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ if ($device['os'] == "junos")
|
||||
$usage_oid = ".1.3.6.1.4.1.2636.3.1.13.1.8." . $index;
|
||||
$descr = $entry['jnxOperatingDescr'];
|
||||
$usage = $entry['jnxOperatingCPU'];
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
|
||||
{
|
||||
discover_processor($valid_processor, $device, $usage_oid, $index, "junos", $descr, "1", $usage, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ if ($device['os'] == "junose")
|
||||
$descr = $entry['juniSystemModuleDescr'];
|
||||
$usage = $entry['juniSystemModuleCpuFiveMinAvgPct'];
|
||||
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
|
||||
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "")
|
||||
{
|
||||
discover_processor($valid_processor, $device, $usage_oid, $index, "junose", $descr, "1", $usage, $entPhysicalIndex, NULL);
|
||||
}
|
||||
|
||||
+18
-12
@@ -121,7 +121,7 @@ function getHostOS($device)
|
||||
$dir_handle = @opendir($config['install_dir'] . "/includes/discovery/os") or die("Unable to open $path");
|
||||
while ($file = readdir($dir_handle))
|
||||
{
|
||||
if (preg_match("/.php$/", $file) )
|
||||
if (preg_match("/.php$/", $file))
|
||||
{
|
||||
include($config['install_dir'] . "/includes/discovery/os/" . $file);
|
||||
}
|
||||
@@ -167,20 +167,22 @@ function format_bi($size, $round = '2')
|
||||
{
|
||||
$sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E');
|
||||
$ext = $sizes[0];
|
||||
for ($i = 1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; }
|
||||
for ($i = 1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; }
|
||||
return round($size, $round).$ext;
|
||||
}
|
||||
|
||||
function percent_colour($perc)
|
||||
{
|
||||
$r = min(255, 5 * ($perc - 25));
|
||||
$b = max(0, 255 - (5 * ($perc + 25)));
|
||||
return sprintf('#%02x%02x%02x', $r, $b, $b);
|
||||
$r = min(255, 5 * ($perc - 25));
|
||||
$b = max(0, 255 - (5 * ($perc + 25)));
|
||||
|
||||
return sprintf('#%02x%02x%02x', $r, $b, $b);
|
||||
}
|
||||
|
||||
function interface_errors($rrd_file, $period = '-1d') // Returns the last in/out errors value in RRD
|
||||
{
|
||||
global $config;
|
||||
|
||||
$cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5";
|
||||
$data = trim(shell_exec($cmd));
|
||||
foreach (explode("\n", $data) as $entry)
|
||||
@@ -191,6 +193,7 @@ function interface_errors($rrd_file, $period = '-1d') // Returns the last in/out
|
||||
}
|
||||
$errors['in'] = round($in_errors);
|
||||
$errors['out'] = round($out_errors);
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
@@ -223,16 +226,19 @@ function getImage($host)
|
||||
} elseif (file_exists($config['html_dir'] . "/images/os/$distro" . ".gif")){ $image = '<img src="'.$config['base_url'].'/images/os/'.$distro.'.gif" />'; }
|
||||
}
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
function renamehost($id, $new)
|
||||
function renamehost($id, $new, $source = 'console')
|
||||
{
|
||||
global $config;
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
|
||||
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0); # FIXME getdevicebyid?
|
||||
|
||||
rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new");
|
||||
mysql_query("UPDATE devices SET hostname = '$new' WHERE device_id = '$id'");
|
||||
eventlog("Hostname changed -> $new (console)", $id);
|
||||
eventlog("Hostname changed -> $new ($source)", $id);
|
||||
}
|
||||
|
||||
function delete_port($int_id)
|
||||
@@ -300,7 +306,7 @@ function addHost($host, $community, $snmpver, $port = 161, $transport = 'udp')
|
||||
{
|
||||
if (isPingable($host))
|
||||
{
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' )
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0')
|
||||
{
|
||||
# FIXME internalize -- but we don't have $device yet!
|
||||
# FIXME this needs to be addhost.php's content instead, kindof, also use this function there then.
|
||||
@@ -378,7 +384,7 @@ function formatUptime($diff, $format="long")
|
||||
else
|
||||
{
|
||||
if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; }
|
||||
if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; }
|
||||
if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '') . ", "; }
|
||||
if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; }
|
||||
if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; }
|
||||
if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; }
|
||||
@@ -402,12 +408,12 @@ function isSNMPable($device)
|
||||
function isPingable($hostname)
|
||||
{
|
||||
global $config;
|
||||
$status = shell_exec($config['fping'] . " $hostname");
|
||||
$status = shell_exec($config['fping'] . " $hostname 2>/dev/null");
|
||||
if (strstr($status, "alive"))
|
||||
{
|
||||
return TRUE;
|
||||
} else {
|
||||
$status = shell_exec($config['fping6'] . " $hostname");
|
||||
$status = shell_exec($config['fping6'] . " $hostname 2>/dev/null");
|
||||
if (strstr($status, "alive"))
|
||||
{
|
||||
return TRUE;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$version = preg_replace("/.+ version (.+) running on .+ (\S+)$/", "\\1||\\2", $sysDescr );
|
||||
$version = preg_replace("/.+ version (.+) running on .+ (\S+)$/", "\\1||\\2", $sysDescr);
|
||||
list($version,$hardware) = explode("||", $version);
|
||||
|
||||
?>
|
||||
@@ -154,7 +154,7 @@ while ($port = mysql_fetch_array($port_query))
|
||||
$update .= ", `$oid` = NULL";
|
||||
log_event($oid . ": ".$port[$oid]." -> NULL", $device['device_id'], 'interface', $port['interface_id']);
|
||||
if ($debug) { echo($oid . ": ".$port[$oid]." -> NULL "); } else { echo($oid . " "); }
|
||||
} elseif ($port[$oid] != $this_port[$oid] ) {
|
||||
} elseif ($port[$oid] != $this_port[$oid]) {
|
||||
$update .= ", `$oid` = '".mres($this_port[$oid])."'";
|
||||
log_event($oid . ": ".$port[$oid]." -> " . $this_port[$oid], $device['device_id'], 'interface', $port['interface_id']);
|
||||
if ($debug) { echo($oid . ": ".$port[$oid]." -> " . $this_port[$oid]." "); } else { echo($oid . " "); }
|
||||
@@ -251,7 +251,7 @@ while ($port = mysql_fetch_array($port_query))
|
||||
{
|
||||
foreach ($pagp_oids as $oid)
|
||||
{ // Loop the OIDs
|
||||
if ($this_port[$oid] != $port[$oid] )
|
||||
if ($this_port[$oid] != $port[$oid])
|
||||
{ // If data has changed, build a query
|
||||
$update .= ", `$oid` = '".mres($this_port[$oid])."'";
|
||||
echo("PAgP ");
|
||||
|
||||
Reference in New Issue
Block a user