From 15cc00c27de28fdf6da6faaab4388a8c7bb39e19 Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 26 Feb 2015 21:51:28 +0000 Subject: [PATCH] Tidying up --- includes/dbFacile.php | 23 ++++++----------------- includes/discovery/functions.inc.php | 10 ++++------ includes/discovery/processors/ios.inc.php | 2 -- includes/discovery/vlans.inc.php | 2 +- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/includes/dbFacile.php b/includes/dbFacile.php index c3aa8ed6bc..1f18c1a6fd 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -24,10 +24,10 @@ Usage function dbQuery($sql, $parameters = array()) { global $fullSql, $debug; $fullSql = dbMakeQuery($sql, $parameters); - //if($debug) { - //print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); - //echo("\nSQL[".$fullSql."] "); - //} + if($debug) { + print Console_Color::convert("\nSQL[%y".$fullSql."%n] "); + #echo("\nSQL[".$fullSql."] "); + } /* if($this->logFile) @@ -35,13 +35,6 @@ function dbQuery($sql, $parameters = array()) { */ $result = mysql_query($fullSql); // sets $this->result - if (mysql_error()) { - echo("\nSQL[".$fullSql."] "); - print mysql_error(); - } - if(mysql_error()) { - file_put_contents('/tmp/mysql_strict.log',date("Y-m-d H:i:s").','.$fullSql.','.mysql_error()."\n",FILE_APPEND); - } /* if($this->logFile) { $time_end = microtime(true); @@ -121,13 +114,9 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) { // need field name and placeholder value // but how merge these field placeholders with actual $parameters array for the WHERE clause - $sql = 'UPDATE `' . $table . '` SET '; + $sql = 'UPDATE `' . $table . '` set '; foreach($data as $key => $value) { - if ($value == "NOW()") { - $sql .= "`".$key."` = " . $value . ","; - } else { - $sql .= "`".$key."` = '" . $value . "',"; - } + $sql .= "`".$key."` ". '=:' . $key . ','; } $sql = substr($sql, 0, -1); // strip off last comma diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index a825356ff1..1b4db40c59 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -132,7 +132,7 @@ function discover_device($device, $options = NULL) function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL, $poller_type = 'snmp', $entPhysicalIndex = NULL, $entPhysicalIndex_measured = NULL) { global $config, $debug; - + if ($debug) { echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n"); } if (is_null($low_warn_limit) || !is_null($warn_limit)) @@ -355,7 +355,7 @@ function sensor_limit($class, $current) function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') { $entries = dbFetchRows("SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?", array($class, $device['device_id'], $poller_type)); - + if (count($entries)) { foreach ($entries as $entry) @@ -475,8 +475,7 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec global $config, $debug; if ($debug) { - echo("\n"); - var_dump($device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex); + echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); } if ($descr) @@ -523,8 +522,7 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = global $config, $debug; if ($debug) { - echo("\n"); - var_dump($device, $index, $type, $descr, $precision, $entPhysicalIndex, $hrDeviceIndex); + echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); } #FIXME implement the mempool_perc, mempool_used, etc. diff --git a/includes/discovery/processors/ios.inc.php b/includes/discovery/processors/ios.inc.php index 71c98b67ff..ce67bd11f0 100755 --- a/includes/discovery/processors/ios.inc.php +++ b/includes/discovery/processors/ios.inc.php @@ -39,7 +39,6 @@ if ($device['os_group'] == "cisco" || $device['os'] == "acsw") if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "") { - //discover_processor($valid['processor'], $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL); discover_processor($valid['processor'], $device, $usage_oid, $index, "cpm", $descr, "1", $usage, $entPhysicalIndex, NULL); } } @@ -48,7 +47,6 @@ if ($device['os_group'] == "cisco" || $device['os'] == "acsw") if (!is_array($valid['processor']['cpm'])) { $avgBusy5 = snmp_get($device, ".1.3.6.1.4.1.9.2.1.58.0", "-Oqv"); - if (is_numeric($avgBusy5)) { discover_processor($valid['processor'], $device, ".1.3.6.1.4.1.9.2.1.58.0", "0", "ios", "Processor", "1", $avgBusy5, NULL, NULL); diff --git a/includes/discovery/vlans.inc.php b/includes/discovery/vlans.inc.php index 4342899ec7..6ad9889850 100644 --- a/includes/discovery/vlans.inc.php +++ b/includes/discovery/vlans.inc.php @@ -64,7 +64,7 @@ foreach ($device['vlans'] as $domain_id => $vlans) if ($from_db['port_vlan_id']) { - dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ". $from_db['port_vlan_id']); + dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ?", array($from_db['port_vlan_id'])); echo("Updated"); } else { dbInsert(array_merge($db_w, $db_a), 'ports_vlans');