Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discoverying and polling vrf #Issue280 #2820

Merged
merged 47 commits into from Feb 15, 2016
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
faf2b84
Adding sql-schema
h3n0c Jan 20, 2016
9c0f0d7
Adding mibs
h3n0c Jan 20, 2016
1bf8610
discoverying and polling VRF
h3n0c Jan 20, 2016
2820689
Adding sql-schema
h3n0c Jan 20, 2016
11097f6
Adding mibs
h3n0c Jan 20, 2016
b637ce6
discoverying and polling VRF
h3n0c Jan 20, 2016
1f58058
merging
h3n0c Jan 20, 2016
255eb9c
Adding sql-schema
h3n0c Jan 20, 2016
a7c88be
Adding mibs
h3n0c Jan 20, 2016
831940c
discoverying and polling VRF
h3n0c Jan 20, 2016
286dcdc
Adding sql-schema
h3n0c Jan 20, 2016
5d9c6eb
merging
h3n0c Jan 22, 2016
1a21c51
Syntax update
h3n0c Jan 25, 2016
c801e4b
Adding sql-schema
h3n0c Jan 20, 2016
3c3cf96
Adding mibs
h3n0c Jan 20, 2016
30eb276
discoverying and polling VRF
h3n0c Jan 20, 2016
6a03b7d
Adding sql-schema
h3n0c Jan 20, 2016
b50ca4b
Adding sql-schema
h3n0c Jan 20, 2016
63fa635
Adding sql-schema
h3n0c Jan 20, 2016
674171c
Syntax update
h3n0c Jan 25, 2016
8d466dd
merging
h3n0c Jan 25, 2016
a01fc7c
modify order of cisco-vrf-lite
h3n0c Jan 26, 2016
24231cd
Adding sql-schema
h3n0c Jan 20, 2016
ea5d2c6
Adding mibs
h3n0c Jan 20, 2016
0ac8f58
discoverying and polling VRF
h3n0c Jan 20, 2016
386ed4b
Adding sql-schema
h3n0c Jan 20, 2016
b9f9189
Adding sql-schema
h3n0c Jan 20, 2016
5705791
Adding sql-schema
h3n0c Jan 20, 2016
21d2b45
Syntax update
h3n0c Jan 25, 2016
0b34930
Adding sql-schema
h3n0c Jan 20, 2016
724ad08
discoverying and polling VRF
h3n0c Jan 20, 2016
f3ae90f
Adding sql-schema
h3n0c Jan 20, 2016
990a009
Adding sql-schema
h3n0c Jan 20, 2016
f5fde61
Adding sql-schema
h3n0c Jan 20, 2016
08658e3
Syntax update
h3n0c Jan 25, 2016
e755edf
modify order of cisco-vrf-lite
h3n0c Jan 26, 2016
13aac3f
merging
h3n0c Jan 26, 2016
47c830a
bug correction on ospf polling module
h3n0c Jan 28, 2016
1890cfb
Merge remote-tracking branch 'refs/remotes/librenms/master' into issu…
h3n0c Feb 2, 2016
8a3d14f
Correct data duplication on discovering cisco vrf lite
h3n0c Feb 2, 2016
6de58f5
merging
h3n0c Feb 2, 2016
cfee15f
update Authors
h3n0c Feb 2, 2016
7a00d91
update branch
h3n0c Feb 6, 2016
24df0a0
merging
h3n0c Feb 8, 2016
21e37c2
merging - update schema
h3n0c Feb 10, 2016
6a51746
bug correction
h3n0c Feb 10, 2016
0161260
merging
h3n0c Feb 13, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions includes/common.php
Expand Up @@ -290,6 +290,16 @@ function device_by_id_cache($device_id, $refresh = '0') {
}
else {
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));

//order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time
$vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id));
$device['vrf_lite_cisco'] = array();
if(!empty($vrfs_lite_cisco)){
foreach ($vrfs_lite_cisco as $vrf){
$device['vrf_lite_cisco'][$vrf['context_name']] = $vrf;
}
}

