foreach ($entity_array as $index => $entry) { if ($entitysensor[$entry['entPhySensorType']] && is_numeric($entry['entPhySensorValue']) && is_numeric($index) && $entry['entPhySensorOperStatus'] != 'unavailable' && $entry['entPhySensorOperStatus'] != 'nonoperational') { $ok = TRUE; $options = array('entPhysicalIndex' => $index); $oid = ".1.3.6.1.2.1.99.1.1.1.4.{$index}"; $type = $entitysensor[$entry['entPhySensorType']]; $descr = rewrite_entity_name($entry['entPhysicalDescr']); if ($entry['entPhysicalDescr'] && $entry['entPhysicalName']) { // Check if entPhysicalDescr equals entPhysicalName, // Also compare like this: 'TenGigabitEthernet2/1 Bias Current' and 'Te2/1 Bias Current' if (strpos($entry['entPhysicalDescr'], substr($entry['entPhysicalName'], 2)) === FALSE) { $descr = rewrite_entity_name($entry['entPhysicalDescr']) . ' - ' . rewrite_entity_name($entry['entPhysicalName']); } } else { if (!$entry['entPhysicalDescr'] && $entry['entPhysicalName']) { $descr = rewrite_entity_name($entry['entPhysicalName']); } else { if (!$entry['entPhysicalDescr'] && !$entry['entPhysicalName']) { // This is also trick for some retard devices like NetMan Plus $descr = nicecase($type); } } } if ($device['os'] == 'asa' && $entry['entPhySensorScale'] == 'yocto' && $entry['entPhySensorPrecision'] == '0') { // Hardcoded fix for Cisco ASA 9.1.5 (can be other) bug when all scales equals yocto (OBSERVIUM-1110) $scale = 1; } else { if (isset($entry['entPhySensorScale'])) { $scale = si_to_scale($entry['entPhySensorScale'], $entry['entPhySensorPrecision']); } else { // Some devices not report scales, like NetMan Plus. But this is really HACK
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage discovery * @copyright (C) 2006-2014 Adam Armstrong * */ // Huawei VRP mempools $mib = 'HUAWEI-ENTITY-EXTENT-MIB'; echo " {$mib} "; $mempool_array = snmpwalk_cache_multi_oid($device, "hwEntityMemUsage", NULL, $mib, mib_dirs('huawei')); if (is_array($mempool_array)) { $mempool_array = snmpwalk_cache_multi_oid($device, "hwEntityMemSize", $mempool_array, $mib, mib_dirs('huawei')); $mempool_array = snmpwalk_cache_multi_oid($device, "hwEntityBomEnDesc", $mempool_array, $mib, mib_dirs('huawei')); foreach ($mempool_array as $index => $entry) { if (is_numeric($entry['hwEntityMemUsage']) && $entry['hwEntityMemSize'] > 0) { $descr = rewrite_entity_name($entry['hwEntityBomEnDesc']); $percent = $entry['hwEntityMemUsage']; if (!strstr($descr, "No") && !strstr($percent, "No") && $descr != "") { $total = $entry['hwEntityMemSize']; $used = $total * $percent / 100; discover_mempool($valid['mempool'], $device, $index, $mib, $descr, 1, $total, $used); } } } } unset($mempool_array, $index, $descr, $total, $used, $percent); // EOF
/** * @dataProvider providerRewriteEntityName * @group rename_entity */ public function testRewriteEntityName($string, $result) { $this->assertSame($result, rewrite_entity_name($string)); }
<div class="widget widget-table"> <div class="widget-header"> <a href="<?php echo generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'mempool')); ?> "> <i class="oicon-memory"></i><h3>内存</h3> </a> </div> <div class="widget-content"> <?php echo '<table class="table table-condensed-more table-striped table-bordered">'; foreach ($mempools as $mempool) { $percent = round($mempool['mempool_perc'], 0); $text_descr = rewrite_entity_name($mempool['mempool_descr']); if ($mempool['mempool_total'] != '100') { $total = formatStorage($mempool['mempool_total']); $used = formatStorage($mempool['mempool_used']); $free = formatStorage($mempool['mempool_free']); } else { // If total == 100, than memory not have correct size and uses percents only $total = $mempool['mempool_total'] . '%'; $used = $mempool['mempool_used'] . '%'; $free = $mempool['mempool_free'] . '%'; } $background = get_percentage_colours($percent); $graph_array = array(); $graph_array['height'] = "100"; $graph_array['width'] = "210"; $graph_array['to'] = $config['time']['now'];
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage discovery * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $sensor_array = snmpwalk_cache_oid($device, 'hpicfSensorTable', array(), 'HP-ICF-CHASSIS'); foreach ($sensor_array as $index => $entry) { $descr = rewrite_entity_name($entry['hpicfSensorDescr']); // Find entPhysicalClass some way if (stripos($descr, 'fan') !== FALSE) { $entPhysicalClass = 'fan'; } else { if (stripos($descr, 'power') !== FALSE) { $entPhysicalClass = 'power'; } else { if (stripos($descr, 'temperature') !== FALSE) { $entPhysicalClass = 'temperature'; } else { $entPhysicalClass = 'other'; } } } $oid = '.1.3.6.1.4.1.11.2.14.11.1.2.6.1.4.' . $index; $value = $entry['hpicfSensorStatus'];
//BLUECOAT-SG-SENSOR-MIB::deviceSensorTrapEnabled.11 = INTEGER: false(2) //BLUECOAT-SG-SENSOR-MIB::deviceSensorUnits.11 = INTEGER: volts(4) //BLUECOAT-SG-SENSOR-MIB::deviceSensorScale.11 = INTEGER: -2 //BLUECOAT-SG-SENSOR-MIB::deviceSensorValue.10 = INTEGER: 1194 //BLUECOAT-SG-SENSOR-MIB::deviceSensorValue.11 = INTEGER: 330 //BLUECOAT-SG-SENSOR-MIB::deviceSensorCode.11 = INTEGER: ok(1) //BLUECOAT-SG-SENSOR-MIB::deviceSensorStatus.11 = INTEGER: ok(1) //BLUECOAT-SG-SENSOR-MIB::deviceSensorTimeStamp.11 = Timeticks: (3426521929) 396 days, 14:06:59.29 Hundredths of seconds //BLUECOAT-SG-SENSOR-MIB::deviceSensorName.11 = STRING: +3.3V bus voltage 2 (Vcc) echo " BLUECOAT-SG-SENSOR-MIB "; $sensor_array = snmpwalk_cache_multi_oid($device, 'deviceSensorValueTable', array(), 'BLUECOAT-SG-SENSOR-MIB', mib_dirs('bluecoat')); $sensor_type_map = array('volts' => 'voltage', 'rpm' => 'fanspeed', 'celsius' => 'temperature', 'dBm' => 'dbm'); foreach ($sensor_array as $index => $entry) { if ($sensor_type_map[$entry['deviceSensorUnits']] && is_numeric($entry['deviceSensorValue']) && is_numeric($index) && $entry['deviceSensorStatus'] != 'unavailable' && $entry['deviceSensorStatus'] != 'nonoperational') { $ok = TRUE; $descr = rewrite_entity_name($entry['deviceSensorName']); $oid = ".1.3.6.1.4.1.3417.2.1.1.1.1.1.5." . $index; $type = $sensor_type_map[$entry['deviceSensorUnits']]; $scale = si_to_scale($entry['deviceSensorScale']); $value = $entry['deviceSensorValue']; if ($type == "temperature") { if ($value * $scale > 200) { $ok = FALSE; } } if ($value == "-127") { $ok = FALSE; } if ($ok) { discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'bluecoat-sg-proxy-mib', $descr, $scale, $value); }
* Observium * * This file is part of Observium. * * @package observium * @subpackage discovery * @copyright (C) 2006-2014 Adam Armstrong * */ $mib = 'SW-MIB'; echo " {$mib} "; $sensor_array = snmpwalk_cache_multi_oid($device, 'swSensorTable', array(), $mib, mib_dirs('brocade')); $sensor_type_map = array('temperature' => 'temperature', 'fan' => 'fanspeed', 'power-supply' => 'state'); foreach ($sensor_array as $index => $entry) { if ($sensor_type_map[$entry['swSensorType']] && is_numeric($entry['swSensorValue'])) { $descr = rewrite_entity_name($entry['swSensorInfo']); $oid = '.1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.' . $index; $type = $sensor_type_map[$entry['swSensorType']]; $value = $entry['swSensorValue']; // Because I am nice, rename old RRDs - CLEANME remove in r7000 $old_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/sensor-' . $type . '--' . $index . '.rrd'; $new_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/sensor-' . $type . '-sw-mib-' . $index . '.rrd'; if (is_file($old_rrd)) { rename($old_rrd, $new_rrd); print_warning('Moved RRD'); } discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'sw-mib', $descr, 1, $value); } } unset($sensor_type_map, $sensor_array, $index, $type, $value, $descr); // EOF
// DNOS-BOXSERVICES-PRIVATE-MIB::boxServicesPowSupplyIndex.0 = INTEGER: 0 // DNOS-BOXSERVICES-PRIVATE-MIB::boxServicesPowSupplyIndex.1 = INTEGER: 1 // DNOS-BOXSERVICES-PRIVATE-MIB::boxServicesPowSupplyItemType.0 = INTEGER: fixed(1) // DNOS-BOXSERVICES-PRIVATE-MIB::boxServicesPowSupplyItemType.1 = INTEGER: removable(2) // DNOS-BOXSERVICES-PRIVATE-MIB::boxServicesPowSupplyItemState.0 = INTEGER: operational(2) // DNOS-BOXSERVICES-PRIVATE-MIB::boxServicesPowSupplyItemState.1 = INTEGER: notpresent(1) $oid = 'boxServicesPowSuppliesTable'; $oids = snmpwalk_cache_multi_oid($device, $oid, array(), $mib); $show_numbers = count($oids) > 1; foreach ($oids as $index => $entry) { if ($entry['boxServicesPowSupplyItemState'] == 'notpresent') { continue; } // State Sensor $value = $entry['boxServicesPowSupplyItemState']; $descr = nicecase(rewrite_entity_name($entry['boxServicesPowSupplyItemType'])) . ' PSU'; if ($show_numbers) { $descr .= ' ' . ($index + 1); } $sensor_oid = ".1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.7.1.3.{$index}"; $options = array('entPhysicalClass' => 'power'); discover_sensor($valid['sensor'], 'state', $device, $sensor_oid, "boxServicesPowSupplyState.{$index}", 'dnos-boxservices-state', $descr, NULL, $value, $options); } // Power Usage // // DNOS-BOXSERVICES-PRIVATE-MIB::boxsPwrUsageHistoryUnitSampleTime.1.1 = STRING: "6d:03:46:39" // ... // DNOS-BOXSERVICES-PRIVATE-MIB::boxsPwrUsageHistoryUnitSampleTime.1.60 = STRING: "3d:16:45:40" // DNOS-BOXSERVICES-PRIVATE-MIB::boxsPwrUsageHistoryUnitSampleTime.2.1 = STRING: "6d:04:46:39" // ... // DNOS-BOXSERVICES-PRIVATE-MIB::boxsPwrUsageHistoryUnitSampleTime.2.60 = STRING: "3d:17:45:40"
* @copyright (C) 2006-2014 Adam Armstrong * */ $graph_type = "processor_usage"; echo "<div style='margin-top: 5px; padding: 0px;'>"; echo '<table class="table table-striped-two table-condensed table-bordered">'; echo "<thead><tr>\n <th>处理器</th>\n <th>历史</th>\n <th>使用率</th>\n </tr></thead>"; $i = '1'; $sql = "SELECT *, `processors`.`processor_id` as `processor_id`"; $sql .= " FROM `processors`"; $sql .= " LEFT JOIN `processors-state` ON `processors`.processor_id = `processors-state`.processor_id"; $sql .= " WHERE `device_id` = ?"; foreach (dbFetchRows($sql, array($device['device_id'])) as $proc) { $proc_url = "graphs/id=" . $proc['processor_id'] . "/type=" . $graph_type; $mini_url = "graph.php?id=" . $proc['processor_id'] . "&type=" . $graph_type . "&from=" . $config['time']['day'] . "&to=" . $config['time']['now'] . "&width=80&height=20&bg=f4f4f4"; $text_descr = $proc['processor_descr']; $text_descr = rewrite_entity_name($text_descr); $proc_popup = "onmouseover=\"return overlib('<div class=entity-title>" . $device['hostname'] . " - " . $text_descr; $proc_popup .= "</div><img src=\\'graph.php?id=" . $proc['processor_id'] . "&type=" . $graph_type . "&from=" . $config['time']['month'] . "&to=" . $config['time']['now'] . "&width=400&height=125\\'>"; $proc_popup .= "', RIGHT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\""; $percent = round($proc['processor_usage']); $background = get_percentage_colours($percent); echo "<tr>\n <td class='entity-title'><a href='" . $proc_url . "' {$proc_popup}>" . $text_descr . "</a></td>\n <td width=90><a href='" . $proc_url . "' {$proc_popup}><img src='{$mini_url}'></a></td>\n <td width=200><a href='" . $proc_url . "' {$proc_popup}>\n " . print_percentage_bar(400, 20, $percent, $percent . "%", "ffffff", $background['left'], 100 - $percent . "%", "ffffff", $background['right']) . "\n </a></td>\n </tr>"; echo "<tr><td colspan=5>"; $graph_array['id'] = $proc['processor_id']; $graph_array['type'] = $graph_type; print_graph_row($graph_array); } echo "</table>"; echo "</div>"; // EOF
* @subpackage webui * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ $graph_type = "device_processor"; $sql = "SELECT *, `processors`.`processor_id` AS `processor_id`"; $sql .= " FROM `processors`"; $sql .= " LEFT JOIN `processors-state` ON `processors`.processor_id = `processors-state`.processor_id"; $sql .= " WHERE `processors`.`processor_type` != 'hr-average' AND `device_id` = ?"; $processors_db = dbFetchRows($sql, array($device['device_id'])); if (count($processors_db)) { $processors = array(); // Combinate multiple same processors foreach ($processors_db as $proc) { $text_descr = rewrite_entity_name($proc['processor_descr']); $processors[$text_descr]['id'][] = $proc['processor_id']; $processors[$text_descr]['usage'] += $proc['processor_usage']; $processors[$text_descr]['count']++; } ?> <div class="widget widget-table"> <div class="widget-header"> <a href="<?php echo generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'processor')); ?> "> <i class="oicon-processor"></i><h3>处理器</h3> </a> </div>
$descr = str_replace("temperature", "", $descr); $descr = str_replace("sensor", "", $descr); $descr = trim($descr); discover_sensor($valid['sensor'], 'temperature', $device, $temperature_oid, $oid, 'junos', $descr, 1, $temperature); } } } */ $oids = snmpwalk_cache_multi_oid($device, 'jnxOperatingEntry', array(), 'JUNIPER-MIB'); $oids = snmpwalk_cache_multi_oid($device, 'jnxFruEntry', $oids, 'JUNIPER-MIB'); if (OBS_DEBUG > 1) { print_vars($oids); } foreach ($oids as $index => $entry) { $descr = rewrite_entity_name($entry['jnxOperatingDescr']); // Temperature $oid_name = 'jnxOperatingTemp'; $oid_num = '.1.3.6.1.4.1.2636.3.1.13.1.7.' . $index; //$type = $mib . '-' . $oid_name; $type = 'junos'; // Compat with old discovery style $scale = 1; $value = $entry[$oid_name]; if ($value != 0) { discover_sensor($valid['sensor'], 'temperature', $device, $oid_num, $index, $type, $descr, $scale, $value); } $oid_name = 'jnxOperatingState'; $oid_num = '.1.3.6.1.4.1.2636.3.1.13.1.6.' . $index; $type = 'jnxOperatingState'; $value = $entry[$oid_name];
if ($entry['entPhysicalDescr'] && $entry['entPhysicalName']) { // Check if entPhysicalDescr equals entPhysicalName, // Also compare like this: 'TenGigabitEthernet2/1 Bias Current' and 'Te2/1 Bias Current' if (strpos($entry['entPhysicalDescr'], substr($entry['entPhysicalName'], 2)) === FALSE) { $descr = rewrite_entity_name($entry['entPhysicalDescr']) . " - " . rewrite_entity_name($entry['entPhysicalName']); } } else { if (!$entry['entPhysicalDescr']) { $descr = rewrite_entity_name($entry['entPhysicalName']); } } // Set description based on measured entity if it exists if (is_numeric($entry['entSensorMeasuredEntity']) && $entry['entSensorMeasuredEntity']) { $measured_descr = rewrite_entity_name($entity_array[$entry['entSensorMeasuredEntity']]['entPhysicalDescr']); if (!$measured_descr) { $measured_descr = rewrite_entity_name($entity_array[$entry['entSensorMeasuredEntity']]['entPhysicalName']); } if ($measured_descr) { $descr = $measured_descr . " - " . $descr; } } $oid = ".1.3.6.1.4.1.9.9.91.1.1.1.1.4.{$index}"; $value = $entry['entSensorValue']; if ($c_entitysensor[$entry['entSensorType']] != 'state') { // Normal sensors $type = $c_entitysensor[$entry['entSensorType']]; $sensor_type = 'cisco-entity-sensor'; } else { // State sensors $type = 'state'; // 1:other, 2:unknown, 3:chassis, 4:backplane, 5:container, 6:powerSupply,
$hrDeviceIndex = $entry['hrDeviceIndex']; $usage_oid = ".1.3.6.1.2.1.25.3.3.1.2.{$index}"; $usage = $entry['hrProcessorLoad']; // 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']; } // Workaround to set fake description for Mikrotik and other who don't populate hrDeviceDescr if (empty($entry['hrDeviceDescr'])) { $descr = 'Processor'; } $descr = rewrite_entity_name($descr); if ($device['os'] == 'arista_eos' && $index == 1) { unset($descr); } 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); $hr_cpus++; $hr_total += $usage; } unset($old_rrd, $new_rrd, $descr, $entry, $usage_oid, $index, $usage, $hrDeviceIndex, $descr_array); } unset($entry); } if ($hr_cpus) { $hr_total = $hr_total / $hr_cpus; discover_processor($valid['processor'], $device, 1, 1, 'hr-average', 'Average', 1, $usage);
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage discovery * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ // temperature $sensor_array = snmpwalk_cache_multi_oid($device, 'temperature', array(), 'SMARTNODE-MIB'); foreach ($sensor_array as $index => $entry) { if ($entry['tempProbeDescr'] != '' && is_numeric($entry['currentDegreesCelsius'])) { $descr = rewrite_entity_name($entry['tempProbeDescr']); $oid = ".1.3.6.1.4.1.1768.100.70.30.2.1.2." . $index; $type = 'temperature'; $value = $entry['currentDegreesCelsius']; discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'smartnode-temp', $descr, 1, $value); } } /// FIXME. Disabled, since this functionality should be implemented in graphs module. // http://jira.observium.org/browse/OBSERVIUM-1066 /** // calls $sensor_array = snmpwalk_cache_multi_oid($device, 'gateway', array(), 'SMARTNODE-MIB'); foreach ($sensor_array as $index => $entry) { if ($entry['gwDescr'] != '')
//TIMETRA-CHASSIS-MIB::tmnxChassisTotalNumber.0 = INTEGER: 1 $chassis_count = snmp_get($device, "tmnxChassisTotalNumber.0", "-Oqv", $mib); if (!isset($cache_discovery['timetra-chassis-mib'])) { $cache_discovery['timetra-chassis-mib'] = snmpwalk_cache_twopart_oid($device, 'tmnxHwTable', NULL, $mib); } //TIMETRA-CHASSIS-MIB::tmnxHwName.1.50331649 = STRING: "chassis" //TIMETRA-CHASSIS-MIB::tmnxHwName.1.134217729 = STRING: "Slot 1" //TIMETRA-CHASSIS-MIB::tmnxHwTempSensor.1.50331649 = INTEGER: true(1) //TIMETRA-CHASSIS-MIB::tmnxHwTempSensor.1.134217729 = INTEGER: true(1) //TIMETRA-CHASSIS-MIB::tmnxHwTemperature.1.50331649 = INTEGER: 37 degrees celsius //TIMETRA-CHASSIS-MIB::tmnxHwTemperature.1.134217729 = INTEGER: 37 degrees celsius foreach ($cache_discovery['timetra-chassis-mib'] as $chassis => $entries) { $chassis_name = $chassis_count > 1 ? ", Chassis {$chassis}" : ""; foreach ($entries as $index => $entry) { if ($entry['tmnxHwTempSensor'] == 'true' && $entry['tmnxHwTemperature'] != '-1') { $descr = rewrite_entity_name($entry['tmnxHwName']) . $chassis_name; $oid = ".1.3.6.1.4.1.6527.3.1.2.2.1.8.1.18.{$chassis}.{$index}"; $options = array('limit_high' => $entry['tmnxHwTempThreshold']); discover_sensor($valid['sensor'], 'temperature', $device, $oid, "{$chassis}.{$index}", 'timetra-chassis-temp', $descr, 1, $entry['tmnxHwTemperature'], $options); } } } $timetra_entity = array('tmnxChassisPowerSupplyTempStatus' => array('name' => 'Power Supply Temperature', 'class' => 'temperature', 'oid' => '.1.3.6.1.4.1.6527.3.1.2.2.1.5.1.4'), 'tmnxChassisPowerSupply1Status' => array('name' => 'Power Supply 1', 'class' => 'power', 'oid' => '.1.3.6.1.4.1.6527.3.1.2.2.1.5.1.6'), 'tmnxChassisPowerSupply2Status' => array('name' => 'Power Supply 2', 'class' => 'power', 'oid' => '.1.3.6.1.4.1.6527.3.1.2.2.1.5.1.7'), 'tmnxChassisFanOperStatus' => array('name' => 'Fans', 'class' => 'fan', 'oid' => '.1.3.6.1.4.1.6527.3.1.2.2.1.4.1.2')); //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyACStatus.1.1 = INTEGER: deviceNotEquipped(2) //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyACStatus.1.2 = INTEGER: deviceNotEquipped(2) //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyDCStatus.1.1 = INTEGER: deviceStateOk(3) //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyDCStatus.1.2 = INTEGER: deviceStateOk(3) //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyTempStatus.1.1 = INTEGER: deviceNotEquipped(2) //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyTempStatus.1.2 = INTEGER: deviceNotEquipped(2) //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyTempThreshold.1.1 = INTEGER: 58 degrees celsius //TIMETRA-CHASSIS-MIB::tmnxChassisPowerSupplyTempThreshold.1.2 = INTEGER: 58 degrees celsius