mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	code and formatting cleanups/small fixes
git-svn-id: http://www.observium.org/svn/observer/trunk@1771 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
		@@ -17,68 +17,86 @@ if($device['os_group'] == "ios" || $device['os_group'] == "junos" || $device['os
 | 
			
		||||
  $oids = str_replace("\"", "", $oids);
 | 
			
		||||
 | 
			
		||||
  $oids = trim($oids);
 | 
			
		||||
  foreach ( explode("\n", $oids) as $oid ) {
 | 
			
		||||
   if($oid) {
 | 
			
		||||
    list($vrf['oid'], $vrf['mplsVpnVrfRouteDistinguisher']) = explode("||", $oid);
 | 
			
		||||
    $vrf['name'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher.".$vrf['oid']));
 | 
			
		||||
    list(,$vrf['name'],, $vrf['mplsVpnVrfRouteDistinguisher']) = explode("\"", $vrf['name']);
 | 
			
		||||
    $vrf['mplsVpnVrfDescription'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfDescription.".$vrf['oid']));
 | 
			
		||||
  foreach ( explode("\n", $oids) as $oid ) 
 | 
			
		||||
  {
 | 
			
		||||
    if($oid) 
 | 
			
		||||
    {
 | 
			
		||||
      list($vrf['oid'], $vrf['mplsVpnVrfRouteDistinguisher']) = explode("||", $oid);
 | 
			
		||||
      $vrf['name'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher.".$vrf['oid']));
 | 
			
		||||
      list(,$vrf['name'],, $vrf['mplsVpnVrfRouteDistinguisher']) = explode("\"", $vrf['name']);
 | 
			
		||||
      $vrf['mplsVpnVrfDescription'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfDescription.".$vrf['oid']));
 | 
			
		||||
 | 
			
		||||
    if(@mysql_result(mysql_query("SELECT count(*) FROM vrfs WHERE `device_id` = '".$device['device_id']."'
 | 
			
		||||
                                 AND `vrf_oid`='".$vrf['oid']."'"),0)) {
 | 
			
		||||
      $update_query  = "UPDATE `vrfs` SET `mplsVpnVrfDescription` = '".$vrf['mplsVpnVrfDescription']."', `mplsVpnVrfRouteDistinguisher` = '".$vrf['mplsVpnVrfRouteDistinguisher']."' ";
 | 
			
		||||
      $update_query .= "WHERE device_id = '".$device['device_id']."' AND vrf_oid = '".$vrf['oid']."'"; 
 | 
			
		||||
      mysql_query($update_query);
 | 
			
		||||
    } else {
 | 
			
		||||
      $insert_query  = "INSERT INTO `vrfs` (`vrf_oid`,`vrf_name`,`mplsVpnVrfRouteDistinguisher`,`mplsVpnVrfDescription`,`device_id`) ";
 | 
			
		||||
      $insert_query .= "VALUES ('".$vrf['oid']."','".$vrf['name']."','".$vrf['mplsVpnVrfRouteDistinguisher']."','".$vrf['mplsVpnVrfDescription']."','".$device['device_id']."')";
 | 
			
		||||
      mysql_query($insert_query);
 | 
			
		||||
    }
 | 
			
		||||
    $vrf_id = @mysql_result(mysql_query("SELECT vrf_id FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='".$vrf['oid']."'"),0);
 | 
			
		||||
    $valid_vrf[$vrf_id] = 1;
 | 
			
		||||
    echo("\nRD:".$vrf['mplsVpnVrfRouteDistinguisher']." ".$vrf['name']." ".$vrf['mplsVpnVrfDescription']." ");
 | 
			
		||||
    $ports_oid = ".1.3.6.1.3.118.1.2.1.1.2." . $vrf['oid'];
 | 
			
		||||
    $ports = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $ports_oid");
 | 
			
		||||
    $ports = trim(str_replace($ports_oid . ".", "", $ports));
 | 
			
		||||
      if(@mysql_result(mysql_query("SELECT count(*) FROM vrfs WHERE `device_id` = '".$device['device_id']."'
 | 
			
		||||
                                 AND `vrf_oid`='".$vrf['oid']."'"),0))
 | 
			
		||||
      {
 | 
			
		||||
        $update_query  = "UPDATE `vrfs` SET `mplsVpnVrfDescription` = '".$vrf['mplsVpnVrfDescription']."', `mplsVpnVrfRouteDistinguisher` = '".$vrf['mplsVpnVrfRouteDistinguisher']."' ";
 | 
			
		||||
        $update_query .= "WHERE device_id = '".$device['device_id']."' AND vrf_oid = '".$vrf['oid']."'"; 
 | 
			
		||||
        mysql_query($update_query);
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        $insert_query  = "INSERT INTO `vrfs` (`vrf_oid`,`vrf_name`,`mplsVpnVrfRouteDistinguisher`,`mplsVpnVrfDescription`,`device_id`) ";
 | 
			
		||||
        $insert_query .= "VALUES ('".$vrf['oid']."','".$vrf['name']."','".$vrf['mplsVpnVrfRouteDistinguisher']."','".$vrf['mplsVpnVrfDescription']."','".$device['device_id']."')";
 | 
			
		||||
        mysql_query($insert_query);
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      $vrf_id = @mysql_result(mysql_query("SELECT vrf_id FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='".$vrf['oid']."'"),0);
 | 
			
		||||
      $valid_vrf[$vrf_id] = 1;
 | 
			
		||||
      echo("\nRD:".$vrf['mplsVpnVrfRouteDistinguisher']." ".$vrf['name']." ".$vrf['mplsVpnVrfDescription']." ");
 | 
			
		||||
      $ports_oid = ".1.3.6.1.3.118.1.2.1.1.2." . $vrf['oid'];
 | 
			
		||||
      $ports = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $ports_oid");
 | 
			
		||||
      $ports = trim(str_replace($ports_oid . ".", "", $ports));
 | 
			
		||||
#    list($ports) = explode(" ", $ports);
 | 
			
		||||
    echo(" ( ");
 | 
			
		||||
    foreach (explode("\n", $ports) as $if_id) {
 | 
			
		||||
      $interface = mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE ifIndex = '$if_id' AND device_id = '" . $device['device_id'] . "'"));
 | 
			
		||||
      echo(makeshortif($interface['ifDescr']) . " ");
 | 
			
		||||
      mysql_query("UPDATE ports SET ifVrf = '".$vrf_id."' WHERE interface_id = '".$interface['interface_id']."'");
 | 
			
		||||
      $if = $interface['interface_id'];
 | 
			
		||||
      $valid_vrf_if[$vrf_id][$if] = 1;
 | 
			
		||||
      echo(" ( ");
 | 
			
		||||
      foreach (explode("\n", $ports) as $if_id)
 | 
			
		||||
      {
 | 
			
		||||
        $interface = mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE ifIndex = '$if_id' AND device_id = '" . $device['device_id'] . "'"));
 | 
			
		||||
        echo(makeshortif($interface['ifDescr']) . " ");
 | 
			
		||||
        mysql_query("UPDATE ports SET ifVrf = '".$vrf_id."' WHERE interface_id = '".$interface['interface_id']."'");
 | 
			
		||||
        $if = $interface['interface_id'];
 | 
			
		||||
        $valid_vrf_if[$vrf_id][$if] = 1;
 | 
			
		||||
      }
 | 
			
		||||
      echo(") ");
 | 
			
		||||
    }
 | 
			
		||||
    echo(") ");
 | 
			
		||||
   }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $sql   = "SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "'";
 | 
			
		||||
    $data = mysql_query($sql);
 | 
			
		||||
    while($row = mysql_fetch_array($data)) {
 | 
			
		||||
      $if = $row['interface_id'];
 | 
			
		||||
      $vrf_id = $row['ifVrf'];
 | 
			
		||||
      if($row['ifVrf']){ if(!$valid_vrf_if[$vrf_id][$if]) {
 | 
			
		||||
  $sql = "SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "'";
 | 
			
		||||
  $data = mysql_query($sql);
 | 
			
		||||
  while($row = mysql_fetch_array($data))
 | 
			
		||||
  {
 | 
			
		||||
    $if = $row['interface_id'];
 | 
			
		||||
    $vrf_id = $row['ifVrf'];
 | 
			
		||||
    if($row['ifVrf'])
 | 
			
		||||
    {
 | 
			
		||||
      if(!$valid_vrf_if[$vrf_id][$if])
 | 
			
		||||
      {
 | 
			
		||||
        echo("-");
 | 
			
		||||
        $query = @mysql_query("UPDATE ports SET `ifVrf` = NULL WHERE interface_id = '$if'");
 | 
			
		||||
      } else {echo(".");} }
 | 
			
		||||
      } 
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        echo(".");
 | 
			
		||||
      } 
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
    $sql  = "SELECT * FROM vrfs WHERE device_id = '" . $device['device_id'] . "'";
 | 
			
		||||
    $data = mysql_query($sql);
 | 
			
		||||
    while($row = mysql_fetch_array($data)) {
 | 
			
		||||
      $vrf_id = $row['vrf_id'];
 | 
			
		||||
      if(!$valid_vrf[$vrf_id]) {
 | 
			
		||||
        echo("-");
 | 
			
		||||
        $query = @mysql_query("DELETE FROM vrfs WHERE vrf_id = '$vrf_id'");
 | 
			
		||||
      } else {echo(".");}
 | 
			
		||||
    }
 | 
			
		||||
  $sql = "SELECT * FROM vrfs WHERE device_id = '" . $device['device_id'] . "'";
 | 
			
		||||
  $data = mysql_query($sql);
 | 
			
		||||
  while($row = mysql_fetch_array($data))
 | 
			
		||||
  {
 | 
			
		||||
    $vrf_id = $row['vrf_id'];
 | 
			
		||||
    if(!$valid_vrf[$vrf_id])
 | 
			
		||||
    {
 | 
			
		||||
      echo("-");
 | 
			
		||||
      $query = @mysql_query("DELETE FROM vrfs WHERE vrf_id = '$vrf_id'");
 | 
			
		||||
    } else { echo(".");}
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  unset($valid_vrf_if);
 | 
			
		||||
  unset($valid_vrf);
 | 
			
		||||
 | 
			
		||||
  echo("\n");
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
} # ios/junos/ironware
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
?>
 | 
			
		||||
		Reference in New Issue
	
	Block a user