mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
Fixed some scrut major issues
This commit is contained in:
@@ -105,14 +105,14 @@ foreach (dbFetch("SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bil
|
||||
{
|
||||
@$timestamp = $row['formatted_date'];
|
||||
if (!$first) { $first = $timestamp; }
|
||||
@$delta = $row['delta'];
|
||||
@$period = $row['period'];
|
||||
@$in_delta = $row['in_delta'];
|
||||
@$out_delta = $row['out_delta'];
|
||||
@$in_value = round($in_delta * 8 / $period, 2);
|
||||
@$out_value = round($out_delta * 8 / $period, 2);
|
||||
$delta = $row['delta'];
|
||||
$period = $row['period'];
|
||||
$in_delta = $row['in_delta'];
|
||||
$out_delta = $row['out_delta'];
|
||||
$in_value = round($in_delta * 8 / $period, 2);
|
||||
$out_value = round($out_delta * 8 / $period, 2);
|
||||
|
||||
@$last = $timestamp;
|
||||
$last = $timestamp;
|
||||
|
||||
$iter_in += $in_delta;
|
||||
$iter_out += $out_delta;
|
||||
|
||||
@@ -86,7 +86,7 @@ function graph_error($string)
|
||||
rrdtool_graph($graphfile, $rrd_options);
|
||||
|
||||
if ($height > "99") {
|
||||
$woo = shell_exec($rrd_cmd);
|
||||
shell_exec($rrd_cmd);
|
||||
if ($debug) { echo("<pre>".$rrd_cmd."</pre>"); }
|
||||
if (is_file($graphfile) && !$debug)
|
||||
{
|
||||
@@ -98,7 +98,6 @@ function graph_error($string)
|
||||
} else {
|
||||
if (!$debug) { header('Content-type: image/png'); }
|
||||
$im = imagecreate($width, $height);
|
||||
$orange = imagecolorallocate($im, 255, 225, 225);
|
||||
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
|
||||
imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0));
|
||||
imagepng($im);
|
||||
@@ -113,7 +112,7 @@ if ($error_msg) {
|
||||
|
||||
graph_error($graph_error);
|
||||
|
||||
} elseif (!$auth) {
|
||||
} elseif ($auth === null) {
|
||||
// We are unauthenticated :(
|
||||
|
||||
if ($width < 200)
|
||||
|
||||
+32
-31
@@ -204,12 +204,12 @@ function get_port_by_id($port_id)
|
||||
if (is_numeric($port_id))
|
||||
{
|
||||
$port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($port_id));
|
||||
}
|
||||
if (is_array($port))
|
||||
{
|
||||
return $port;
|
||||
} else {
|
||||
return FALSE;
|
||||
if (is_array($port))
|
||||
{
|
||||
return $port;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,12 +218,12 @@ function get_application_by_id($application_id)
|
||||
if (is_numeric($application_id))
|
||||
{
|
||||
$application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id));
|
||||
}
|
||||
if (is_array($application))
|
||||
{
|
||||
return $application;
|
||||
} else {
|
||||
return FALSE;
|
||||
if (is_array($application))
|
||||
{
|
||||
return $application;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,12 +232,12 @@ function get_sensor_by_id($sensor_id)
|
||||
if (is_numeric($sensor_id))
|
||||
{
|
||||
$sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($sensor_id));
|
||||
}
|
||||
if (is_array($sensor))
|
||||
{
|
||||
return $sensor;
|
||||
} else {
|
||||
return FALSE;
|
||||
if (is_array($sensor))
|
||||
{
|
||||
return $sensor;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,12 +246,12 @@ function get_device_id_by_port_id($port_id)
|
||||
if (is_numeric($port_id))
|
||||
{
|
||||
$device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `port_id` = ?", array($port_id));
|
||||
}
|
||||
if (is_numeric($device_id))
|
||||
{
|
||||
return $device_id;
|
||||
} else {
|
||||
return FALSE;
|
||||
if (is_numeric($device_id))
|
||||
{
|
||||
return $device_id;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,12 +260,12 @@ function get_device_id_by_app_id($app_id)
|
||||
if (is_numeric($app_id))
|
||||
{
|
||||
$device_id = dbFetchCell("SELECT `device_id` FROM `applications` WHERE `app_id` = ?", array($app_id));
|
||||
}
|
||||
if (is_numeric($device_id))
|
||||
{
|
||||
return $device_id;
|
||||
} else {
|
||||
return FALSE;
|
||||
if (is_numeric($device_id))
|
||||
{
|
||||
return $device_id;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,6 +494,7 @@ function formatStorage($value, $round = '2', $sf = '3')
|
||||
|
||||
function format_si($value, $round = '2', $sf = '3')
|
||||
{
|
||||
$neg = 0;
|
||||
if ($value < "0")
|
||||
{
|
||||
$neg = 1;
|
||||
@@ -513,7 +514,7 @@ function format_si($value, $round = '2', $sf = '3')
|
||||
for ($i = 1; (($i < count($sizes)) && ($value != 0) && ($value <= 0.1)); $i++) { $value = $value * 1000; $ext = $sizes[$i]; }
|
||||
}
|
||||
|
||||
if ($neg) { $value = $value * -1; }
|
||||
if ($neg == 1) { $value = $value * -1; }
|
||||
|
||||
return format_number_short(round($value, $round),$sf).$ext;
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ function discover_new_device($hostname)
|
||||
|
||||
if ( match_network($config['nets'], $ip) )
|
||||
{
|
||||
$remote_device_id = addHost ($dst_host);
|
||||
$remote_device_id = addHost ($dst_host,'');
|
||||
if ($remote_device_id) {
|
||||
$remote_device = device_by_id_cache($remote_device_id, 1);
|
||||
echo("+[".$remote_device['hostname']."(".$remote_device['device_id'].")]");
|
||||
discover_device($remote_device);
|
||||
$remote_device = device_by_id_cache($remote_device_id, 1);
|
||||
device_by_id_cache($remote_device_id, 1);
|
||||
return $remote_device_id;
|
||||
}
|
||||
} else {
|
||||
|
||||
+14
-7
@@ -108,7 +108,8 @@ function getHostOS($device)
|
||||
echo("| $sysDescr | $sysObjectId | ");
|
||||
}
|
||||
|
||||
$dir_handle = @opendir($config['install_dir'] . "/includes/discovery/os") or die("Unable to open $path");
|
||||
$path = $config['install_dir'] . "/includes/discovery/os";
|
||||
$dir_handle = @opendir($path) or die("Unable to open $path");
|
||||
while ($file = readdir($dir_handle))
|
||||
{
|
||||
if (preg_match("/.php$/", $file))
|
||||
@@ -136,6 +137,8 @@ function interface_errors($rrd_file, $period = '-1d') // Returns the last in/out
|
||||
|
||||
$cmd = $config['rrdtool']." fetch -s $period -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 4,5";
|
||||
$data = trim(shell_exec($cmd));
|
||||
$in_errors = 0;
|
||||
$out_errors = 0;
|
||||
foreach (explode("\n", $data) as $entry)
|
||||
{
|
||||
list($in, $out) = explode(" ", $entry);
|
||||
@@ -175,6 +178,9 @@ function getImage($device)
|
||||
$image = '<img src="' . $config['base_url'] . '/images/os/' . $distro . '.png" />';
|
||||
}
|
||||
}
|
||||
if (empty($image)) {
|
||||
$image = '<img src="' . $config['base_url'] . '/images/os/generic.png" />';
|
||||
}
|
||||
}
|
||||
|
||||
return $image;
|
||||
@@ -207,6 +213,9 @@ function getImageSrc($device)
|
||||
$image = $config['base_url'] . '/images/os/' . $distro . '.png';
|
||||
}
|
||||
}
|
||||
if (empty($image)) {
|
||||
$image = $config['base_url'] . '/images/os/generic.png';
|
||||
}
|
||||
}
|
||||
|
||||
return $image;
|
||||
@@ -219,13 +228,14 @@ function renamehost($id, $new, $source = 'console')
|
||||
// FIXME does not check if destination exists!
|
||||
$host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id));
|
||||
rename($config['rrd_dir']."/$host",$config['rrd_dir']."/$new");
|
||||
$return = dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id));
|
||||
dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id));
|
||||
log_event("Hostname changed -> $new ($source)", $id, 'system');
|
||||
}
|
||||
|
||||
function delete_device($id)
|
||||
{
|
||||
global $config;
|
||||
$ret = '';
|
||||
|
||||
$host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id));
|
||||
|
||||
@@ -267,8 +277,6 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0
|
||||
// Test reachability
|
||||
if (isPingable($host))
|
||||
{
|
||||
$added = 0;
|
||||
|
||||
if (empty($snmpver))
|
||||
{
|
||||
// Try SNMPv2c
|
||||
@@ -324,7 +332,7 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp', $quiet = '0
|
||||
if (isSNMPable($device))
|
||||
{
|
||||
$snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB");
|
||||
if ($snmphost == "" || ($snmphost && ($snmphost == $host || $hostshort = $host)))
|
||||
if (empty($snmphost) || ($snmphost && ($snmphost == $host || $hostshort = $host)))
|
||||
{
|
||||
$device_id = createHost ($host, $community, $snmpver, $port, $transport);
|
||||
return $device_id;
|
||||
@@ -369,7 +377,6 @@ function scanUDP($host, $port, $timeout)
|
||||
$write = fwrite($handle,"\x00");
|
||||
if (!$write) { next; }
|
||||
$startTime = time();
|
||||
$header = fread($handle, 1);
|
||||
$endTime = time();
|
||||
$timeDiff = $endTime - $startTime;
|
||||
if ($timeDiff >= $timeout)
|
||||
@@ -409,7 +416,7 @@ function netmask2cidr($netmask)
|
||||
return $addr->bitmask;
|
||||
}
|
||||
|
||||
function cidr2netmask()
|
||||
function cidr2netmask($netmask)
|
||||
{
|
||||
return (long2ip(ip2long("255.255.255.255") << (32-$netmask)));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ function poll_sensor($device, $class, $unit)
|
||||
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ?", array($class, $device['device_id'])) as $sensor)
|
||||
{
|
||||
echo("Checking (" . $sensor['poller_type'] . ") $class " . $sensor['sensor_descr'] . "... ");
|
||||
$sensor_value = '';
|
||||
|
||||
if ($sensor['poller_type'] == "snmp")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user