zoukankan      html  css  js  c++  java
  • function

    static function getPortNames($DeviceID,$portid=null){
    if(!$dev=SwitchInfo::BasicTests($DeviceID)){
    return false;
    }
    // We never did finish the discussion of if we should use the mib vs the oid
    $baseOID = ".1.3.6.1.2.1.31.1.1.1.1";
    $baseOID = "IF-MIB::ifName";
    $nameList=self::OSS_SNMP_Lookup($dev,"descriptions",$portid,$baseOID);

    if(is_array($nameList)){
    $saving=false;
    $newList=array();
    foreach($nameList as $i => $desc){
    if($i==$dev->FirstPortNum){$saving=true;}
    if($saving){$newList[sizeof($newList)+1]=$desc;}
    if(sizeof($newList)==$dev->Ports){break;}
    }
    $nameList=$newList;
    }
    return $nameList;
    }

     
    static function createPorts($DeviceID,$update_existing=false){
    // If $update_existing is true then we'll try to create all the ports and as a by product
    // create any new ports. The setting here will ensure we don't log any errors from the
    // ports that already exist.
    $dev=New Device;
    $dev->DeviceID=$DeviceID;
    if(!$dev->GetDevice()){return false;}

    // Check the user's permissions to modify this device
    if($dev->Rights!='Write'){return false;}
    $portList=array();

    if($dev->DeviceType=="Switch"){
    $nameList=SwitchInfo::getPortNames($dev->DeviceID);
    $aliasList=SwitchInfo::getPortAlias($dev->DeviceID);
    }

    // Build the DevicePorts from the existing info in the following priority:
    // - Template ports table
    // - SNMP data (if it exists)
    // - Placeholders

    //Search template ports
    $tports=array();
    if($dev->TemplateID>0){
    $tport=new TemplatePorts();
    $tport->TemplateID=$dev->TemplateID;
    $tports=$tport->getPorts();
    }

    if($dev->DeviceType=="Switch"){
    for($n=0; $n<$dev->Ports; $n++){
    $i=$n+1;
    $portList[$i]=new DevicePorts();
    $portList[$i]->DeviceID=$dev->DeviceID;
    $portList[$i]->PortNumber=$i;
    if(isset($tports[$i])){
    // Get any attributes from the device template
    foreach($tports[$i] as $key => $value){ if(array_key_exists($key,$portList[$i])){ $portList[$i]->$key=$value; } } } // pull port name first from snmp then from template then just call it port x $portList[$i]->Label=(isset($nameList[$n]))?$nameList[$n]:(isset($tports[$i]) && $tports[$i]->Label)?$tports[$i]->Label:__("Port").$i; $portList[$i]->Notes=(isset($aliasList[$n]))?$aliasList[$n]:''; $portList[$i]->createPort($update_existing); } }else{ for($n=0; $n<$dev->Ports; $n++){ $i=$n+1; $portList[$i]=new DevicePorts(); $portList[$i]->DeviceID=$dev->DeviceID; $portList[$i]->PortNumber=$i; //对应 模板端口对象数组 if(isset($tports[$i])){ // Get any attributes from the device template foreach($tports[$i] as $key => $value){ if(array_key_exists($key,$portList[$i])){ $portList[$i]->$key=$value; } } } $portList[$i]->Label=($portList[$i]->Label=="")?__("Port").$i:$portList[$i]->Label; $portList[$i]->createPort($update_existing); if($dev->DeviceType=="Patch Panel"){ $label=$portList[$i]->Label; $i=$i*-1; $portList[$i]=new DevicePorts(); $portList[$i]->DeviceID=$dev->DeviceID; $portList[$i]->PortNumber=$i; $portList[$i]->Label=$label; $portList[$i]->createPort($update_existing); } } } return $portList;}
     
  • 相关阅读:
    「HDU3640」I,Zombie
    气温变化折线图/matplotlib中文显示
    基本折线图
    根据统计数据画直方图
    matplotlib直方图绘制(hist)
    豆瓣Top250电影数据爬取学习
    pd.set_option参数设置
    django安装
    字典公共键
    字典排序
  • 原文地址:https://www.cnblogs.com/hehexu/p/8638265.html
Copyright © 2011-2022 走看看