more cleanup/reindent, yay

git-svn-id: http://www.observium.org/svn/observer/trunk@1839 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-15 11:24:35 +00:00
parent e43eaf7461
commit 12fbf7430c
13 changed files with 391 additions and 378 deletions

View File

@@ -2,14 +2,14 @@
global $valid_sensor;
if ($device['os'] == "ios" || $device['os_group'] == "ios")
if ($device['os'] == "ios" || $device['os_group'] == "ios")
{
echo("\nCISCO-ENTITY-SENSOR");
$oids = array();
$oids = array();
echo("\nCaching OIDs:");
if(!is_array($entity_array))
if (!is_array($entity_array))
{
$entity_array = array();
echo(" entPhysicalDescr");
@@ -39,8 +39,7 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
echo("\nSensors: ");
if($debug) { print_r($oids); }
if ($debug) { print_r($oids); }
$entitysensor['voltsDC'] = "voltage";
$entitysensor['voltsAC'] = "voltage";
@@ -52,93 +51,96 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
$entitysensor['celsius'] = "temperature";
$entitysensor['watts'] = "watts";
if(is_array($oids))
if (is_array($oids))
{
foreach($oids as $index => $entry)
foreach ($oids as $index => $entry)
{
#echo("[" . $entry['entSensorType'] . "|" . $entry['entSensorValue']. "|" . $index . "]");
if($entitysensor[$entry['entSensorType']] && is_numeric($entry['entSensorValue']) && is_numeric($index))
if ($entitysensor[$entry['entSensorType']] && is_numeric($entry['entSensorValue']) && is_numeric($index))
{
$entPhysicalIndex = $index;
$descr = $entity_array[$index]['entPhysicalName'];
if($descr || $device['os'] == "iosxr")
{
if ($descr || $device['os'] == "iosxr")
{
$descr = rewrite_entity_descr($descr);
} else {
$descr = $entity_array[$index]['entPhysicalDescr'];
} else {
$descr = $entity_array[$index]['entPhysicalDescr'];
$descr = rewrite_entity_descr($descr);
}
## Set description based on measured entity if it exists
if(is_numeric($entry['entSensorMeasuredEntity']) && $entry['entSensorMeasuredEntity']) {
if (is_numeric($entry['entSensorMeasuredEntity']) && $entry['entSensorMeasuredEntity'])
{
$measured_descr = $entity_array[$entry['entSensorMeasuredEntity']]['entPhysicalName'];
if(!measured_descr)
if (!measured_descr)
{
$measured_descr = $entity_array[$entry['entSensorMeasuredEntity']]['entPhysicalDescr'];
}
}
$descr = $measured_descr . " - " . $descr;
}
### Bit dirty also, clean later
$descr = str_replace("Temp: ", "", $descr);
$descr = str_ireplace("temperature ", "", $descr);
$descr = str_ireplace("temperature ", "", $descr);
$oid = ".1.3.6.1.4.1.9.9.91.1.1.1.1.4.".$index;
$current = $entry['entSensorValue'];
$type = $entitysensor[$entry['entSensorType']];
#echo("$index : ".$entry['entSensorScale']."|");
### FIXME this stuff is foul
if($entry['entSensorScale'] == "nano") { $divisor = "1000000000"; $multiplier = "1"; }
if($entry['entSensorScale'] == "micro") { $divisor = "1000000"; $multiplier = "1"; }
if($entry['entSensorScale'] == "milli") { $divisor = "1000"; $multiplier = "1"; }
if($entry['entSensorScale'] == "units") { $divisor = "1"; $multiplier = "1"; }
if($entry['entSensorScale'] == "kilo") { $divisor = "1"; $multiplier = "1000"; }
if($entry['entSensorScale'] == "mega") { $divisor = "1"; $multiplier = "1000000"; }
if($entry['entSensorScale'] == "giga") { $divisor = "1"; $multiplier = "1000000000"; }
if(is_numeric($entry['entSensorPrecision']) && $entry['entSensorPrecision'] > "0") { $divisor = $divisor . str_pad('', $entry['entSensorPrecision'], "0"); }
if ($entry['entSensorScale'] == "nano") { $divisor = "1000000000"; $multiplier = "1"; }
if ($entry['entSensorScale'] == "micro") { $divisor = "1000000"; $multiplier = "1"; }
if ($entry['entSensorScale'] == "milli") { $divisor = "1000"; $multiplier = "1"; }
if ($entry['entSensorScale'] == "units") { $divisor = "1"; $multiplier = "1"; }
if ($entry['entSensorScale'] == "kilo") { $divisor = "1"; $multiplier = "1000"; }
if ($entry['entSensorScale'] == "mega") { $divisor = "1"; $multiplier = "1000000"; }
if ($entry['entSensorScale'] == "giga") { $divisor = "1"; $multiplier = "1000000000"; }
if (is_numeric($entry['entSensorPrecision']) && $entry['entSensorPrecision'] > "0") { $divisor = $divisor . str_pad('', $entry['entSensorPrecision'], "0"); }
$current = $current * $multiplier / $divisor;
### Set thresholds to null
$limit = NULL; $low_limit = NULL; $warn_limit = NULL; $warn_limit_low = NULL;
### Check thresholds for this entry (bit dirty, but it works!)
if(is_array($t_oids[$index]))
if (is_array($t_oids[$index]))
{
foreach($t_oids[$index] as $t_index => $entry)
{
### Critical Limit
if($entry['entSensorThresholdSeverity'] == "major" && $entry['entSensorThresholdRelation'] == "greaterOrEqual")
foreach ($t_oids[$index] as $t_index => $entry)
{
$limit = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
}
### Critical Limit
if ($entry['entSensorThresholdSeverity'] == "major" && $entry['entSensorThresholdRelation'] == "greaterOrEqual")
{
$limit = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
}
if($entry['entSensorThresholdSeverity'] == "major" && $entry['entSensorThresholdRelation'] == "lessOrEqual")
{
$limit_low = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
}
### Warning Limit
if($entry['entSensorThresholdSeverity'] == "minor" && $entry['entSensorThresholdRelation'] == "greaterOrEqual")
{
$warn_limit = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
}
if ($entry['entSensorThresholdSeverity'] == "major" && $entry['entSensorThresholdRelation'] == "lessOrEqual")
{
$limit_low = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
}
if($entry['entSensorThresholdSeverity'] == "minor" && $entry['entSensorThresholdRelation'] == "lessOrEqual")
{
$warn_limit_low = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
### Warning Limit
if ($entry['entSensorThresholdSeverity'] == "minor" && $entry['entSensorThresholdRelation'] == "greaterOrEqual")
{
$warn_limit = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
}
if ($entry['entSensorThresholdSeverity'] == "minor" && $entry['entSensorThresholdRelation'] == "lessOrEqual")
{
$warn_limit_low = $entry['entSensorThresholdValue'] * $multiplier / $divisor;
}
}
}
}
### End Threshold code
$ok = TRUE;
if($current == "-127") { $ok = FALSE; } ## False reading
# if($type == "temperature" && $current < 1) { $ok = FALSE; } ## False reading. Temperature <1 :)
if($descr == "") { $ok = FALSE; } ## Invalid description. Lots of these on Nexus
if($ok) {
if ($current == "-127") { $ok = FALSE; } ## False reading
# if ($type == "temperature" && $current < 1) { $ok = FALSE; } ## False reading. Temperature <1 :)
if ($descr == "") { $ok = FALSE; } ## Invalid description. Lots of these on Nexus
if ($ok) {
# echo("\n$valid_sensor, $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $limit, $warn_limit, $current");
discover_sensor($valid_sensor, $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $limit, $warn_limit, $current);
}
@@ -150,4 +152,4 @@ if ($device['os'] == "ios" || $device['os_group'] == "ios")
}
}
?>
?>