$cache['devices']['id'][$device_id] = $device;
}
return $device;
Expand Down
3 changes: 3 additions & 0 deletions includes/defaults.inc.php
Expand Up @@ -438,6 +438,8 @@ function set_debug($debug) {
// Enable Pseudowires
$config['enable_vrfs'] = 1;
// Enable VRFs
$config['enable_vrf_lite_cisco'] = 1;
// Enable VRF lite cisco
$config['enable_printers'] = 0;
// Enable Printer support
$config['enable_sla'] = 0;
Expand Down Expand Up @@ -734,6 +736,7 @@ function set_debug($debug) {
$config['discovery_modules']['cisco-mac-accounting'] = 1;
$config['discovery_modules']['cisco-pw'] = 1;
$config['discovery_modules']['cisco-vrf'] = 1;
$config['discovery_modules']['cisco-vrf-lite'] = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you align this config item with the others please.

// $config['discovery_modules']['cisco-cef'] = 1;
$config['discovery_modules']['cisco-sla'] = 1;
$config['discovery_modules']['vmware-vminfo'] = 1;
Expand Down
136 changes: 74 additions & 62 deletions includes/discovery/arp-table.inc.php
Expand Up @@ -4,78 +4,90 @@

echo 'ARP Table : ';

$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB');
$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data));
$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data));
if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
}
else{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a space after the else so:

else {

$vrfs_lite_cisco = array(array('context_name'=>null));
}
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name']=$vrf['context_name'];

$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB');
$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data));
$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data));

foreach (explode("\n", $ipNetToMedia_data) as $data) {
list($oid, $mac) = explode(' ', $data);
list($if, $first, $second, $third, $fourth) = explode('.', $oid);
$ip = $first.'.'.$second.'.'.$third.'.'.$fourth;
if ($ip != '...') {
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));
foreach (explode("\n", $ipNetToMedia_data) as $data) {
list($oid, $mac) = explode(' ', $data);
list($if, $first, $second, $third, $fourth) = explode('.', $oid);
$ip = $first.'.'.$second.'.'.$third.'.'.$fourth;
if ($ip != '...') {
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));

list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac);
$m_a = zeropad($m_a);
$m_b = zeropad($m_b);
$m_c = zeropad($m_c);
$m_d = zeropad($m_d);
$m_e = zeropad($m_e);
$m_f = zeropad($m_f);
$md_a = hexdec($m_a);
$md_b = hexdec($m_b);
$md_c = hexdec($m_c);
$md_d = hexdec($m_d);
$md_e = hexdec($m_e);
$md_f = hexdec($m_f);
$mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f";
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac);
$m_a = zeropad($m_a);
$m_b = zeropad($m_b);
$m_c = zeropad($m_c);
$m_d = zeropad($m_d);
$m_e = zeropad($m_e);
$m_f = zeropad($m_f);
$md_a = hexdec($m_a);
$md_b = hexdec($m_b);
$md_c = hexdec($m_c);
$md_d = hexdec($m_d);
$md_e = hexdec($m_e);
$md_f = hexdec($m_f);
$mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f";

$mac_table[$if][$mac]['ip'] = $ip;
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
$port_id = $interface['port_id'];
$mac_table[$port_id][$clean_mac] = 1;
$mac_table[$if][$mac]['ip'] = $ip;
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
$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 = ?', 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=?', array($ip, $interface['port_id']));
if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) {
// 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']);

if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n");
if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n");

log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']);
}
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=?', array($interface['port_id'], $ip));
echo '.';
}
else if (isset($interface['port_id'])) {
echo '+';
// echo("Add MAC $mac\n");
$insert_data = array(
'port_id' => $interface['port_id'],
'mac_address' => $clean_mac,
'ipv4_address' => $ip,
);
dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']));
echo '.';
}
else if (isset($interface['port_id'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this to:

elseif () {

echo '+';
// echo("Add MAC $mac\n");
$insert_data = array(
'port_id' => $interface['port_id'],
'mac_address' => $clean_mac,
'ipv4_address' => $ip,
'context_name' => $device['context_name'],
);

dbInsert($insert_data, 'ipv4_mac');
dbInsert($insert_data, 'ipv4_mac');
}//end if
}//end if
}//end if
}//end foreach
}//end foreach

$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` = ?', array($entry_if, $entry_mac));
d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
$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'] ."'";
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']));
d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']);

echo '-';
echo '-';
}
}
echo "\n";
unset($mac);
unset($device['context_name']);
}

echo "\n";
unset($mac);
unset($vrfs_c);