add better debugging. version check quiet.

git-svn-id: http://www.observium.org/svn/observer/trunk@2472 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-09-15 22:35:22 +00:00
parent edaa3d0afe
commit ae2f6b1941
4 changed files with 38 additions and 34 deletions

View File

@@ -164,21 +164,22 @@ if ($discovered_devices)
$string = $argv[0] . " $doing " . date("F j, Y, G:i") . " - $discovered_devices devices discovered in $proctime secs";
if ($debug) echo("$string\n");
if(!$options['h'] == "new" && $config['version_check'] && !isset($options['q'])) {
if(!$options['h'] == "new" && $config['version_check']) {
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");
}
if(!isset($options['q'])) {
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);
?>

View File

@@ -18,6 +18,15 @@ include_once($config['install_dir'] . "/includes/services.inc.php");
include_once($config['install_dir'] . "/includes/dbFacile.php");
include_once($config['install_dir'] . "/includes/console_colour.php");
function external_exec($command)
{
global $debug;
if($debug) { echo($command."/n"); }
$output = shell_exec($command);
if($debug) { echo($output."/n"); }
return $output;
}
function mac_clean_to_readable($mac)
{

View File

@@ -64,10 +64,8 @@ function snmp_get_multi($device, $oids, $options = "-OQUs", $mib = NULL, $mibdir
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oids;
if (!$debug) { $cmd .= " 2>/dev/null"; }
if ($debug) { echo("$cmd\n"); }
$data = trim(shell_exec($cmd));
$data = trim(external_exec($cmd));
$runtime_stats['snmpget']++;
if ($debug) { echo("$data\n"); }
foreach (explode("\n", $data) as $entry)
{
list($oid,$value) = explode("=", $entry);
@@ -141,9 +139,7 @@ function snmp_get($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
if (!$debug) { $cmd .= " 2>/dev/null"; }
if ($debug) { echo("$cmd\n"); }
$data = trim(shell_exec($cmd));
if ($debug) { echo("$data\n"); }
$data = trim(external_exec($cmd));
}
$runtime_stats['snmpget']++;
if (is_string($data) && (preg_match("/No Such Instance/i", $data) || preg_match("/No Such Object/i", $data) || preg_match("/No more variables left/i", $data)))
@@ -198,9 +194,7 @@ function snmp_walk($device, $oid, $options = NULL, $mib = NULL, $mibdir = NULL)
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
if (!$debug) { $cmd .= " 2>/dev/null"; }
if ($debug) { echo("$cmd\n"); }
$data = trim(shell_exec($cmd));
if ($debug) { echo("$data\n"); }
$data = trim(external_exec($cmd));
if (is_string($data) && (preg_match("/No Such (Object|Instance)/i", $data)))
{
@@ -258,9 +252,7 @@ function snmpwalk_cache_cip($device, $oid, $array, $mib = 0)
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
if (!$debug) { $cmd .= " 2>/dev/null"; }
if ($debug) { echo("$cmd\n"); }
$data = trim(shell_exec($cmd));
if ($debug) { echo("$data\n"); }
$data = trim(external_exec($cmd));
$device_id = $device['device_id'];
#echo("Caching: $oid\n");
@@ -324,7 +316,7 @@ function snmp_cache_ifIndex($device)
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
if (isset($retries)) { $cmd .= " -r " . $retries; }
if (!$debug) { $cmd .= " 2>/dev/null"; }
$data = trim(shell_exec($cmd));
$data = trim(external_exec($cmd));
$device_id = $device['device_id'];
foreach (explode("\n", $data) as $entry)
@@ -469,7 +461,9 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0)
if (isset($retries)) { $cmd .= " -r " . $retries; }
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
if (!$debug) { $cmd .= " 2>/dev/null"; }
$data = trim(shell_exec($cmd));
$data = trim(external_exec($cmd));
$device_id = $device['device_id'];
foreach (explode("\n", $data) as $entry)
{
@@ -525,7 +519,7 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
if (isset($retries)) { $cmd .= " -r " . $retries; }
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
if (!$debug) { $cmd .= " 2>/dev/null"; }
$data = trim(shell_exec($cmd));
$data = trim(external_exec($cmd));
$device_id = $device['device_id'];
foreach (explode("\n", $data) as $entry)
@@ -582,7 +576,7 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0)
if (isset($retries)) { $cmd .= " -r " . $retries; }
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$oid;
if (!$debug) { $cmd .= " 2>/dev/null"; }
$data = trim(shell_exec($cmd));
$data = trim(external_exec($cmd));
$device_id = $device['device_id'];
foreach (explode("\n", $data) as $entry)
@@ -642,7 +636,7 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0)
$cmd .= " -t " . $timeout . " -r " . $retries;
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." ".$string;
if (!$debug) { $cmd .= " 2>/dev/null"; }
$data = trim(shell_exec($cmd));
$data = trim(external_exec($cmd));
$x=0;
$values = explode("\n", $data);
#echo("Caching: ifIndex $port\n");
@@ -685,7 +679,7 @@ function snmp_cache_portIfIndex($device, $array)
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
if (isset($retries)) { $cmd .= " -r " . $retries; }
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portIfIndex";
$output = trim(shell_exec($cmd));
$output = trim(external_exec($cmd));
$device_id = $device['device_id'];
foreach (explode("\n", $output) as $entry)
@@ -729,7 +723,7 @@ function snmp_cache_portName($device, $array)
if (isset($timeout)) { $cmd .= " -t " . $timeout; }
if (isset($retries)) { $cmd .= " -r " . $retries; }
$cmd .= " ".$device['transport'].":".$device['hostname'].":".$device['port']." portName";
$output = trim(shell_exec($cmd));
$output = trim(external_exec($cmd));
$device_id = $device['device_id'];
#echo("Caching: portName\n");

View File

@@ -30,19 +30,19 @@ if($dataHandle)
list($cur, $tag) = explode("-", $config['version']);
list($cur_omnipotence, $cur_year, $cur_month, $cur_revision) = explode(".", $cur);
if($argv[1] == "--cron") {
if($argv[1] == "--cron" || isset($options['q'])) {
$fd = fopen($config['log_file'],'a');
fputs($fd,$string . "\n");
fclose($fd);
shell_exec("echo $omnipotence.$year.$month.$month > rrd/version.txt ");
shell_exec("echo $omnipotence.$year.$month.$month > ".$config['rrd_dir']."/version.txt ");
} else {
if($cur != $data) {
echo("Current Version : $cur_omnipotence.$cur_year.$cur_month.$cur_revision \n");
if($omnipotence > $cur_omnipotence) {
echo("New version : $omnipotence.$year.$month.$revision\n");
} elseif ($year > $cur_year) {