more cleanups and reindents, still a lot to come

git-svn-id: http://www.observium.org/svn/observer/trunk@1836 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-15 09:45:00 +00:00
parent 890823b00f
commit 3a4e92e246
11 changed files with 92 additions and 92 deletions

View File

@@ -13,32 +13,32 @@ $ports = str_replace(" ", "||", $ports);
$interface_ignored = 0;
$interface_added = 0;
foreach(explode("\n", $ports) as $entry){
foreach (explode("\n", $ports) as $entry){
$entry = trim($entry);
list($ifIndex, $ifDescr) = explode("||", $entry, 2);
if(!strstr($entry, "irtual")) {
if (!strstr($entry, "irtual")) {
$if = trim(strtolower($ifDescr));
$nullintf = 0;
foreach($config['bad_if'] as $bi) { if (strstr($if, $bi)) { $nullintf = 1; } }
if(is_array($config['bad_if_regexp'])) {
foreach($config['bad_if_regexp'] as $bi) {
foreach ($config['bad_if'] as $bi) { if (strstr($if, $bi)) { $nullintf = 1; } }
if (is_array($config['bad_if_regexp'])) {
foreach ($config['bad_if_regexp'] as $bi) {
if (preg_match($bi ."i", $if)) {
$nullintf = 1;
}
}
}
if(empty($ifDescr)) { $nullintf = 1; }
if($device['os'] == "catos" && strstr($if, "vlan") ) { $nullintf = 1; }
if (empty($ifDescr)) { $nullintf = 1; }
if ($device['os'] == "catos" && strstr($if, "vlan") ) { $nullintf = 1; }
$ifDescr = fixifName($ifDescr);
if (preg_match('/serial[0-9]:/', $if)) { $nullintf = 1; }
if(isset($config['allow_ng']) && !$config['allow_ng']) {
if (isset($config['allow_ng']) && !$config['allow_ng']) {
if (preg_match('/ng[0-9]+$/', $if)) { $nullintf = 1; }
}
if ($debug) echo("\n $if ");
if ($nullintf == 0) {
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) == '0') {
mysql_query("INSERT INTO `ports` (`device_id`,`ifIndex`,`ifDescr`) VALUES ('".$device['device_id']."','$ifIndex','$ifDescr')");
# Add Interface
echo("+");
@@ -49,7 +49,7 @@ foreach(explode("\n", $ports) as $entry){
$int_exists[] = "$ifIndex";
} else {
# Ignored Interface
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0') {
mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'");
# Delete Interface
echo("-"); ## Deleted Interface
@@ -72,7 +72,7 @@ while ($test_if = mysql_fetch_array($query)) {
if ($int_exists[$i] == $this_if) { $exists = 1; }
$i++;
}
if(!$exists) {
if (!$exists) {
echo("-");
mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE interface_id = '" . $test_if['interface_id'] . "'");
}

View File

@@ -2,17 +2,18 @@
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM processors WHERE device_id = '".$device['device_id']."' AND processor_type != 'ucd-old'"),0);
if($device['os_group'] == "unix" && $count == "0")
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;
if(is_numeric($percent)) {
if (is_numeric($percent))
{
discover_processor($valid_processor, $device, 0, 0, "ucd-old", "CPU", "1", $system+$user, NULL, NULL);
}
}

View File

@@ -13,13 +13,15 @@ include("processors-ucd-old.inc.php");
$sql = "SELECT * FROM `processors` WHERE `device_id` = '".$device['device_id']."'";
$query = mysql_query($sql);
if($debug) { print_r ($valid_processor); }
if ($debug) { print_r ($valid_processor); }
while ($test_processor = mysql_fetch_array($query)) {
while ($test_processor = mysql_fetch_array($query))
{
$processor_index = $test_processor['processor_index'];
$processor_type = $test_processor['processor_type'];
if($debug) { echo($processor_index . " -> " . $processor_type . "\n"); }
if(!$valid_processor[$processor_type][$processor_index]) {
if ($debug) { echo($processor_index . " -> " . $processor_type . "\n"); }
if (!$valid_processor[$processor_type][$processor_index])
{
echo("-");
mysql_query("DELETE FROM `processors` WHERE processor_id = '" . $test_processor['processor_id'] . "'");
}

View File

@@ -6,9 +6,9 @@ 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"); }
if(is_array($hrDevice_array))
if (is_array($hrDevice_array))
{
foreach($hrDevice_array as $index => $entry)
foreach ($hrDevice_array as $index => $entry)
{
if ($entry['hrDeviceType'] == "hrDeviceProcessor")
{
@@ -20,10 +20,10 @@ if(is_array($hrDevice_array))
#### What is this for? I have forgotten. What has : in its hrDeviceDescr?
#### Set description to that found in hrDeviceDescr, first part only if containing a :
$descr_array = explode(":",$entry['hrDeviceDescr']);
if($descr_array['1']) { $descr = $descr_array['1']; } else { $descr = $descr_array['0']; }
if ($descr_array['1']) { $descr = $descr_array['1']; } else { $descr = $descr_array['0']; }
### Workaround to set fake description for Mikrotik who don't populate hrDeviceDescr
if($device['os'] == "routeros" && !isset($entry['hrDeviceDescr'])) { $descr = "Processor";}
if ($device['os'] == "routeros" && !isset($entry['hrDeviceDescr'])) { $descr = "Processor";}
$descr = str_replace("CPU ", "", $descr);
$descr = str_replace("(TM)", "", $descr);
@@ -32,12 +32,13 @@ if(is_array($hrDevice_array))
$old_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("hrProcessor-" . $index . ".rrd");
$new_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-hr-" . $index . ".rrd");
if($debug) { echo("$old_rrd $new_rrd"); }
if (is_file($old_rrd)) {
if ($debug) { echo("$old_rrd $new_rrd"); }
if (is_file($old_rrd))
{
rename($old_rrd,$new_rrd);
echo("Moved RRD ");
}
if(isset($descr) && $descr != "An electronic chip that makes the computer work.")
if (isset($descr) && $descr != "An electronic chip that makes the computer work.")
{
discover_processor($valid_processor, $device, $usage_oid, $index, "hr", $descr, "1", $usage, NULL, $hrDeviceIndex);
}

View File

@@ -6,7 +6,7 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
{
echo("CISCO-PROCESS-MIB : ");
$processors_array = snmpwalk_cache_oid($device, "cpmCPU", NULL, "CISCO-PROCESS-MIB");
if($debug) { print_r($processors_array); }
if ($debug) { print_r($processors_array); }
foreach ($processors_array as $index => $entry)
{
@@ -14,19 +14,20 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
{
$entPhysicalIndex = $entry['cpmCPUTotalPhysicalIndex'];
if(isset($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(isset($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'];
}
if($entPhysicalIndex) {
if ($entPhysicalIndex) {
$descr_oid = "entPhysicalName." . $entPhysicalIndex;
$descr = snmp_get($device, $descr_oid, "-Oqv", "ENTITY-MIB");
}
if(!$descr) { $descr = "Processor $index"; }
if (!$descr) { $descr = "Processor $index"; }
$old_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("cpmCPU-" . $index . ".rrd");
$new_rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-cpm-" . $index . ".rrd");
@@ -34,13 +35,13 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
if (is_file($old_rrd))
{
shell_exec("mv -f $old_rrd $new_rrd");
if($debug) { echo("$old_rrd $new_rrd"); }
if ($debug) { echo("$old_rrd $new_rrd"); }
echo("Moved RRD ");
}
#echo("|".$descr."|");
if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
{
discover_processor($valid_processor, $device, $usage_oid, $index, "cpm", $descr, "1", $entry['juniSystemModuleCpuUtilPct'], $entPhysicalIndex, NULL);
}

View File

@@ -2,22 +2,23 @@
global $valid_processor;
if($device['os'] == "ironware" || $device['os_group'] == "ironware")
if ($device['os'] == "ironware" || $device['os_group'] == "ironware")
{
echo("IronWare : ");
$processors_array = snmpwalk_cache_triple_oid($device, "snAgentCpuUtilEntry", $processors_array, "FOUNDRY-SN-AGENT-MIB");
if($debug) { print_r($processors_array); }
foreach($processors_array as $index => $entry)
if ($debug) { print_r($processors_array); }
foreach ($processors_array as $index => $entry)
{
if (($entry['snAgentCpuUtilValue'] || $entry['snAgentCpuUtil100thPercent']) && $entry['snAgentCpuUtilInterval'] == "300")
{
#$entPhysicalIndex = $entry['cpmCPUTotalPhysicalIndex'];
if($entry['snAgentCpuUtil100thPercent']) {
if ($entry['snAgentCpuUtil100thPercent'])
{
$usage_oid = ".1.3.6.1.4.1.1991.1.1.2.11.1.1.6." . $index;
$usage = $entry['snAgentCpuUtil100thPercent'];
$precision = 100;
} elseif($entry['snAgentCpuUtilValue']) {
} elseif ($entry['snAgentCpuUtilValue']) {
$usage_oid = ".1.3.6.1.4.1.1991.1.1.2.11.1.1.4." . $index;
$usage = $entry['snAgentCpuUtilValue'];
$precision = 100;
@@ -40,7 +41,6 @@ if($device['os'] == "ironware" || $device['os_group'] == "ironware")
}
}
}
## End Ironware Processors
unset ($processors_array);

View File

@@ -3,7 +3,7 @@
global $valid_processor;
## JUNOS Processors
if($device['os'] == "junos")
if ($device['os'] == "junos")
{
echo("JUNOS : ");
$processors_array = snmpwalk_cache_multi_oid($device, "jnxOperatingCPU", $processors_array, "JUNIPER-MIB" , '+'.$config['install_dir']."/mibs/junos");
@@ -21,7 +21,7 @@ if($device['os'] == "junos")
$usage_oid = ".1.3.6.1.4.1.2636.3.1.13.1.8." . $index;
$descr = $entry['jnxOperatingDescr'];
$usage = $entry['jnxOperatingCPU'];
if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
{
discover_processor($valid_processor, $device, $usage_oid, $index, "junos", $descr, "1", $usage, NULL, NULL);
}

View File

@@ -3,11 +3,11 @@
global $valid_processor;
## JUNOSe Processors
if($device['os'] == "junose")
if ($device['os'] == "junose")
{
echo("JUNOSe : ");
$processors_array = snmpwalk_cache_double_oid($device, "juniSystemModule", $processors_array, "Juniper-System-MIB" , $config['install_dir']."/mibs/junose");
if($debug) { print_r($processors_array); }
if ($debug) { print_r($processors_array); }
foreach ($processors_array as $index => $entry)
{
@@ -19,7 +19,7 @@ if($device['os'] == "junose")
$descr = $entry['juniSystemModuleDescr'];
$usage = $entry['juniSystemModuleCpuFiveMinAvgPct'];
if(!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
if (!strstr($descr, "No") && !strstr($usage, "No") && $descr != "" )
{
discover_processor($valid_processor, $device, $usage_oid, $index, "junose", $descr, "1", $usage, $entPhysicalIndex, NULL);
}

View File

@@ -8,18 +8,17 @@ global $valid_processor;
## STATISTICS-MIB::hpSwitchCpuStat.0 = INTEGER: 10
if($device['os'] == "procurve")
if ($device['os'] == "procurve")
{
echo("Procurve : ");
$descr = "Processor";
$usage = snmp_get($device, ".1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0", "-OQUvs", "STATISTICS-MIB", $config['mib_dir'].":".$config['mib_dir']."/hp");
if(is_numeric($usage))
if (is_numeric($usage))
{
discover_processor($valid_processor, $device, "1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0", "0", "procurve-fixed", $descr, "1", $usage, NULL, NULL);
}
}
unset ($processors_array);

View File

@@ -6,19 +6,17 @@ global $valid_processor;
## Hardcoded discovery of cpu usage on RADLAN devices.
##
if($device['os'] == "radlan")
if ($device['os'] == "radlan")
{
echo("RADLAN : ");
$descr = "Processor";
$usage = snmp_get($device, ".1.3.6.1.4.1.89.1.9.0", "-OQUvs", "RADLAN-rndMng", $config['mib_dir'].":".$config['mib_dir']."/radlan");
if(is_numeric($usage))
if (is_numeric($usage))
{
discover_processor($valid_processor, $device, ".1.3.6.1.4.1.89.1.9.0", "0", "radlan", $descr, "1", $usage, NULL, NULL);
}
}
unset ($processors_array);

View File

@@ -1,18 +1,16 @@
<?php
if($device['os'] == "screenos" && mysql_result(mysql_query("SELECT COUNT(*) FROM processors WHERE device_id = '".$device['device_id']."' AND processor_type != 'screenos'"),0) == "0")
if ($device['os'] == "screenos" && mysql_result(mysql_query("SELECT COUNT(*) FROM processors WHERE device_id = '".$device['device_id']."' AND processor_type != 'screenos'"),0) == "0")
{
# .1.3.6.1.4.1.3224.16.1.3.0 Cpu Last 5 Minutes
# discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision = "1", $current = NULL, $entPhysicalIndex = NULL, $hrDeviceIndex = NULL)
echo("ScreenOS ");
$percent = snmp_get($device, ".1.3.6.1.4.1.3224.16.1.3.0", "-OvQ");
if(is_numeric($percent)) {
if (is_numeric($percent))
{
discover_processor($valid_processor, $device, ".1.3.6.1.4.1.3224.16.1.3.0", "1", "screenos", "Processor", "1", $percent, NULL, NULL);
}
}