mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
move arp table polling out of cisco mac accounting file, this works on other devices as well - tested on linux/net-snmp and junos
git-svn-id: http://www.observium.org/svn/observer/trunk@678 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -80,6 +80,8 @@ while ($device = mysql_fetch_array($device_query)) {
|
|||||||
## CDP & LLDP
|
## CDP & LLDP
|
||||||
include("includes/discovery/cdp-lldp.inc.php");
|
include("includes/discovery/cdp-lldp.inc.php");
|
||||||
|
|
||||||
|
## ARP Table
|
||||||
|
include("includes/discovery/arp-table.php");
|
||||||
|
|
||||||
if($device['os'] == "netscreen") {
|
if($device['os'] == "netscreen") {
|
||||||
if ($device['type'] == "unknown") { $device['type'] = 'firewall'; }
|
if ($device['type'] == "unknown") { $device['type'] = 'firewall'; }
|
||||||
|
63
includes/discovery/arp-table.php
Normal file
63
includes/discovery/arp-table.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
unset ($mac_table);
|
||||||
|
|
||||||
|
echo("ARP Table : ");
|
||||||
|
|
||||||
|
$ipNetToMedia_data = shell_exec($config['snmpbulkwalk'] . " -m IP-MIB -Oq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." ipNetToMediaPhysAddress");
|
||||||
|
$ipNetToMedia_data = str_replace("ipNetToMediaPhysAddress.", "", trim($ipNetToMedia_data));
|
||||||
|
$ipNetToMedia_data = str_replace("IP-MIB::", "", trim($ipNetToMedia_data));
|
||||||
|
#echo("$ipNetToMedia_data\n");
|
||||||
|
#echo("done\n");
|
||||||
|
foreach(explode("\n", $ipNetToMedia_data) as $data) {
|
||||||
|
list($oid, $mac) = explode(" ", $data);
|
||||||
|
list($if, $first, $second, $third, $fourth) = explode(".", $oid);
|
||||||
|
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(":", $mac);
|
||||||
|
$interface = mysql_fetch_array(mysql_query("SELECT * FROM interfaces WHERE device_id = '".$device['device_id']."' AND ifIndex = '".$if."'"));
|
||||||
|
$ip = $first .".". $second .".". $third .".". $fourth;
|
||||||
|
$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;
|
||||||
|
$interface_id = $interface['interface_id'];
|
||||||
|
$mac_table[$interface_id][$clean_mac] = 1;
|
||||||
|
if(mysql_result(mysql_query("SELECT COUNT(*) from ipv4_mac WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'"),0)) {
|
||||||
|
$sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'";
|
||||||
|
mysql_query($sql);
|
||||||
|
echo(".");
|
||||||
|
} else {
|
||||||
|
echo("+");
|
||||||
|
#echo("Add MAC $mac\n");
|
||||||
|
mysql_query("INSERT INTO `ipv4_mac` (interface_id, mac_address, ipv4_address) VALUES ('".$interface['interface_id']."','$clean_mac','$ip')");
|
||||||
|
}
|
||||||
|
$interface_id = $interface['interface_id'];
|
||||||
|
}
|
||||||
|
$sql = "SELECT * from ipv4_mac AS M, interfaces as I WHERE M.interface_id = I.interface_id and I.device_id = '".$device['device_id']."'";
|
||||||
|
$query = mysql_query($sql);
|
||||||
|
while($entry = mysql_fetch_array($query)) {
|
||||||
|
$entry_mac = $entry['mac_address'];
|
||||||
|
$entry_if = $entry['interface_id'];
|
||||||
|
if(!$mac_table[$entry_if][$entry_mac]) {
|
||||||
|
mysql_query("DELETE FROM ipv4_mac WHERE interface_id = '".$entry_if."' AND mac_address = '".$entry_mac."'");
|
||||||
|
#echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
|
||||||
|
echo("-");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo("\n");
|
||||||
|
|
||||||
|
unset($mac);
|
||||||
|
|
||||||
|
?>
|
@@ -1,66 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
unset ($mac_table);
|
|
||||||
|
|
||||||
echo("ARP Table : ");
|
|
||||||
|
|
||||||
$ipNetToMedia_data = shell_exec($config['snmpbulkwalk'] . " -m IP-MIB -Oq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." ipNetToMediaPhysAddress");
|
|
||||||
$ipNetToMedia_data = str_replace("ipNetToMediaPhysAddress.", "", trim($ipNetToMedia_data));
|
|
||||||
$ipNetToMedia_data = str_replace("IP-MIB::", "", trim($ipNetToMedia_data));
|
|
||||||
#echo("$ipNetToMedia_data\n");
|
|
||||||
#echo("done\n");
|
|
||||||
foreach(explode("\n", $ipNetToMedia_data) as $data) {
|
|
||||||
list($oid, $mac) = explode(" ", $data);
|
|
||||||
list($if, $first, $second, $third, $fourth) = explode(".", $oid);
|
|
||||||
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(":", $mac);
|
|
||||||
$interface = mysql_fetch_array(mysql_query("SELECT * FROM interfaces WHERE device_id = '".$device['device_id']."' AND ifIndex = '".$if."'"));
|
|
||||||
$ip = $first .".". $second .".". $third .".". $fourth;
|
|
||||||
$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;
|
|
||||||
$interface_id = $interface['interface_id'];
|
|
||||||
$mac_table[$interface_id][$clean_mac] = 1;
|
|
||||||
if(mysql_result(mysql_query("SELECT COUNT(*) from ipv4_mac WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'"),0)) {
|
|
||||||
$sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND ipv4_address = '$ip'";
|
|
||||||
mysql_query($sql);
|
|
||||||
echo(".");
|
|
||||||
} else {
|
|
||||||
echo("+");
|
|
||||||
#echo("Add MAC $mac\n");
|
|
||||||
mysql_query("INSERT INTO `ipv4_mac` (interface_id, mac_address, ipv4_address) VALUES ('".$interface['interface_id']."','$clean_mac','$ip')");
|
|
||||||
}
|
|
||||||
$interface_id = $interface['interface_id'];
|
|
||||||
}
|
|
||||||
$sql = "SELECT * from ipv4_mac AS M, interfaces as I WHERE M.interface_id = I.interface_id and I.device_id = '".$device['device_id']."'";
|
|
||||||
$query = mysql_query($sql);
|
|
||||||
while($entry = mysql_fetch_array($query)) {
|
|
||||||
$entry_mac = $entry['mac_address'];
|
|
||||||
$entry_if = $entry['interface_id'];
|
|
||||||
if(!$mac_table[$entry_if][$entry_mac]) {
|
|
||||||
mysql_query("DELETE FROM ipv4_mac WHERE interface_id = '".$entry_if."' AND mac_address = '".$entry_mac."'");
|
|
||||||
#echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
|
|
||||||
echo("-");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo("\n");
|
|
||||||
|
|
||||||
unset($mac);
|
|
||||||
|
|
||||||
echo("MAC Accounting : ");
|
echo("MAC Accounting : ");
|
||||||
|
|
||||||
$datas = shell_exec($config['snmpbulkwalk'] . " -m CISCO-IP-STAT-MIB -Oqn -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." cipMacSwitchedBytes");
|
$datas = shell_exec($config['snmpbulkwalk'] . " -m CISCO-IP-STAT-MIB -Oqn -".$device['snmpver']." -c ".$device['community']." ".$device['hostname']." cipMacSwitchedBytes");
|
||||||
|
Reference in New Issue
Block a user