fix some things

git-svn-id: http://www.observium.org/svn/observer/trunk@2351 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-05-20 14:27:53 +00:00
parent d48badddc5
commit 90dfbfa141
5 changed files with 49 additions and 6 deletions

View File

@@ -234,6 +234,17 @@ if ($debug) echo("$string\n");
if($config['version_check'] && !isset($options['q'])) { if($config['version_check'] && !isset($options['q'])) {
include("includes/versioncheck.inc.php"); include("includes/versioncheck.inc.php");
echo('MySQL: Cell['.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,2).'s]'.
' Row[' .($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,2).'s]'.
' Rows[' .($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,2).'s]'.
' Column['.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,2).'s]'.
' Update[' .($db_stats['update']+0).'/'.round($db_stats['update_sec']+0,2).'s]'.
' Insert['.($db_stats['insert']+0). '/'.round($db_stats['insert_sec']+0,2).'s]'.
' Delete['.($db_stats['delete']+0). '/'.round($db_stats['delete_sec']+0,2).'s]');
echo("\n");
} }
logfile($string); logfile($string);

View File

@@ -6,7 +6,7 @@
<select name='device_id' id='device_id'> <select name='device_id' id='device_id'>
<option value=''>All Devices</option> <option value=''>All Devices</option>
<?php <?php
foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $dat) foreach (dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`") as $data)
{ {
echo("<option value='".$data['device_id']."'"); echo("<option value='".$data['device_id']."'");
if ($data['device_id'] == $_POST['device_id']) { echo("selected"); } if ($data['device_id'] == $_POST['device_id']) { echo("selected"); }

View File

@@ -51,6 +51,7 @@ function dbQuery($sql, $parameters = array()) {
* */ * */
function dbInsert($data, $table) { function dbInsert($data, $table) {
global $fullSql; global $fullSql;
global $db_stats;
// the following block swaps the parameters if they were given in the wrong order. // the following block swaps the parameters if they were given in the wrong order.
// it allows the method to work for those that would rather it (or expect it to) // it allows the method to work for those that would rather it (or expect it to)
// follow closer with SQL convention: // follow closer with SQL convention:
@@ -64,19 +65,26 @@ function dbInsert($data, $table) {
$sql = 'INSERT INTO `' . $table . '` (`' . implode('`,`', array_keys($data)) . '`) VALUES (' . implode(',', dbPlaceHolders($data)) . ')'; $sql = 'INSERT INTO `' . $table . '` (`' . implode('`,`', array_keys($data)) . '`) VALUES (' . implode(',', dbPlaceHolders($data)) . ')';
$time_start = microtime(true);
dbBeginTransaction(); dbBeginTransaction();
$result = dbQuery($sql, $data); $result = dbQuery($sql, $data);
if($result) { if($result) {
$id = mysql_insert_id(); $id = mysql_insert_id();
dbCommitTransaction(); dbCommitTransaction();
return $id; #return $id;
} else { } else {
if($table != 'Contact') { if($table != 'Contact') {
trigger_error('QDB - Insert failed.', E_USER_WARNING); trigger_error('QDB - Insert failed.', E_USER_WARNING);
} }
dbRollbackTransaction(); dbRollbackTransaction();
return false; #$id = false;
} }
$time_end = microtime(true);
$db_stats['insert_sec'] += number_format($time_end - $time_start, 8);
$db_stats['insert']++;
return $id;
} }
/* /*
@@ -85,6 +93,7 @@ function dbInsert($data, $table) {
* */ * */
function dbUpdate($data, $table, $where = null, $parameters = array()) { function dbUpdate($data, $table, $where = null, $parameters = array()) {
global $fullSql; global $fullSql;
global $db_stats;
// the following block swaps the parameters if they were given in the wrong order. // the following block swaps the parameters if they were given in the wrong order.
// it allows the method to work for those that would rather it (or expect it to) // it allows the method to work for those that would rather it (or expect it to)
// follow closer with SQL convention: // follow closer with SQL convention:
@@ -109,13 +118,20 @@ function dbUpdate($data, $table, $where = null, $parameters = array()) {
$data = array_merge($data, $parameters); $data = array_merge($data, $parameters);
} }
$time_start = microtime(true);
if(dbQuery($sql, $data)) { if(dbQuery($sql, $data)) {
return mysql_affected_rows(); $return = mysql_affected_rows();
} else { } else {
#echo("$fullSql"); #echo("$fullSql");
trigger_error('QDB - Update failed.', E_USER_WARNING); trigger_error('QDB - Update failed.', E_USER_WARNING);
return false; $return = false;
} }
$time_end = microtime(true);
$db_stats['update_sec'] += number_format($time_end - $time_start, 8);
$db_stats['update']++;
return $return;
} }
function dbDelete($table, $where = null, $parameters = array()) { function dbDelete($table, $where = null, $parameters = array()) {

View File

@@ -285,9 +285,14 @@ if (is_array($ospf_nbrs_db))
if ($ospf_nbr_db['interface_id'] != $ospf_nbr_poll['interface_id']) if ($ospf_nbr_db['interface_id'] != $ospf_nbr_poll['interface_id'])
{ {
$ospf_nbr_update = " "; if($ospf_nbr_poll['interface_id']) {
$ospf_nbr_update = array('interface_id' => $ospf_nbr_poll['interface_id']);
} else {
$ospf_nbr_update = array('interface_id' => array('NULL'));
}
} }
foreach ($ospf_nbr_oids as $oid) foreach ($ospf_nbr_oids as $oid)
{ // Loop the OIDs { // Loop the OIDs
if ($debug) { echo($ospf_nbr_db[$oid]."|".$ospf_nbr_poll[$oid]."\n"); } if ($debug) { echo($ospf_nbr_db[$oid]."|".$ospf_nbr_poll[$oid]."\n"); }

View File

@@ -106,6 +106,7 @@ function poll_device($device, $options) {
global $config; global $config;
global $device; global $device;
global $polled_devices; global $polled_devices;
global $db_stats;
$attribs = get_dev_attribs($device['device_id']); $attribs = get_dev_attribs($device['device_id']);
@@ -239,6 +240,16 @@ if (!$options['m'])
$string = $argv[0] . " $doing " . date("F j, Y, G:i") . " - $polled_devices devices polled in $poller_time secs"; $string = $argv[0] . " $doing " . date("F j, Y, G:i") . " - $polled_devices devices polled in $poller_time secs";
if ($debug) echo("$string\n"); if ($debug) echo("$string\n");
echo('MySQL: Cell['.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,2).'s]'.
' Row[' .($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,2).'s]'.
' Rows[' .($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,2).'s]'.
' Column['.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,2).'s]'.
' Update[' .($db_stats['update']+0).'/'.round($db_stats['update_sec']+0,2).'s]'.
' Insert['.($db_stats['insert']+0). '/'.round($db_stats['insert_sec']+0,2).'s]'.
' Delete['.($db_stats['delete']+0). '/'.round($db_stats['delete_sec']+0,2).'s]');
echo("\n");
logfile($string); logfile($string);
unset($config); ### Remove this for testing unset($config); ### Remove this for testing