Fix Scrutinizer issues

This commit is contained in:
Paul Gear
2015-06-16 08:42:05 +10:00
parent 95e3d7000d
commit 0eb3e69167
5 changed files with 14 additions and 14 deletions

View File

@@ -20,7 +20,8 @@ foreach (glob($prefix."*.rrd") as $filename) {
$instance = substr($globpart, 0, -4); // take off ".rrd" $instance = substr($globpart, 0, -4); // take off ".rrd"
$ds = array(); $ds = array();
$mibvar = end(explode("-", $subtype)); $mibparts = explode("-", $subtype);
$mibvar = end($mibparts);
$ds['ds'] = name_shorten($mibvar); $ds['ds'] = name_shorten($mibvar);
$ds['descr'] = "$mibvar-$instance"; $ds['descr'] = "$mibvar-$instance";
$ds['filename'] = $filename; $ds['filename'] = $filename;
@@ -33,5 +34,3 @@ $nototal = 0;
$simple_rrd = true; $simple_rrd = true;
include("includes/graphs/generic_multi_line.inc.php"); include("includes/graphs/generic_multi_line.inc.php");
?>

View File

@@ -41,10 +41,10 @@ $subtype = $graphtype['subtype'];
$auth = is_client_authorized($_SERVER['REMOTE_ADDR']); $auth = is_client_authorized($_SERVER['REMOTE_ADDR']);
include($config['install_dir'] . "/html/includes/graphs/$type/auth.inc.php"); include($config['install_dir'] . "/html/includes/graphs/$type/auth.inc.php");
if ($auth && is_file($config['install_dir'] . "/html/includes/graphs/$type/$subtype.inc.php")) { if ($auth === true && is_file($config['install_dir'] . "/html/includes/graphs/$type/$subtype.inc.php")) {
include($config['install_dir'] . "/html/includes/graphs/$type/$subtype.inc.php"); include($config['install_dir'] . "/html/includes/graphs/$type/$subtype.inc.php");
} }
elseif ($auth && is_mib_graph($type, $subtype)) { elseif ($auth === true && is_mib_graph($type, $subtype)) {
include($config['install_dir'] . "/html/includes/graphs/$type/mib.inc.php"); include($config['install_dir'] . "/html/includes/graphs/$type/mib.inc.php");
} }
else { else {

View File

@@ -652,11 +652,14 @@ function d_print_r($var, $no_debug_text = null)
* Substitute for $subst if necessary. * Substitute for $subst if necessary.
* @return the shortened name * @return the shortened name
*/ */
function name_shorten($name, $common, $subst = "mibval", $len = 19) function name_shorten($name, $common = null, $subst = "mibval", $len = 19)
{ {
if (strlen($name) > $len && strpos($name, $common) >= 0) { if ($common !== null) {
$newname = str_replace($common, '', $name); // remove common from the beginning of the string, if present
$name = $newname; if (strlen($name) > $len && strpos($name, $common) >= 0) {
$newname = str_replace($common, '', $name);
$name = $newname;
}
} }
if (strlen($name) > $len) { if (strlen($name) > $len) {
$name = $subst; $name = $subst;
@@ -690,8 +693,8 @@ function is_mib_graph($type, $subtype)
*/ */
function is_client_authorized($clientip) function is_client_authorized($clientip)
{ {
global $config; global $config;
if (isset($config['allow_unauth_graphs']) && $config['allow_unauth_graphs']) { if (isset($config['allow_unauth_graphs']) && $config['allow_unauth_graphs']) {
d_echo("Unauthorized graphs allowed\n"); d_echo("Unauthorized graphs allowed\n");
return true; return true;

View File

@@ -14,5 +14,3 @@
$devicemib = array($device['sysObjectID'] => "all"); $devicemib = array($device['sysObjectID'] => "all");
poll_mibs($devicemib, $device, $graphs); poll_mibs($devicemib, $device, $graphs);
?>

View File

@@ -946,7 +946,7 @@ function snmp_translate($oid, $module, $mibdir = null)
$cmd .= " 2>/dev/null"; // ignore invalid MIBs $cmd .= " 2>/dev/null"; // ignore invalid MIBs
$lines = preg_split('/\n+/', external_exec($cmd)); $lines = preg_split('/\n+/', external_exec($cmd));
if (!$lines) { if (empty($lines)) {
d_echo("No results from snmptranslate\n"); d_echo("No results from snmptranslate\n");
return null; return null;
} }
@@ -1051,7 +1051,7 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs)
foreach ($oids as $index => $array) { foreach ($oids as $index => $array) {
foreach ($array as $oid => $val) { foreach ($array as $oid => $val) {
$type = oid_rrd_type($oid, $mibdef); $type = oid_rrd_type($oid, $mibdef);
if (!$type) { if ($type === false) {
continue; continue;
} }
$usedoids[$index][$oid] = $val; $usedoids[$index][$oid] = $val;