From 9052296c1357081eaa7d6bc713c12d88bde937d4 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Fri, 23 Jul 2010 13:42:28 +0000 Subject: [PATCH] lots of cleanups to various things git-svn-id: http://www.observium.org/svn/observer/trunk@1463 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/common.php | 2 +- includes/discovery/processors-ucd-old.inc.php | 4 +- .../discovery/processors/hrdevice.inc.php | 5 + includes/discovery/processors/ios.inc.php | 4 +- includes/polling/netstats.inc.php | 5 +- includes/polling/os/ios.inc.php | 121 +++++------------- includes/polling/port-adsl.inc.php | 4 +- includes/polling/port-etherlike.inc.php | 4 +- includes/polling/ports.inc.php | 75 ++++++----- includes/polling/processors-ucd-old.inc.php | 6 +- poller.php | 5 + 11 files changed, 101 insertions(+), 134 deletions(-) diff --git a/includes/common.php b/includes/common.php index 50db46ac7f..8f2c1a10e8 100644 --- a/includes/common.php +++ b/includes/common.php @@ -9,7 +9,7 @@ function device_by_id_cache($device_id) { $device = $device_cache[$device_id]; } else { - $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'")); + $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'")); $device_cache[$device_id] = $device; } return $device; diff --git a/includes/discovery/processors-ucd-old.inc.php b/includes/discovery/processors-ucd-old.inc.php index 5f0138a611..f33658b086 100644 --- a/includes/discovery/processors-ucd-old.inc.php +++ b/includes/discovery/processors-ucd-old.inc.php @@ -7,8 +7,8 @@ if($device['os_group'] == "unix" && $count == "0") echo("UCD Old: "); $system = snmp_get($device, "ssCpuSystem.0", "-OvQ", "UCD-SNMP-MIB"); - $user = snmp_get($device, "ssCpuUser.0", "-OvQ", "UCD-SNMP-MIB"); - $idle = snmp_get($device, "ssCpuIdle.0", "-OvQ", "UCD-SNMP-MIB"); + $user = snmp_get($device, "ssCpuUser.0", "-OvQ", "UCD-SNMP-MIB"); + $idle = snmp_get($device, "ssCpuIdle.0", "-OvQ", "UCD-SNMP-MIB"); $percent = $system + $user + $idle; diff --git a/includes/discovery/processors/hrdevice.inc.php b/includes/discovery/processors/hrdevice.inc.php index c3d631686c..e9e1a83cac 100755 --- a/includes/discovery/processors/hrdevice.inc.php +++ b/includes/discovery/processors/hrdevice.inc.php @@ -6,6 +6,7 @@ if ($device['os_group'] == "unix" || $device['os'] == "windows" || $device['os'] { echo("hrDevice "); $hrDevice_oids = array('hrDevice','hrProcessorLoad'); + unset($hrDevice_array); foreach ($hrDevice_oids as $oid) { $hrDevice_array = snmpwalk_cache_oid($device, $oid, $hrDevice_array, "HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES"); } foreach($hrDevice_array[$device['device_id']] as $index => $entry) { @@ -40,9 +41,13 @@ if ($device['os_group'] == "unix" || $device['os'] == "windows" || $device['os'] { discover_processor($valid_processor, $device, $usage_oid, $index, "hr", $descr, "1", $usage, NULL, $hrDeviceIndex); } + unset($old_rrd,$new_rrd,$descr,$entry,$usage_oid,$index,$usage,$hrDeviceIndex,$descr_array); } + unset($entry); } + unset($hrDevice_oids, $hrDevice_array, $oid); } + ## End hrDevice Processors ?> diff --git a/includes/discovery/processors/ios.inc.php b/includes/discovery/processors/ios.inc.php index e42f03617c..a44c16ab0a 100755 --- a/includes/discovery/processors/ios.inc.php +++ b/includes/discovery/processors/ios.inc.php @@ -14,10 +14,10 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios") { $entPhysicalIndex = $entry['cpmCPUTotalPhysicalIndex']; - if($entry['cpmCPUTotal5minRev']) { + if(isset($entry['cpmCPUTotal5minRev'])) { $usage_oid = ".1.3.6.1.4.1.9.9.109.1.1.1.1.8." . $index; $usage = $entry['cpmCPUTotal5minRev']; - } elseif($entry['cpmCPUTotal5min']) { + } elseif(isset($entry['cpmCPUTotal5min'])) { $usage_oid = ".1.3.6.1.4.1.9.9.109.1.1.1.1.5." . $index; $usage = $entry['cpmCPUTotal5min']; } diff --git a/includes/polling/netstats.inc.php b/includes/polling/netstats.inc.php index 46b43c92db..60aa70af89 100755 --- a/includes/polling/netstats.inc.php +++ b/includes/polling/netstats.inc.php @@ -6,6 +6,8 @@ if($device[os] != "Snom") { #### These are at the start of large trees that we don't want to walk the entirety of, so we snmpget_multi them + $oids = array(); + $oids['ip'] = array ('ipForwDatagrams','ipInDelivers','ipInReceives','ipOutRequests','ipInDiscards','ipOutDiscards','ipOutNoRoutes', 'ipReasmReqds','ipReasmOKs','ipReasmFails','ipFragOKs','ipFragFails','ipFragCreates', 'ipInUnknownProtos', 'ipInHdrErrors', 'ipInAddrErrors'); @@ -72,8 +74,9 @@ if($device[os] != "Snom") { unset($snmpstring); rrdtool_update($rrdfile, $rrdupdate); - } + } + unset($oids, $data, $data_array, $oid, $protos); } ?> diff --git a/includes/polling/os/ios.inc.php b/includes/polling/os/ios.inc.php index af14a96074..2c14415b1f 100755 --- a/includes/polling/os/ios.inc.php +++ b/includes/polling/os/ios.inc.php @@ -1,107 +1,52 @@ diff --git a/includes/polling/port-adsl.inc.php b/includes/polling/port-adsl.inc.php index 40fef89cac..2b2edeffce 100755 --- a/includes/polling/port-adsl.inc.php +++ b/includes/polling/port-adsl.inc.php @@ -40,9 +40,9 @@ # adslAturPerfValidIntervals.1 = 0 # adslAturPerfInvalidIntervals.1 = 0 - if(isset($array[$device[device_id]][$port[ifIndex]]['adslLineCoding'])) { // Check to make sure Port data is cached. + if(isset($port_stats[$device[device_id]][$port[ifIndex]]['adslLineCoding'])) { // Check to make sure Port data is cached. - $this_port = &$array[$device[device_id]][$port[ifIndex]]; + $this_port = &$port_stats[$device[device_id]][$port[ifIndex]]; $rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("port-".$port['ifIndex']."-adsl.rrd"); diff --git a/includes/polling/port-etherlike.inc.php b/includes/polling/port-etherlike.inc.php index d252a724ee..a515c48ece 100755 --- a/includes/polling/port-etherlike.inc.php +++ b/includes/polling/port-etherlike.inc.php @@ -1,8 +1,8 @@ "0") { echo("ADSL "); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.1.1", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.2.1", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.3.1", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.4.1", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.5.1", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.1", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.2", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.3", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.4", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.5", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.6", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.7", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.8", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.1", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.2", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.3", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.4", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.5", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.6", $array, "ADSL-LINE-MIB"); - $array = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.7", $array, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.1.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.2.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.3.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.4.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.5.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.2", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.3", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.4", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.5", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.6", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.7", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.6.1.8", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.1", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.2", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.3", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.4", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.5", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.6", $port_stats, "ADSL-LINE-MIB"); + $port_stats = snmpwalk_cache_oid($device, ".1.3.6.1.2.1.10.94.1.1.7.1.7", $port_stats, "ADSL-LINE-MIB"); } echo("\n"); - #foreach ($etherlike_oids as $oid) { $array = snmpwalk_cache_oid($device, $oid, $array, "EtherLike-MIB"); } - #foreach ($cisco_oids as $oid) { $array = snmpwalk_cache_oid($device, $oid, $array, "OLD-CISCO-INTERFACES-MIB"); } - #foreach ($pagp_oids as $oid) { $array = snmpwalk_cache_oid($device, $oid, $array, "CISCO-PAGP-MIB"); } + #foreach ($etherlike_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "EtherLike-MIB"); } + #foreach ($cisco_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "OLD-CISCO-INTERFACES-MIB"); } + #foreach ($pagp_oids as $oid) { $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "CISCO-PAGP-MIB"); } if($device['os_group'] == "ios") { - $array = snmp_cache_portIfIndex ($device, $array); - $array = snmp_cache_portName ($device, $array); + $port_stats = snmp_cache_portIfIndex ($device, $port_stats); + $port_stats = snmp_cache_portName ($device, $port_stats); $data_oids[] = "portName"; - #$array = snmpwalk_cache_oid($device, "vmVlan", $array, "CISCO-VLAN-MEMBERSHIP-MIB"); - #$array = snmpwalk_cache_oid($device, "vlanTrunkPortEncapsulationOperType", $array, "CISCO-VTP-MIB"); - #$array = snmpwalk_cache_oid($device, "vlanTrunkPortNativeVlan", $array, "CISCO-VTP-MIB"); + #$port_stats = snmpwalk_cache_oid($device, "vmVlan", $port_stats, "CISCO-VLAN-MEMBERSHIP-MIB"); + #$port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortEncapsulationOperType", $port_stats, "CISCO-VTP-MIB"); + #$port_stats = snmpwalk_cache_oid($device, "vlanTrunkPortNativeVlan", $port_stats, "CISCO-VTP-MIB"); } $polled = time(); /// End Building SNMP Cache Array - if($debug) { print_r($array); } + if($debug) { print_r($port_stats); } /// New interface detection ///// TO DO @@ -89,9 +89,9 @@ while ($port = mysql_fetch_array($port_query)) { echo(" --> " . $port['ifDescr'] . " "); - if($array[$device['device_id']][$port['ifIndex']] && $port['ignore'] == "0") { // Check to make sure Port data is cached. + if($port_stats[$device['device_id']][$port['ifIndex']] && $port['ignore'] == "0") { // Check to make sure Port data is cached. - $this_port = &$array[$device['device_id']][$port['ifIndex']]; + $this_port = &$port_stats[$device['device_id']][$port['ifIndex']]; $polled_period = $polled - $port['poll_time']; @@ -258,7 +258,16 @@ } else { echo("Port Ignored."); } + echo("\n"); + + #### Clear Per-Port Variables Here + unset($this_port); + } + #### Clear Variables Here + unset($port_stats); + + ?> diff --git a/includes/polling/processors-ucd-old.inc.php b/includes/polling/processors-ucd-old.inc.php index f8888af62e..c7cc9fe1c2 100644 --- a/includes/polling/processors-ucd-old.inc.php +++ b/includes/polling/processors-ucd-old.inc.php @@ -2,10 +2,10 @@ ### Simple poller for UCD old style CPU. will always poll the same index. - $system = snmp_get($device, "ssCpuSystem.0", "-OvQ", "UCD-SNMP-MIB"); - $user = snmp_get($device, "ssCpuUser.0", "-OvQ", "UCD-SNMP-MIB"); + #$system = snmp_get($device, "ssCpuSystem.0", "-OvQ", "UCD-SNMP-MIB"); + #$user = snmp_get($device, "ssCpuUser.0", "-OvQ", "UCD-SNMP-MIB"); $idle = snmp_get($device, "ssCpuIdle.0", "-OvQ", "UCD-SNMP-MIB"); - $proc = $system + $user; + $proc = 100 - $idle; ?> diff --git a/poller.php b/poller.php index 44f1e8d072..40bd717941 100755 --- a/poller.php +++ b/poller.php @@ -249,6 +249,7 @@ while ($device = mysql_fetch_array($device_query)) $poll_separator = ", "; $polled_devices++; echo("\n"); + } $device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5); @@ -280,4 +281,8 @@ $string = $argv[0] . " $doing " . date("F j, Y, G:i") . " - $polled_devices dev if ($debug) echo("$string\n"); shell_exec("echo '".$string."' >> ".$config['log_file']); # FIXME EWW +unset($config); ### Remove this for testing + +#print_r(get_defined_vars()); + ?>