refactor: Don't do unneeded snmp queries (#7841)

* Don't do uneeded snmp queries
sensors discovery 26 -> 16
wrapped some poller modules in db checks.  The same could be done for some others, but more work is needed.

* travis fix
This commit is contained in:
Tony Murray
2017-12-02 17:18:45 -06:00
committed by Neil Lathwood
parent 5405498ed6
commit b9dc7773d7
12 changed files with 152 additions and 138 deletions

View File

@@ -13,8 +13,11 @@ if ($device['os'] == 'junos') {
$entity_array = array();
echo ' entPhysicalEntry';
$entity_array = snmpwalk_cache_oid($device, 'entPhysicalEntry', $entity_array, 'ENTITY-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB');
echo ' entAliasMappingIdentifier';
$entity_array = snmpwalk_cache_twopart_oid($device, 'entAliasMappingIdentifier', $entity_array, 'ENTITY-MIB:IF-MIB');
if (!empty($entity_array)) {
echo ' entAliasMappingIdentifier';
$entity_array = snmpwalk_cache_twopart_oid($device, 'entAliasMappingIdentifier', $entity_array, 'ENTITY-MIB:IF-MIB');
}
}
foreach ($entity_array as $entPhysicalIndex => $entry) {

View File

@@ -1,7 +1,6 @@
<?php
$chip = snmp_get($device, '.1.3.6.1.2.1.1.1.0', '-Oqv');
if (preg_match("/(Linux).+(ntc)/", $chip)) {
if (preg_match("/(Linux).+(ntc)/", $poll_device['sysDescr'])) {
$sensor_type = "chip_battery_charge";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.10.112.111.119.101.114.45.115.116.97.';
$lowlimit = 5;

View File

@@ -6,7 +6,7 @@ if ($device['os_group'] == 'cisco') {
$oids = array();
echo 'Caching OIDs:';
if (!is_array($entity_array)) {
if (empty($entity_array)) {
$tmp_oids = array('entPhysicalDescr', 'entPhysicalName', 'entPhysicalClass', 'entPhysicalContainedIn', 'entPhysicalParentRelPos');
$entity_array = array();
foreach ($tmp_oids as $tmp_oid) {

View File

@@ -1,6 +1,5 @@
<?php
$chip = snmp_get($device, '.1.3.6.1.2.1.1.1.0', '-Oqv');
if (preg_match("/(Linux).+(ntc)/", $chip)) {
if (preg_match("/(Linux).+(ntc)/", $poll_device['sysDescr'])) {
$sensor_type = "chip_currents";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.10.112.111.119.101.114.45.115.116.97.';
$lowlimit = 0;

View File

@@ -5,31 +5,40 @@ if (empty($entity_array)) {
$entity_array = array();
echo ' entPhysicalDescr';
$entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalDescr', $entity_array, 'CISCO-ENTITY-SENSOR-MIB');
echo ' entPhysicalName';
$entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalName', $entity_array, 'CISCO-ENTITY-SENSOR-MIB');
if (!empty($entity_array)) {
echo ' entPhysicalName';
$entity_array = snmpwalk_cache_multi_oid($device, 'entPhysicalName', $entity_array, 'CISCO-ENTITY-SENSOR-MIB');
}
}
$oids = array();
echo ' entPhySensorType';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorType', $oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorScale';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorScale', $oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorPrecision';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorPrecision', $oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorValue';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorValue', $oids, 'ENTITY-SENSOR-MIB');
if ($device['os'] === 'arista_eos') {
require 'includes/discovery/sensors/misc/arista-eos-limits.inc.php';
if (!empty($entity_array)) {
$oids = array();
echo ' entPhySensorType';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorType', $oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorScale';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorScale', $oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorPrecision';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorPrecision', $oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorValue';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorValue', $oids, 'ENTITY-SENSOR-MIB');
if ($device['os'] === 'arista_eos') {
require 'includes/discovery/sensors/misc/arista-eos-limits.inc.php';
}
}
$entitysensor['voltsDC'] = 'voltage';
$entitysensor['voltsAC'] = 'voltage';
$entitysensor['amperes'] = 'current';
$entitysensor['watts'] = 'power';
$entitysensor['hertz'] = 'freq';
$entitysensor['percentRH'] = 'humidity';
$entitysensor['rpm'] = 'fanspeed';
$entitysensor['celsius'] = 'temperature';
$entitysensor['dBm'] = 'dbm';
if (is_array($oids)) {
if (!empty($oids)) {
$entitysensor = array(
'voltsDC' => 'voltage',
'voltsAC' => 'voltage',
'amperes' => 'current',
'watts' => 'power',
'hertz' => 'freq',
'percentRH' => 'humidity',
'rpm' => 'fanspeed',
'celsius' => 'temperature',
'dBm' => 'dbm',
);
foreach ($oids as $index => $entry) {
$low_limit = null;
$low_warn_limit = null;

View File

@@ -42,9 +42,7 @@ if (starts_with($sysObjectId, '.1.3.6.1.4.1.232.')) {
}
}
$chip = snmp_get($device, '.1.3.6.1.2.1.1.1.0', '-Oqv');
if (preg_match("/(Linux).+(ntc)/", $chip)) {
if (preg_match("/(Linux).+(ntc)/", $poll_device['sysDescr'])) {
$sensor_type = "chip_axp209_temperature";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.10.112.111.119.101.114.45.115.116.97.';
$lowlimit = -40;

View File

@@ -65,8 +65,7 @@ foreach (explode("\n", $oids) as $data) {
}//end if
}
$chip = snmp_get($device, '.1.3.6.1.2.1.1.1.0', '-Oqv');
if (preg_match("/(Linux).+(ntc)/", $chip)) {
if (preg_match("/(Linux).+(ntc)/", $poll_device['sysDescr'])) {
$sensor_type = "chip_volts";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.10.112.111.119.101.114.45.115.116.97.';
$lowlimit = 3.8;

View File

@@ -5,7 +5,9 @@ use LibreNMS\RRD\RrdDefinition;
if ($device['os_group'] == 'cisco') {
// FIXME - seems to be broken. IPs appear with leading zeroes.
$ipsec_array = snmpwalk_cache_oid($device, 'cipSecTunnelEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB');
$ike_array = snmpwalk_cache_oid($device, 'cikeTunnelEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB');
if (!empty($ipsec_array)) {
$ike_array = snmpwalk_cache_oid($device, 'cikeTunnelEntry', array(), 'CISCO-IPSEC-FLOW-MONITOR-MIB');
}
$tunnels_db = dbFetchRows('SELECT * FROM `ipsec_tunnels` WHERE `device_id` = ?', array($device['device_id']));
foreach ($tunnels_db as $tunnel) {

View File

@@ -2,96 +2,96 @@
use LibreNMS\RRD\RrdDefinition;
// FIXME -- we're walking, so we can discover here too.
if ($device['os_group'] == 'cisco') {
$cip_oids = array(
'cipMacHCSwitchedBytes',
'cipMacHCSwitchedPkts',
);
$cip_array = array();
foreach ($cip_oids as $oid) {
echo "$oid ";
$cip_array = snmpwalk_cache_cip($device, $oid, $cip_array, 'CISCO-IP-STAT-MIB');
}
$polled = time();
$mac_entries = 0;
$acc_rows = dbFetchRows('SELECT *, A.poll_time AS poll_time FROM `mac_accounting` as A, `ports` AS I where A.port_id = I.port_id AND I.device_id = ?', array($device['device_id']));
foreach ($acc_rows as $acc) {
$device_id = $acc['device_id'];
$ifIndex = $acc['ifIndex'];
$mac = $acc['mac'];
if (!empty($acc_rows)) {
$cip_oids = array(
'cipMacHCSwitchedBytes',
'cipMacHCSwitchedPkts',
);
$cip_array = array();
$polled_period = ($polled - $acc['poll_time']);
foreach ($cip_oids as $oid) {
echo "$oid ";
$cip_array = snmpwalk_cache_cip($device, $oid, $cip_array, 'CISCO-IP-STAT-MIB');
}
if ($cip_array[$ifIndex][$mac]) {
$acc['update']['poll_time'] = $polled;
$acc['update']['poll_prev'] = $acc['poll_time'];
$acc['update']['poll_period'] = $polled_period;
$polled = time();
$mac_entries++;
$mac_entries = 0;
$b_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['input'];
$b_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['output'];
$p_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['input'];
$p_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['output'];
foreach ($acc_rows as $acc) {
$device_id = $acc['device_id'];
$ifIndex = $acc['ifIndex'];
$mac = $acc['mac'];
$this_ma = &$cip_array[$ifIndex][$mac];
$polled_period = ($polled - $acc['poll_time']);
// Update metrics
foreach ($cip_oids as $oid) {
foreach (array('input', 'output') as $dir) {
$oid_dir = $oid.'_'.$dir;
$acc['update'][$oid_dir] = $this_ma[$oid][$dir];
$acc['update'][$oid_dir.'_prev'] = $acc[$oid_dir];
$oid_prev = $oid_dir.'_prev';
if ($this_ma[$oid][$dir]) {
$oid_diff = ($this_ma[$oid][$dir] - $acc[$oid_dir]);
$oid_rate = ($oid_diff / $polled_period);
$acc['update'][$oid_dir.'_rate'] = $oid_rate;
$acc['update'][$oid_dir.'_delta'] = $oid_diff;
d_echo("\n $oid_dir ($oid_diff B) $oid_rate Bps $polled_period secs\n");
if ($cip_array[$ifIndex][$mac]) {
$acc['update']['poll_time'] = $polled;
$acc['update']['poll_prev'] = $acc['poll_time'];
$acc['update']['poll_period'] = $polled_period;
$mac_entries++;
$b_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['input'];
$b_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedBytes']['output'];
$p_in = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['input'];
$p_out = $cip_array[$ifIndex][$mac]['cipMacHCSwitchedPkts']['output'];
$this_ma = &$cip_array[$ifIndex][$mac];
// Update metrics
foreach ($cip_oids as $oid) {
foreach (array('input', 'output') as $dir) {
$oid_dir = $oid . '_' . $dir;
$acc['update'][$oid_dir] = $this_ma[$oid][$dir];
$acc['update'][$oid_dir . '_prev'] = $acc[$oid_dir];
$oid_prev = $oid_dir . '_prev';
if ($this_ma[$oid][$dir]) {
$oid_diff = ($this_ma[$oid][$dir] - $acc[$oid_dir]);
$oid_rate = ($oid_diff / $polled_period);
$acc['update'][$oid_dir . '_rate'] = $oid_rate;
$acc['update'][$oid_dir . '_delta'] = $oid_diff;
d_echo("\n $oid_dir ($oid_diff B) $oid_rate Bps $polled_period secs\n");
}
}
}
}
d_echo("\n".$acc['hostname'].' '.$acc['ifDescr']." $mac -> $b_in:$b_out:$p_in:$p_out ");
d_echo("\n" . $acc['hostname'] . ' ' . $acc['ifDescr'] . " $mac -> $b_in:$b_out:$p_in:$p_out ");
$rrd_name = array('cip', $ifIndex, $mac);
$rrd_dev = RrdDefinition::make()
->addDataset('IN', 'COUNTER', 0, 12500000000)
->addDataset('OUT', 'COUNTER', 0, 12500000000)
->addDataset('PIN', 'COUNTER', 0, 12500000000)
->addDataset('POUT', 'COUNTER', 0, 12500000000);
$rrd_name = array('cip', $ifIndex, $mac);
$rrd_dev = RrdDefinition::make()
->addDataset('IN', 'COUNTER', 0, 12500000000)
->addDataset('OUT', 'COUNTER', 0, 12500000000)
->addDataset('PIN', 'COUNTER', 0, 12500000000)
->addDataset('POUT', 'COUNTER', 0, 12500000000);
// FIXME - use memcached to make sure these values don't go backwards?
$fields = array(
'IN' => $b_in,
'OUT' => $b_out,
'PIN' => $p_in,
'POUT' => $p_out,
);
// FIXME - use memcached to make sure these values don't go backwards?
$fields = array(
'IN' => $b_in,
'OUT' => $b_out,
'PIN' => $p_in,
'POUT' => $p_out,
);
$tags = compact('ifIndex', 'mac', 'rrd_name', 'rrd_def');
data_update($device, 'cip', $tags, $fields);
$tags = compact('ifIndex', 'mac', 'rrd_name', 'rrd_def');
data_update($device, 'cip', $tags, $fields);
if ($acc['update']) {
// Do Updates
dbUpdate($acc['update'], 'mac_accounting', '`ma_id` = ?', array($acc['ma_id']));
} //end if
}//end if
}//end foreach
if ($acc['update']) {
// Do Updates
dbUpdate($acc['update'], 'mac_accounting', '`ma_id` = ?', array($acc['ma_id']));
} //end if
}//end if
}//end foreach
unset($cip_array);
unset($cip_array);
if ($mac_entries) {
echo " $mac_entries MAC accounting entries\n";
if ($mac_entries) {
echo " $mac_entries MAC accounting entries\n";
}
}
echo "\n";
}//end if

View File

@@ -5,8 +5,6 @@ use LibreNMS\RRD\RrdDefinition;
echo "Cisco Cat6xxx/76xx Crossbar : \n";
$mod_stats = snmpwalk_cache_oid($device, 'cc6kxbarModuleModeTable', array(), 'CISCO-CAT6K-CROSSBAR-MIB');
$chan_stats = snmpwalk_cache_oid($device, 'cc6kxbarModuleChannelTable', array(), 'CISCO-CAT6K-CROSSBAR-MIB');
$chan_stats = snmpwalk_cache_oid($device, 'cc6kxbarStatisticsTable', $chan_stats, 'CISCO-CAT6K-CROSSBAR-MIB');
foreach ($mod_stats as $index => $entry) {
$group = 'c6kxbar';
@@ -16,6 +14,11 @@ foreach ($mod_stats as $index => $entry) {
}
}
$chan_stats = snmpwalk_cache_oid($device, 'cc6kxbarModuleChannelTable', array(), 'CISCO-CAT6K-CROSSBAR-MIB');
if (!empty($chan_stats)) {
$chan_stats = snmpwalk_cache_oid($device, 'cc6kxbarStatisticsTable', $chan_stats, 'CISCO-CAT6K-CROSSBAR-MIB');
}
foreach ($chan_stats as $index => $entry) {
list($index,$subindex) = explode('.', $index, 2);
$group = 'c6kxbar';

View File

@@ -7,42 +7,44 @@ echo 'MEF Links: ';
*/
$db_info_list = dbFetchRows('SELECT id, mefID, mefType, mefIdent, mefMTU, mefAdmState, mefRowState FROM mefinfo WHERE device_id = ?', array($device['device_id']));
$current_mefinfo = snmpwalk_cache_multi_oid($device, 'MefServiceEvcCfgEntry', array(), 'MEF-UNI-EVC-MIB');
foreach ($db_info_list as $db_info) {
$mef_info = array();
if (!empty($db_info_list)) {
$current_mefinfo = snmpwalk_cache_multi_oid($device, 'MefServiceEvcCfgEntry', array(), 'MEF-UNI-EVC-MIB');
$mef_info['mefType'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgServiceType'];
$mef_info['mefIdent'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgIdentifier'];
$mef_info['mefMTU'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgMtuSize'];
$mef_info['mefAdmState'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgAdminState'];
$mef_info['mefRowState'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgRowStatus'];
foreach ($db_info_list as $db_info) {
$mef_info = array();
/*
* Coriant MEF-EVC is quite strange, MTU is sometime set to 0 so we can set it into 1600 instead
* According to Coriant this should be fixed in Nov 2017
*/
if (($mef_info['mefMTU'] == 0) && ($device['os'] == 'coriant')) {
$mef_info['mefMTU'] = 1600;
}
$mef_info['mefType'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgServiceType'];
$mef_info['mefIdent'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgIdentifier'];
$mef_info['mefMTU'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgMtuSize'];
$mef_info['mefAdmState'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgAdminState'];
$mef_info['mefRowState'] = $current_mefinfo[$db_info['mefID']]['mefServiceEvcCfgRowStatus'];
/*
* Process all the MEF properties.
*/
foreach ($mef_info as $property => $value) {
/*
* Check the property for any modifications.
* Coriant MEF-EVC is quite strange, MTU is sometime set to 0 so we can set it into 1600 instead
* According to Coriant this should be fixed in Nov 2017
*/
if ($mef_info[$property] != $db_info[$property]) {
// FIXME - this should loop building a query and then run the query after the loop (bad geert!)
dbUpdate(array($property => mres($mef_info[$property])), 'mefinfo', '`id` = ?', array($db_info['id']));
if ($db_info['mefIdent'] != null) {
log_event("MEF Link : ".mres($db_info['mefIdent']) . ' (' . preg_replace('/^mef/', '', mres($db_info[$property])) . ') -> ' . $mef_info[$property], $device);
if (($mef_info['mefMTU'] == 0) && ($device['os'] == 'coriant')) {
$mef_info['mefMTU'] = 1600;
}
/*
* Process all the MEF properties.
*/
foreach ($mef_info as $property => $value) {
/*
* Check the property for any modifications.
*/
if ($mef_info[$property] != $db_info[$property]) {
// FIXME - this should loop building a query and then run the query after the loop (bad geert!)
dbUpdate(array($property => mres($mef_info[$property])), 'mefinfo', '`id` = ?', array($db_info['id']));
if ($db_info['mefIdent'] != null) {
log_event("MEF Link : " . mres($db_info['mefIdent']) . ' (' . preg_replace('/^mef/', '', mres($db_info[$property])) . ') -> ' . $mef_info[$property], $device);
}
}
}
}
}//end foreach
}//end foreach
}
/*
* Finished discovering MEF Links information.
*/

View File

@@ -1,3 +1,3 @@
<?php
$version = trim(snmp_get($device, ".1.3.6.1.4.1.5454.1.80.1.1.2.0", "-Oqv"), '"');
$hardware = trim(snmp_get($device, ".1.3.6.1.2.1.1.1.0", "-Oqv"), '"');
$hardware = $poll_device['sysDescr'];