Esempio n. 1
0
  /** 对IP_Net_To_Media进行探测 */
  private void doIPNetProbe() {
    if (DiscoverEngine.getInstance().getStopStatus() == 1) return;
    List ipNetTable =
        SnmpUtil.getInstance().getIpNetToMediaTable(this.getIpAddress(), this.getCommunity());

    if (ipNetTable == null || ipNetTable.size() == 0) // important
    {
      setDiscovered(true);
      return;
    }
    ipTotal = ipNetTable.size();
    int threadTotal = 0; // 线程总数
    SysLogger.info("PER_THREAD_IP===" + PER_THREAD_IP);
    if (ipTotal % PER_THREAD_IP == 0) // 每个线程对N个ip进行探测
    threadTotal = ipTotal / PER_THREAD_IP;
    else threadTotal = ipTotal / PER_THREAD_IP + 1;

    IPNetProbeThread probeThread = null;
    for (int i = 0; i < threadTotal; i++) {
      if (i == threadTotal - 1)
        probeThread = new IPNetProbeThread(this, ipNetTable.subList(i * PER_THREAD_IP, ipTotal));
      else
        probeThread =
            new IPNetProbeThread(
                this, ipNetTable.subList(i * PER_THREAD_IP, (i + 1) * PER_THREAD_IP));
      DiscoverEngine.getInstance().addThread(probeThread);
    }
  }
  /*
   * 根据IP查询
   *
   */
  public List getByIp(String ipaddress) {
    List list = new ArrayList();
    Session session = null;
    Hashtable retValue = new Hashtable();
    try {

      rs =
          conn.executeQuery(
              "select * from system_oraspaceconf where ipaddress = '"
                  + ipaddress
                  + "' order by ipaddress");
      // Query query=session.createQuery("from Oraspaceconfig oraspaceconfig where
      // oraspaceconfig.sms="+smsflag+" order by oraspaceconfig.ipaddress");

      while (rs.next()) list.add(loadFromRS(rs));
    } catch (Exception e) {
      e.printStackTrace();
    }
    // TODO Auto-generated method stub
    return list;
  }
 /*
  * 根据IP和是否要显示于日报表的标志位查询
  *
  */
 public Hashtable getByAlarmflag(Integer smsflag) {
   List list = new ArrayList();
   Session session = null;
   Hashtable retValue = new Hashtable();
   try {
     rs =
         conn.executeQuery(
             "select * from system_oraspaceconf where sms=" + smsflag + " order by ipaddress");
     // Query query=session.createQuery("from Oraspaceconfig oraspaceconfig where
     // oraspaceconfig.sms="+smsflag+" order by oraspaceconfig.ipaddress");
     while (rs.next()) list.add(loadFromRS(rs));
     if (list != null && list.size() > 0) {
       for (int i = 0; i < list.size(); i++) {
         Oraspaceconfig oraspaceconfig = (Oraspaceconfig) list.get(i);
         String ipaddr = oraspaceconfig.getIpaddress();
         String[] iparry = ipaddr.split(":");
         IpTranslation tranfer = new IpTranslation();
         String[] tip = tranfer.getIpFromHex(iparry[0]);
         retValue.put(
             tip[0]
                 + "."
                 + tip[1]
                 + "."
                 + tip[2]
                 + "."
                 + tip[3]
                 + ":"
                 + iparry[1]
                 + ":"
                 + oraspaceconfig.getSpacename(),
             oraspaceconfig);
         // SysLogger.info(tip[0]+"."+tip[1]+"."+tip[2]+"."+tip[3]+":"+iparry[1]+":"+oraspaceconfig.getSpacename()+"===="+oraspaceconfig.getSpacename());
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   // TODO Auto-generated method stub
   return retValue;
 }
  public void run() {
    if (DiscoverEngine.getInstance().getStopStatus() == 1) return;
    snmp = SnmpUtil.getInstance();
    SysLogger.info("开始分析设备" + node.getIpAddress() + "的地址转发表");
    Set shieldList = DiscoverResource.getInstance().getShieldSet();
    List netshieldList = DiscoverResource.getInstance().getNetshieldList();
    List netincludeList = DiscoverResource.getInstance().getNetincludeList();
    IfEntity ifEntity = null;
    IfEntity endifEntity = null;

    // 生成线程池
    ThreadPool threadPool = new ThreadPool(addressList.size());

    for (int i = 0; i < addressList.size(); i++) {
      // ###################################
      // 若不需要服务器,则不进行交换机的ARP表采集
      // if(1==1)continue;
      // ###################################
      try {
        // node.updateCount(2);
        IpAddress ipAddr = (IpAddress) addressList.get(i);
        threadPool.runTask(NetMediThread.createTask(ipAddr, node));
        // SysLogger.info("在"+node.getIpAddress()+"的地址转发表发现IP "+ipAddr.getIpAddress()+",开始分析");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } // end_for
    // 关闭线程池并等待所有任务完成
    threadPool.join();
    threadPool.close();
    threadPool = null;

    DiscoverEngine.getInstance().addDiscoverdcount();
    snmp = null;
    setCompleted(true);
  } // end_run
  /*
   *
   * 从内存和数据库表里获取每个IP的端口信息,存入端口配置表里
   */
  public void fromLastToOraspaceconfig() throws Exception {
    List list = new ArrayList();
    List list1 = new ArrayList();
    List shareList = new ArrayList();
    Hashtable oraspacehash = new Hashtable();
    Session session = null;
    Vector configV = new Vector();
    IpTranslation tranfer = new IpTranslation();
    try {
      // 从ORASPACCE配置表里获取列表
      rs = conn.executeQuery("select * from system_oraspaceconf order by ipaddress");
      while (rs.next()) list1.add(loadFromRS(rs));
      if (list1 != null && list1.size() > 0) {
        for (int i = 0; i < list1.size(); i++) {
          Oraspaceconfig oraspaceconfig = (Oraspaceconfig) list1.get(i);
          // IP:表空间名称

          oraspacehash.put(
              oraspaceconfig.getIpaddress() + ":" + oraspaceconfig.getSpacename(), oraspaceconfig);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    try {

      // 从内存中得到所有ORASPACCE采集信息
      Hashtable sharedata = ShareData.getOraspacedata();

      // 从数据库得到监视ORASPACCE列表
      DBDao dbdao = new DBDao();
      DBTypeDao typedao = new DBTypeDao();
      DBTypeVo typevo = typedao.findByDbtype("oracle");
      shareList = dbdao.getDbByTypeMonFlag(typevo.getId(), 1);
      if (shareList != null && shareList.size() > 0) {
        for (int i = 0; i < shareList.size(); i++) {
          //					OraclePartsDao oracleDao=null;
          try {
            DBVo dbmonitorlist = (DBVo) shareList.get(i);
            //						 oracleDao=new OraclePartsDao();
            //						List<OracleEntity> oracles=oracleDao.findOracleParts(dbmonitorlist.getId());
            //						for(OracleEntity ora:oracles){
            //
            //						}
            if (sharedata.get(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId()) != null) {
              Vector tableinfo_v =
                  (Vector)
                      sharedata.get(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId());
              if (tableinfo_v == null) continue;
              Hashtable spaces = new Hashtable();
              spaces.put("ip", dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId());
              spaces.put("tableinfo_v", tableinfo_v);
              list.add(spaces);
            }
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            //						if(oracleDao!=null)
            //						  oracleDao.close();
          }
        }
      }
      // 判断采集到的ORASPACCE信息是否已经在ORASPACCE配置表里已经存在,若不存在则加入
      if (list != null && list.size() > 0) {
        for (int i = 0; i < list.size(); i++) {
          Hashtable spaces = (Hashtable) list.get(i);
          if (spaces != null && spaces.size() > 0) {
            String ip = (String) spaces.get("ip");
            Vector tableinfo_v = (Vector) spaces.get("tableinfo_v");
            if (tableinfo_v != null && tableinfo_v.size() > 0) {
              Oraspaceconfig oraspaceconfig = null;
              for (int k = 0; k < tableinfo_v.size(); k++) {
                Hashtable return_value = (Hashtable) tableinfo_v.get(k);
                String spacename = (String) return_value.get("tablespace");
                String[] iparr = ip.split(":");
                String tip = tranfer.formIpToHex(iparr[0]);
                if (!oraspacehash.containsKey(tip + ":" + iparr[1] + ":" + spacename)) {
                  oraspaceconfig = new Oraspaceconfig();
                  oraspaceconfig.setSpacename(spacename);
                  oraspaceconfig.setBak("");
                  oraspaceconfig.setIpaddress(tip + ":" + iparr[1]);
                  oraspaceconfig.setLinkuse("");
                  oraspaceconfig.setAlarmvalue(90);
                  oraspaceconfig.setSms(new Integer(0)); // 0:不告警 1:告警,默认的情况是不发送短信
                  oraspaceconfig.setReportflag(new Integer(0)); // 0:不存在于报表 1:存在于报表,默认的情况是不存在于报表
                  conn = new DBManager();
                  save(oraspaceconfig);
                  // configV.add(oraspaceconfig);
                  oraspacehash.put(tip + ":" + iparr[1] + ":" + spacename, oraspaceconfig);
                }
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    // TODO Auto-generated method stub
  }