lots of cleanups to various things

git-svn-id: http://www.observium.org/svn/observer/trunk@1463 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-07-23 13:42:28 +00:00
parent 97111b96e0
commit 9052296c13
11 changed files with 101 additions and 134 deletions

View File

@@ -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;

View File

@@ -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
?>

View File

@@ -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'];
}

View File

@@ -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);
}
?>

View File

@@ -1,107 +1,52 @@
<?php
$community = $device['community'];
$id = $device['device_id'];
$hostname = $device['hostname'];
$port = $device['port'];
$snmpver = $device['snmpver'];
$cpurrd = $config['rrd_dir'] . "/" . $hostname . "/ios-cpu.rrd";
$memrrd = $config['rrd_dir'] . "/" . $hostname . "/ios-mem.rrd";
$sysDescr = str_replace("IOS (tm)", "IOS (tm),", $sysDescr);
list(,$features,$version) = explode(",", $sysDescr);
$version = str_replace(" Version ", "", $version);
list(,$features) = explode("(", $features);
list(,$features) = explode("-", $features);
$snmp_cmdb = $config['snmpget'] . " -M ".$config['mibdir'] . " -m ENTITY-MIB:OLD-CISCO-CHASSIS-MIB -O Qv -" . $device['snmpver'] . " -c " . $device['community'] . " " .
$device['hostname'].":".$device['port'];
$snmp_cmdb .= " entPhysicalModelName.1 entPhysicalContainedIn.1 entPhysicalName.1 entPhysicalSoftwareRev.1 ";
$snmp_cmdb .= " entPhysicalModelName.1001 entPhysicalContainedIn.1001";
$snmp_cmdb .= " cardDescr.1 cardSlotNumber.1";
$model_data = shell_exec($snmp_cmdb);
if($debug) {echo($model_data);}
list($model_1,$contained_1,$name_1,$ver_1,$model_1001,$contained_1001,$descr_1,$slot_1) = explode("\n", $model_data);
$oids = "entPhysicalModelName.1 entPhysicalContainedIn.1 entPhysicalName.1 entPhysicalSoftwareRev.1 entPhysicalModelName.1001 entPhysicalContainedIn.1001 cardDescr.1 cardSlotNumber.1";
$data = snmp_get_multi($device, $oids, "-OQUs", "ENTITY-MIB:OLD-CISCO-CHASSIS-MIB");
if($slot_1 == "-1" && strpos($descr_1, "No") === FALSE) { $ciscomodel = $descr_1; }
if(($contained_1 == "0" || $name_1 == "Chassis") && strpos($model_1, "No") === FALSE) { $ciscomodel = $model_1; list($version_1) = explode(",",$ver_1); }
if($contained_1001 == "0" && strpos($model_1001, "No") === FALSE) { $ciscomodel = $model_1001; }
$ciscomodel = str_replace("\"","",$ciscomodel);
if($ciscomodel) { $hardware = $ciscomodel; unset($ciscomodel); }
print_r($data);
if(strpos($sysDescr, "IOS XR")) {
list(,$version) = explode(",", $sysDescr);
$version = trim($version);
list(,$version) = explode(" ", $version);
list($version) = explode("\n", $version);
trim($version);
if($data[1]['entPhysicalContainedIn'] == "0")
{
echo("woo");
if(isset($data[1]['entPhysicalSoftwareRev']) && $data[1]['entPhysicalSoftwareRev'] != "")
{
$version = $data[1]['entPhysicalSoftwareRev'];
}
if(isset($data[1]['entPhysicalName']) && $data[1]['entPhysicalName'] != "")
{
$hardware = $data[1]['entPhysicalName'];
}
if(isset($data[1]['entPhysicalModelName']) && $data[1]['entPhysicalModelName'] != "")
{
$hardware = $data[1]['entPhysicalModelName'];
}
}
$cpu5m = shell_exec($config['snmpget'] . " -M ".$config['mibdir'] . " -m OLD-CISCO-CPU-MIB -O qv -$snmpver -c $community $hostname:$port avgBusy5.0");
$cpu5m = $cpu5m + 0;
# if($slot_1 == "-1" && strpos($descr_1, "No") === FALSE) { $ciscomodel = $descr_1; }
# if(($contained_1 == "0" || $name_1 == "Chassis") && strpos($model_1, "No") === FALSE) { $ciscomodel = $model_1; list($version_1) = explode(",",$ver_1); }
# if($contained_1001 == "0" && strpos($model_1001, "No") === FALSE) { $ciscomodel = $model_1001; }
# $ciscomodel = str_replace("\"","",$ciscomodel);
# if($ciscomodel) { $hardware = $ciscomodel; unset($ciscomodel); }
# if(strpos($sysDescr, "IOS XR")) {
# list(,$version) = explode(",", $sysDescr);
# $version = trim($version);
# list(,$version) = explode(" ", $version);
# list($version) = explode("\n", $version);
# trim($version);
# }
echo("$hostname\n");
if (!is_file($cpurrd)) {
$rrdcreate = shell_exec($config['rrdtool'] . " create $cpurrd --step 300 \
DS:LOAD5M:GAUGE:600:-1:100 \
RRA:AVERAGE:0.5:1:2000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:2000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000 \
RRA:MIN:0.5:1:2000 \
RRA:MIN:0.5:6:2000 \
RRA:MIN:0.5:24:2000 \
RRA:MIN:0.5:288:2000");
}
shell_exec($config['rrdtool'] . " update $cpurrd N:$cpu5m");
$mem_get = ".1.3.6.1.4.1.9.9.48.1.1.1.6.2 .1.3.6.1.4.1.9.9.48.1.1.1.6.1 .1.3.6.1.4.1.9.9.48.1.1.1.6.3";
$mem_get .= ".1.3.6.1.4.1.9.9.48.1.1.1.5.2 .1.3.6.1.4.1.9.9.48.1.1.1.5.1 .1.3.6.1.4.1.9.9.48.1.1.1.5.3";
$mem_raw = shell_exec($config['snmpget'] . " -M ".$config['mibdir'] . " -O qv -".$device['snmpver']." -c $community $hostname:$port $mem_get");
$mem_raw = str_replace("No Such Instance currently exists at this OID", "0", $mem_raw);
list ($memfreeio, $memfreeproc, $memfreeprocb, $memusedio, $memusedproc, $memusedprocb) = explode("\n", $mem_raw);
$memfreeproc = $memfreeproc + $memfreeprocb;
$memusedproc = $memusedproc + $memusedprocb;
$memfreeio = $memfreeio + 0;
$memfreeproc = $memfreeproc + 0;
$memusedio = $memusedio + 0;
$memusedproc = $memusedproc + 0;
$memtotal = $memfreeio + $memfreeproc + $memusedio + $memusedproc;
if (!is_file($memrrd)) {
shell_exec($config['rrdtool'] ." create $memrrd --step 300 \
DS:IOFREE:GAUGE:600:0:U \
DS:IOUSED:GAUGE:600:-1:U \
DS:PROCFREE:GAUGE:600:0:U \
DS:PROCUSED:GAUGE:600:-1:U \
DS:MEMTOTAL:GAUGE:600:-1:U \
RRA:AVERAGE:0.5:1:2000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:2000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000 \
RRA:MIN:0.5:1:2000 \
RRA:MIN:0.5:6:2000 \
RRA:MIN:0.5:24:2000 \
RRA:MIN:0.5:288:2000");
}
rrdtool_update ($memrrd, "N:$memfreeio:$memusedio:$memfreeproc:$memusedproc:$memtotal");
# include("includes/polling/cisco-processors.inc.php");
# include("includes/polling/cisco-enhanced-mempool.inc.php");
# include("includes/polling/cisco-mempool.inc.php");
# include("includes/polling/cisco-entity-sensors.inc.php");
?>

View File

@@ -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");

View File

@@ -1,8 +1,8 @@
<?php
if($array[$device[device_id]][$port[ifIndex]] && $port['ifType'] == "ethernetCsmacd") { // Check to make sure Port data is cached.
if($port_stats[$device[device_id]][$port[ifIndex]] && $port['ifType'] == "ethernetCsmacd") { // 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("etherlike-".$port['ifIndex'].".rrd");

View File

@@ -28,57 +28,57 @@
$ifmib_oids = array('ifEntry', 'ifXEntry');
echo("Caching Oids: ");
foreach ($ifmib_oids as $oid) { echo("$oid "); $array = snmpwalk_cache_oid($device, $oid, $array, "IF-MIB");}
foreach ($ifmib_oids as $oid) { echo("$oid "); $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, "IF-MIB");}
if($config['enable_ports_etherlike']) { echo("dot3Stats "); $array = snmpwalk_cache_oid($device, "dot3StatsEntry", $array, "EtherLike-MIB"); }
if($config['enable_ports_etherlike']) { echo("dot3Stats "); $port_stats = snmpwalk_cache_oid($device, "dot3StatsEntry", $port_stats, "EtherLike-MIB"); }
if($config['enable_ports_adsl']) {
$device['adsl_count'] = mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifType` = 'adsl'"),0);
}
if($device['adsl_count'] > "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);
?>

View File

@@ -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;
?>

View File

@@ -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());
?>