mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	updates!
git-svn-id: http://www.observium.org/svn/observer/trunk@433 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
		@@ -1,14 +1,27 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
  $sql  = "SELECT * FROM `interfaces` AS I, `devices` AS D";
 | 
			
		||||
  $sql .= " WHERE `ifAlias` like 'Cust: %' AND I.device_id = D.device_id AND D.hostname LIKE '%" . $config['mydomain'] . "' ORDER BY I.ifAlias";
 | 
			
		||||
  $sql .= " WHERE I.ifAlias like 'Cust: %' AND I.device_id = D.device_id  ORDER BY I.ifAlias";
 | 
			
		||||
  $query = mysql_query($sql);
 | 
			
		||||
 | 
			
		||||
  if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; }
 | 
			
		||||
 | 
			
		||||
  echo("<table border=0 cellspacing=0 cellpadding=2 class=devicetable width=100%>");
 | 
			
		||||
 | 
			
		||||
    echo("
 | 
			
		||||
           <tr bgcolor='$list_colour_a'>
 | 
			
		||||
             <th width='7'></th>
 | 
			
		||||
             <th width='250'><span style='font-weight: bold;' class=interface>Customer</span></th>
 | 
			
		||||
             <th width='150'>Device</th>
 | 
			
		||||
             <th width='100'>Interface</th>
 | 
			
		||||
             <th width='100'>Speed</th>
 | 
			
		||||
             <th width='100'>Circuit</th>
 | 
			
		||||
             <th>Notes</th>
 | 
			
		||||
           </tr>
 | 
			
		||||
         ");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  $customers = 1;
 | 
			
		||||
  while($interface = mysql_fetch_array($query)) {
 | 
			
		||||
    $device    = &$interface;
 | 
			
		||||
 | 
			
		||||
@@ -16,26 +29,21 @@
 | 
			
		||||
 | 
			
		||||
    $ifname = fixifname($device['ifDescr']);
 | 
			
		||||
 | 
			
		||||
    $interface['ifAlias'] = str_replace("Cust: ", "", $interface['ifAlias']);
 | 
			
		||||
    $interface['ifAlias'] = str_replace("[PNI]", "Private", $interface['ifAlias']);
 | 
			
		||||
 | 
			
		||||
    $ifclass = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
 | 
			
		||||
 | 
			
		||||
    $displayifalias = $device['ifAlias'];
 | 
			
		||||
    $device['ifAlias'] = str_replace(" [","|",$device['ifAlias']);
 | 
			
		||||
    $device['ifAlias'] = str_replace("] (","|",$device['ifAlias']);
 | 
			
		||||
    $device['ifAlias'] = str_replace(" (","||",$device['ifAlias']);
 | 
			
		||||
    $device['ifAlias'] = str_replace("]","|",$device['ifAlias']);
 | 
			
		||||
    $device['ifAlias'] = str_replace(")","|",$device['ifAlias']);
 | 
			
		||||
    list($device['ifAlias'],$class,$notes) = explode("|", $device['ifAlias']);
 | 
			
		||||
    $useifalias = $device['ifAlias'];
 | 
			
		||||
    $used = '1';
 | 
			
		||||
    if ($device['ifAlias'] == $previfalias) { unset($useifalias );
 | 
			
		||||
    } elseif ($previfalias) { 
 | 
			
		||||
     echo("<tr bgcolor='#ffffff' height='5'><td></td></tr>"); 
 | 
			
		||||
     if($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg="#ffffff"; }
 | 
			
		||||
    list(,$customer) = preg_split("/[\:\[\]\{\}\(\)]/", $interface['ifAlias']);  
 | 
			
		||||
    list(,$circuit) = preg_split("/[\{\}]/", $interface['ifAlias']);
 | 
			
		||||
    list(,$notes) = preg_split("/[\(\)]/", $interface['ifAlias']);
 | 
			
		||||
    list(,$speed) = preg_split("/[\[\]]/", $interface['ifAlias']);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if ($customer == $prev_customer) { 
 | 
			
		||||
      unset($customer);
 | 
			
		||||
    } else { 
 | 
			
		||||
     if(is_integer($customers/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; }
 | 
			
		||||
     $customers++;
 | 
			
		||||
     $prev_customer = $customer;
 | 
			
		||||
    }
 | 
			
		||||
    $previfalias = $device['ifAlias'];
 | 
			
		||||
 | 
			
		||||
    if($device['os'] == "IOS") {
 | 
			
		||||
 | 
			
		||||
@@ -46,12 +54,13 @@
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    echo("
 | 
			
		||||
           <tr bgcolor='$bg'>
 | 
			
		||||
           <tr bgcolor='$bg_colour'>
 | 
			
		||||
             <td width='7'></td>
 | 
			
		||||
             <td width='250'><span style='font-weight: bold;' class=interface>$useifalias</span></td>
 | 
			
		||||
             <td width='200'>" . generatedevicelink($device) . "</td>
 | 
			
		||||
             <td width='250'><span style='font-weight: bold;' class=interface>$customer</span></td>
 | 
			
		||||
             <td width='150'>" . generatedevicelink($device) . "</td>
 | 
			
		||||
             <td width='100'>" . generateiflink($interface, makeshortif($interface['ifDescr'])) . "</td>
 | 
			
		||||
             <td width='100'>$vlan</td>
 | 
			
		||||
             <td width='100'>$speed</td>
 | 
			
		||||
             <td width='100'>$circuit</td>
 | 
			
		||||
             <td>$notes</td>
 | 
			
		||||
           </tr>
 | 
			
		||||
         ");
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										76
									
								
								includes/discovery/cisco-mac-accounting.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										76
									
								
								includes/discovery/cisco-mac-accounting.php
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
<?
 | 
			
		||||
 | 
			
		||||
  unset ($mac_table);
 | 
			
		||||
 | 
			
		||||
  $ipNetToMedia_data = shell_exec($config['snmpbulkwalk'] . " -m IP-MIB -Oq -".$device['snmpver']." -c ".$config['community']." ".$device['hostname']." ipNetToMediaPhysAddress");
 | 
			
		||||
  $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);
 | 
			
		||||
    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;
 | 
			
		||||
    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);
 | 
			
		||||
    } else {
 | 
			
		||||
      #echo("Add MAC $mac\n");
 | 
			
		||||
      mysql_query("INSERT INTO `ipv4_mac` (interface_id, mac_address, ipv4_address) VALUES ('".$interface['interface_id']."','$clean_mac','$ip')");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $datas = shell_exec($config['snmpbulkwalk'] . " -m CISCO-IP-STAT-MIB -Oqn -".$device['snmpver']." -c ".$config['community']." ".$device['hostname']." cipMacSwitchedBytes");
 | 
			
		||||
  $datas = trim($datas);
 | 
			
		||||
  foreach(explode("\n", $datas) as $data) {
 | 
			
		||||
    list($oid) = explode(" ", $data);
 | 
			
		||||
    $oid = str_replace(".1.3.6.1.4.1.9.9.84.1.2.1.1.4.", "", $oid);
 | 
			
		||||
    list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $oid);
 | 
			
		||||
    $oid = "$a_a.$a_b.$a_c.$a_d.$a_e.$a_f";
 | 
			
		||||
    unset($interface);
 | 
			
		||||
    $interface = mysql_fetch_array(mysql_query("SELECT * FROM interfaces WHERE device_id = '".$device['device_id']."' AND ifIndex = '".$if."'"));
 | 
			
		||||
    $ah_a = zeropad(dechex($a_a));
 | 
			
		||||
    $ah_b = zeropad(dechex($a_b));
 | 
			
		||||
    $ah_c = zeropad(dechex($a_c));
 | 
			
		||||
    $ah_d = zeropad(dechex($a_d));
 | 
			
		||||
    $ah_e = zeropad(dechex($a_e));
 | 
			
		||||
    $ah_f = zeropad(dechex($a_f));
 | 
			
		||||
    $mac = "$ah_a:$ah_b:$ah_c:$ah_d:$ah_e:$ah_f";
 | 
			
		||||
    $mac_cisco = "$ah_a$ah_b.$ah_c$ah_d.$ah_e$ah_f";
 | 
			
		||||
    $mac_cisco = $mac_table[$if][$mac]['ciscomac'];
 | 
			
		||||
    $clean_mac = $mac_table[$if][$mac]['cleanmac'];
 | 
			
		||||
    $ip = $mac_table[$if][$mac]['ip'];
 | 
			
		||||
    if($ip && $interface) {
 | 
			
		||||
      $new_mac = str_replace(":", "", $mac);
 | 
			
		||||
      echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip -> $name");
 | 
			
		||||
      if(mysql_result(mysql_query("SELECT COUNT(*) from mac_accounting WHERE interface_id = '".$interface['interface_id']."' AND mac = '$clean_mac'"),0)) {
 | 
			
		||||
        #$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND `mac` = '$clean_mac'";
 | 
			
		||||
        #mysql_query($sql);
 | 
			
		||||
        #if(mysql_affected_rows()) { echo("      UPDATED!"); }
 | 
			
		||||
        #echo($sql);
 | 
			
		||||
      } else {
 | 
			
		||||
        #echo("      Not Exists!");
 | 
			
		||||
        mysql_query("INSERT INTO `mac_accounting` (interface_id,  mac) VALUES ('".$interface['interface_id']."','$clean_mac')");
 | 
			
		||||
      }      
 | 
			
		||||
      echo("\n");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
		Reference in New Issue
	
	Block a user