mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Correct data duplication on discovering cisco vrf lite
This commit is contained in:
@@ -47,10 +47,10 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$port_id = $interface['port_id'];
|
||||
$mac_table[$port_id][$clean_mac] = 1;
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) {
|
||||
if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) {
|
||||
// Commented below, no longer needed but leaving for reference.
|
||||
// $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
|
||||
$old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']);
|
||||
$old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=?', array($ip, $interface['port_id']));
|
||||
|
||||
if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
|
||||
d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n");
|
||||
@@ -58,7 +58,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']);
|
||||
}
|
||||
|
||||
dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']));
|
||||
dbUpdate(array('mac_address' => $clean_mac, 'context_name' => $device['context_name']), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip));
|
||||
echo '.';
|
||||
}
|
||||
elseif (isset($interface['port_id'])) {
|
||||
@@ -75,12 +75,12 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = ' AND `context_name`= ?".$device['device_id']." AND M.context_name='". $device['context_name'] ."'";
|
||||
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'";
|
||||
foreach (dbFetchRows($sql) as $entry) {
|
||||
$entry_mac = $entry['mac_address'];
|
||||
$entry_if = $entry['port_id'];
|
||||
if (!$mac_table[$entry_if][$entry_mac]) {
|
||||
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name']));
|
||||
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac));
|
||||
d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
|
||||
|
||||
echo '-';
|
||||
|
@@ -6,8 +6,7 @@ if ($config['enable_bgp']) {
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$vrfs_lite_cisco = array(array('context_name' => null));
|
||||
}
|
||||
|
||||
@@ -28,8 +27,7 @@ if ($config['enable_bgp']) {
|
||||
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']);
|
||||
if (empty($peers_data)) {
|
||||
$peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$peer2 = true;
|
||||
}
|
||||
|
||||
@@ -83,8 +81,7 @@ if ($config['enable_bgp']) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo 'No BGP on host';
|
||||
if ($device['bgpLocalAs']) {
|
||||
dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id']));
|
||||
@@ -97,7 +94,8 @@ if ($config['enable_bgp']) {
|
||||
foreach ($peerlist as $peer) {
|
||||
$astext = get_astext($peer['as']);
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $device['context_name'])) < '1') {
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
|
||||
|
||||
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'], 'context_name' => $device['context_name']), 'bgpPeers');
|
||||
if ($config['autodiscovery']['bgp'] === true) {
|
||||
$name = gethostbyaddr($peer['ip']);
|
||||
@@ -105,9 +103,8 @@ if ($config['enable_bgp']) {
|
||||
}
|
||||
|
||||
echo '+';
|
||||
}
|
||||
else {
|
||||
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
|
||||
} else {
|
||||
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext), 'context_name' => $device['context_name']), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
|
||||
echo '.';
|
||||
}
|
||||
|
||||
@@ -118,8 +115,7 @@ if ($config['enable_bgp']) {
|
||||
|
||||
if ($peer2 === true) {
|
||||
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
|
||||
}
|
||||
|
||||
@@ -142,9 +138,13 @@ if ($config['enable_bgp']) {
|
||||
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
|
||||
if ($afi && $safi && $bgp_ip == $peer['ip']) {
|
||||
$af_list[$bgp_ip][$afi][$safi] = 1;
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=? AND `context_name`=?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])) == 0) {
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp');
|
||||
}
|
||||
else {
|
||||
//Update Context
|
||||
dbUpdate(array('context_name' => $device['context_name']), 'bgpPeers_cbgp', 'device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,12 +199,12 @@ if ($config['enable_bgp']) {
|
||||
}
|
||||
}
|
||||
|
||||
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'";
|
||||
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '" . $device['device_id'] . "' AND bgpPeerIdentifier = '" . $peer['ip'] . "'";
|
||||
foreach (dbFetchRows($af_query) as $entry) {
|
||||
$afi = $entry['afi'];
|
||||
$safi = $entry['safi'];
|
||||
if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
|
||||
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name']));
|
||||
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,14 +12,12 @@
|
||||
* See COPYING for more details.
|
||||
*/
|
||||
|
||||
|
||||
function discover_new_device($hostname, $device = '', $method = '', $interface = '') {
|
||||
global $config;
|
||||
|
||||
if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) {
|
||||
$dst_host = $hostname . '.' . $config['mydomain'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$dst_host = $hostname;
|
||||
}
|
||||
|
||||
@@ -33,8 +31,7 @@ function discover_new_device($hostname, $device='', $method='', $interface='') {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true){
|
||||
} elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true) {
|
||||
// gethostbyname returned a valid $ip, was $dst_host an IP?
|
||||
if ($config['discovery_by_ip'] === false) {
|
||||
d_echo('Discovery by IP disabled, skipping ' . $dst_host);
|
||||
@@ -67,20 +64,18 @@ function discover_new_device($hostname, $device='', $method='', $interface='') {
|
||||
}
|
||||
|
||||
log_event('Device $' . $remote_device['hostname'] . " ($ip) $extra_log autodiscovered through $method on " . $device['hostname'], $remote_device_id, 'discovery');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log_event("$method discovery of " . $remote_device['hostname'] . " ($ip) failed - check ping and SNMP access", $device['device_id'], 'discovery');
|
||||
}
|
||||
|
||||
return $remote_device_id;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
d_echo("$ip not in a matched network - skipping\n");
|
||||
}//end if
|
||||
}
|
||||
|
||||
}//end discover_new_device()
|
||||
|
||||
//end discover_new_device()
|
||||
|
||||
function discover_device($device, $options = null) {
|
||||
global $config, $valid;
|
||||
@@ -116,19 +111,16 @@ function discover_device($device, $options=null) {
|
||||
include "includes/discovery/$module.inc.php";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
foreach ($config['discovery_modules'] as $module => $module_status) {
|
||||
if ($attribs['discover_' . $module] || ( $module_status && !isset($attribs['discover_' . $module]))) {
|
||||
$module_start = microtime(true);
|
||||
include 'includes/discovery/' . $module . '.inc.php';
|
||||
$module_time = microtime(true) - $module_start;
|
||||
echo "Runtime for discovery module '$module': $module_time\n";
|
||||
}
|
||||
else if (isset($attribs['discover_'.$module]) && $attribs['discover_'.$module] == '0') {
|
||||
} else if (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == '0') {
|
||||
echo "Module [ $module ] disabled on host.\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo "Module [ $module ] disabled globally.\n";
|
||||
}
|
||||
}
|
||||
@@ -158,10 +150,9 @@ function discover_device($device, $options=null) {
|
||||
|
||||
echo "\n";
|
||||
$discovered_devices++;
|
||||
}
|
||||
|
||||
}//end discover_device()
|
||||
|
||||
|
||||
//end discover_device()
|
||||
// Discover sensors
|
||||
|
||||
|
||||
@@ -174,8 +165,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
// Warn limits only make sense when we have both a high and a low limit
|
||||
$low_warn_limit = null;
|
||||
$warn_limit = null;
|
||||
}
|
||||
else if ($low_warn_limit > $warn_limit) {
|
||||
} else if ($low_warn_limit > $warn_limit) {
|
||||
// Fix high/low thresholds (i.e. on negative numbers)
|
||||
list($warn_limit, $low_warn_limit) = array($low_warn_limit, $warn_limit);
|
||||
}
|
||||
@@ -225,16 +215,14 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
|
||||
echo '+';
|
||||
log_event('Sensor Added: ' . mres($class) . ' ' . mres($type) . ' ' . mres($index) . ' ' . mres($descr), $device, 'sensor', $inserted);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$sensor_entry = dbFetchRow('SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `sensor_type` = ? AND `sensor_index` = ?', array($class, $device['device_id'], $type, $index));
|
||||
|
||||
if (!isset($high_limit)) {
|
||||
if (!$sensor_entry['sensor_limit']) {
|
||||
// Calculate a reasonable limit
|
||||
$high_limit = sensor_limit($class, $current);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Use existing limit
|
||||
$high_limit = $sensor_entry['sensor_limit'];
|
||||
}
|
||||
@@ -244,8 +232,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
if (!$sensor_entry['sensor_limit_low']) {
|
||||
// Calculate a reasonable limit
|
||||
$low_limit = sensor_low_limit($class, $current);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Use existing limit
|
||||
$low_limit = $sensor_entry['sensor_limit_low'];
|
||||
}
|
||||
@@ -294,8 +281,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
|
||||
if ($oid == $sensor_entry['sensor_oid'] && $descr == $sensor_entry['sensor_descr'] && $multiplier == $sensor_entry['sensor_multiplier'] && $divisor == $sensor_entry['sensor_divisor'] && $entPhysicalIndex_measured == $sensor_entry['entPhysicalIndex_measured'] && $entPhysicalIndex == $sensor_entry['entPhysicalIndex']) {
|
||||
echo '.';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$update = array(
|
||||
'sensor_oid' => $oid,
|
||||
'sensor_descr' => $descr,
|
||||
@@ -311,9 +297,9 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
}
|
||||
}//end if
|
||||
$valid[$class][$type][$index] = 1;
|
||||
}
|
||||
|
||||
}//end discover_sensor()
|
||||
|
||||
//end discover_sensor()
|
||||
|
||||
function sensor_low_limit($class, $current) {
|
||||
$limit = null;
|
||||
@@ -326,8 +312,7 @@ function sensor_low_limit($class, $current) {
|
||||
case 'voltage':
|
||||
if ($current < 0) {
|
||||
$limit = ($current * (1 + (sgn($current) * 0.15)));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$limit = ($current * (1 - (sgn($current) * 0.15)));
|
||||
}
|
||||
break;
|
||||
@@ -354,9 +339,9 @@ function sensor_low_limit($class, $current) {
|
||||
}//end switch
|
||||
|
||||
return $limit;
|
||||
}
|
||||
|
||||
}//end sensor_low_limit()
|
||||
|
||||
//end sensor_low_limit()
|
||||
|
||||
function sensor_limit($class, $current) {
|
||||
$limit = null;
|
||||
@@ -369,8 +354,7 @@ function sensor_limit($class, $current) {
|
||||
case 'voltage':
|
||||
if ($current < 0) {
|
||||
$limit = ($current * (1 - (sgn($current) * 0.15)));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$limit = ($current * (1 + (sgn($current) * 0.15)));
|
||||
}
|
||||
break;
|
||||
@@ -397,9 +381,9 @@ function sensor_limit($class, $current) {
|
||||
}//end switch
|
||||
|
||||
return $limit;
|
||||
}
|
||||
|
||||
}//end sensor_limit()
|
||||
|
||||
//end sensor_limit()
|
||||
|
||||
function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') {
|
||||
$entries = dbFetchRows('SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?', array($class, $device['device_id'], $poller_type));
|
||||
@@ -420,9 +404,9 @@ function check_valid_sensors($device, $class, $valid, $poller_type='snmp') {
|
||||
unset($type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}//end check_valid_sensors()
|
||||
|
||||
//end check_valid_sensors()
|
||||
|
||||
function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) {
|
||||
global $config;
|
||||
@@ -433,15 +417,14 @@ function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) {
|
||||
|
||||
// FIXME vv no $device!
|
||||
log_event('Juniper ATM VP Added: port ' . mres($port_id) . ' vp ' . mres($vp_id) . ' descr' . mres($vp_descr), 'juniAtmVp', $inserted);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '.';
|
||||
}
|
||||
|
||||
$valid[$port_id][$vp_id] = 1;
|
||||
}
|
||||
|
||||
}//end discover_juniAtmVp()
|
||||
|
||||
//end discover_juniAtmVp()
|
||||
|
||||
function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version, $local_device_id, $remote_device_id) {
|
||||
global $config, $link_exists;
|
||||
@@ -449,8 +432,7 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
|
||||
d_echo("$local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version");
|
||||
|
||||
if (dbFetchCell(
|
||||
'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?',
|
||||
array(
|
||||
'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?', array(
|
||||
$remote_hostname,
|
||||
$local_port_id,
|
||||
$protocol,
|
||||
@@ -476,13 +458,11 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
|
||||
|
||||
echo '+';
|
||||
d_echo("( $inserted inserted )");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$data = dbFetchRow('SELECT * FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?', array($remote_hostname, $local_port_id, $protocol, $remote_port));
|
||||
if ($data['remote_port_id'] == $remote_port_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version && $data['local_device_id'] > 0 && $data['remote_device_id'] > 0) {
|
||||
echo '.';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$update_data = array(
|
||||
'remote_platform' => $remote_platform,
|
||||
'remote_version' => $remote_version,
|
||||
@@ -501,9 +481,9 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn
|
||||
}//end if
|
||||
}//end if
|
||||
$link_exists[$local_port_id][$remote_hostname][$remote_port] = 1;
|
||||
}
|
||||
|
||||
}//end discover_link()
|
||||
|
||||
//end discover_link()
|
||||
|
||||
function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $units, $used = null) {
|
||||
global $config;
|
||||
@@ -523,27 +503,24 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size,
|
||||
'storage_units' => $units,
|
||||
'storage_size' => $size,
|
||||
'storage_used' => $used,
|
||||
),
|
||||
'storage'
|
||||
), 'storage'
|
||||
);
|
||||
|
||||
echo '+';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$updated = dbUpdate(array('storage_descr' => $descr, 'storage_type' => $type, 'storage_units' => $units, 'storage_size' => $size), 'storage', '`device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?', array($device['device_id'], $index, $mib));
|
||||
if ($updated) {
|
||||
echo 'U';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '.';
|
||||
}
|
||||
}//end if
|
||||
|
||||
$valid[$mib][$index] = 1;
|
||||
}//end if
|
||||
}
|
||||
|
||||
}//end discover_storage()
|
||||
|
||||
//end discover_storage()
|
||||
|
||||
function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision = '1', $current = null, $entPhysicalIndex = null, $hrDeviceIndex = null) {
|
||||
global $config;
|
||||
@@ -573,8 +550,7 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec
|
||||
$inserted = dbInsert($insert_data, 'processors');
|
||||
echo '+';
|
||||
log_event('Processor added: type ' . mres($type) . ' index ' . mres($index) . ' descr ' . mres($descr), $device, 'processor', $inserted);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '.';
|
||||
$update_data = array(
|
||||
'processor_descr' => $descr,
|
||||
@@ -586,9 +562,9 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec
|
||||
}//end if
|
||||
$valid[$type][$index] = 1;
|
||||
}//end if
|
||||
}
|
||||
|
||||
}//end discover_processor()
|
||||
|
||||
//end discover_processor()
|
||||
|
||||
function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = '1', $entPhysicalIndex = null, $hrDeviceIndex = null) {
|
||||
global $config;
|
||||
@@ -621,8 +597,7 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision='1
|
||||
$inserted = dbInsert($insert_data, 'mempools');
|
||||
echo '+';
|
||||
log_event('Memory pool added: type ' . mres($type) . ' index ' . mres($index) . ' descr ' . mres($descr), $device, 'mempool', $inserted);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '.';
|
||||
$update_data = array(
|
||||
'mempool_descr' => $descr,
|
||||
@@ -640,9 +615,9 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision='1
|
||||
}//end if
|
||||
$valid[$type][$index] = 1;
|
||||
}//end if
|
||||
}
|
||||
|
||||
}//end discover_mempool()
|
||||
|
||||
//end discover_mempool()
|
||||
|
||||
function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity_oid = null, $capacity = null, $current = null) {
|
||||
global $config;
|
||||
@@ -653,22 +628,20 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity
|
||||
$inserted = dbInsert(array('device_id' => $device['device_id'], 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_index' => $index, 'toner_type' => $type, 'toner_descr' => $descr, 'toner_capacity' => $capacity, 'toner_current' => $current), 'toner');
|
||||
echo '+';
|
||||
log_event('Toner added: type ' . mres($type) . ' index ' . mres($index) . ' descr ' . mres($descr), $device, 'toner', $inserted);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$toner_entry = dbFetchRow('SELECT * FROM `toner` WHERE `device_id` = ? AND `toner_type` = ? AND `toner_index` =?', array($device['device_id'], $type, $index));
|
||||
if ($oid == $toner_entry['toner_oid'] && $descr == $toner_entry['toner_descr'] && $capacity == $toner_entry['toner_capacity'] && $capacity_oid == $toner_entry['toner_capacity_oid']) {
|
||||
echo '.';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dbUpdate(array('toner_descr' => $descr, 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_capacity' => $capacity), 'toner', 'device_id=? AND toner_type=? AND `toner_index`=?', array($device['device_id'], $type, $index));
|
||||
echo 'U';
|
||||
}
|
||||
}
|
||||
|
||||
$valid[$type][$index] = 1;
|
||||
}
|
||||
|
||||
}//end discover_toner()
|
||||
|
||||
//end discover_toner()
|
||||
|
||||
function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name = '') {
|
||||
global $device, $config;
|
||||
@@ -683,24 +656,25 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
|
||||
$port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex));
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') {
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') {
|
||||
dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks');
|
||||
echo 'N';
|
||||
} else {
|
||||
//Update Context
|
||||
dbUpdate(array('context_name' => $device['context_name']), 'ipv6_network', '`ipv6_network` = ?', array($ipv6_network));
|
||||
echo 'n';
|
||||
}
|
||||
|
||||
// Below looks like a duplicate of the above FIXME
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') {
|
||||
dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks');
|
||||
echo 'N';
|
||||
}
|
||||
|
||||
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name));
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `context_name` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
|
||||
dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses');
|
||||
echo '+';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//Update Context
|
||||
dbUpdate(array('context_name' => $device['context_name']), 'ipv6_address', '`ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id));
|
||||
echo '.';
|
||||
}
|
||||
|
||||
@@ -708,5 +682,6 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
|
||||
$valid_address = $full_address . '-' . $port_id;
|
||||
$valid['ipv6'][$valid_address] = 1;
|
||||
}//end if
|
||||
}
|
||||
|
||||
}//end discover_process_ipv6()
|
||||
//end discover_process_ipv6()
|
||||
|
@@ -23,20 +23,27 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') {
|
||||
$port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex));
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name` = ?', array($network, $device['context_name'])) < '1') {
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') {
|
||||
dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks');
|
||||
// echo("Create Subnet $network\n");
|
||||
echo 'S';
|
||||
}
|
||||
else {
|
||||
//Update Context
|
||||
dbUpdate(array('context_name' => $device['context_name']), 'ipv4_networks', '`ipv4_network` = ?', array($network) );
|
||||
echo 's';
|
||||
}
|
||||
|
||||
$ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name']));
|
||||
$ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network));
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? and `context_name`=?', array($oid, $cidr, $port_id, $device['context_name'])) == '0') {
|
||||
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? ', array($oid, $cidr, $port_id)) == '0') {
|
||||
dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id, 'context_name' => $device['context_name']), 'ipv4_addresses');
|
||||
// echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n");
|
||||
echo '+';
|
||||
}
|
||||
else {
|
||||
//Update Context
|
||||
dbUpdate(array('context_name' => $device['context_name']), 'ipv4_addresses', 'ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?',array($oid, $cidr, $port_id) );
|
||||
echo '.';
|
||||
}
|
||||
|
||||
@@ -48,7 +55,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND a.context_name= '" . $device['context_name'] . "'";
|
||||
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id";
|
||||
foreach (dbFetchRows($sql) as $row) {
|
||||
$full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex'];
|
||||
|
||||
|
@@ -68,7 +68,7 @@ foreach ($vrfs_lite_cisco as $vrf) {
|
||||
} //end foreach
|
||||
} //end if
|
||||
|
||||
$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND A.context_name= '" . $device['context_name'] . "'";
|
||||
$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id'";
|
||||
|
||||
foreach (dbFetchRows($sql) as $row) {
|
||||
$full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen'];
|
||||
|
Reference in New Issue
Block a user