/* (non-Javadoc)
   * @see com.dhcc.webnms.host.snmp.AbstractSnmp#collectData()
   */
  public Hashtable collect_Data(NodeGatherIndicators nodeGatherIndicators) {
    // yangjun
    Hashtable returnHash = new Hashtable();
    Vector cpuVector = new Vector();
    List cpuList = new ArrayList();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(nodeGatherIndicators.getNodeid()));
    if (node == null) return returnHash;
    // HostNode host = (HostNode)node;
    // 判断是否在采集时间段内
    if (ShareData.getTimegatherhash() != null) {
      if (ShareData.getTimegatherhash().containsKey(node.getId() + ":equipment")) {
        TimeGratherConfigUtil timeconfig = new TimeGratherConfigUtil();
        int _result = 0;
        _result =
            timeconfig.isBetween(
                (List) ShareData.getTimegatherhash().get(node.getId() + ":equipment"));
        if (_result == 1) {
          // SysLogger.info("########时间段内: 开始采集 "+node.getIpAddress()+" PING数据信息##########");
        } else if (_result == 2) {
          // SysLogger.info("########全天: 开始采集 "+node.getIpAddress()+" PING数据信息##########");
        } else {
          SysLogger.info("######## " + node.getIpAddress() + " 不在采集CPU时间段内,退出##########");
          // 清除之前内存中产生的告警信息
          try {
            // 清除之前内存中产生的CPU告警信息
            NodeDTO nodedto = null;
            NodeUtil nodeUtil = new NodeUtil();
            nodedto = nodeUtil.creatNodeDTOByHost(node);
            CheckEventUtil checkutil = new CheckEventUtil();
            checkutil.deleteEvent(
                node.getId() + "", nodedto.getType(), nodedto.getSubtype(), "cpu", null);
          } catch (Exception e) {
            e.printStackTrace();
          }
          return returnHash;
        }
      }
    }

    try {
      // System.out.println("Start collect data as ip "+host);
      CPUcollectdata cpudata = null;
      Calendar date = Calendar.getInstance();

      try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        com.afunms.polling.base.Node snmpnode =
            (com.afunms.polling.base.Node)
                PollingEngine.getInstance().getNodeByIP(node.getIpAddress());
        Date cc = date.getTime();
        String time = sdf.format(cc);
        snmpnode.setLastTime(time);
      } catch (Exception e) {

      }
      // -------------------------------------------------------------------------------------------cpu start
      int result = 0;

      try {
        String temp = "0";
        String[] oids = new String[] {"1.3.6.1.4.1.171.12.1.1.6.3"};
        String[][] valueArray = null;
        // valueArray = SnmpUtils.getCpuTableData(node.getIpAddress(), node.getCommunity(), oids,
        // node.getSnmpversion(), 3, 1000*30);
        valueArray =
            SnmpUtils.getTemperatureTableData(
                node.getIpAddress(),
                node.getCommunity(),
                oids,
                node.getSnmpversion(),
                node.getSecuritylevel(),
                node.getSecurityName(),
                node.getV3_ap(),
                node.getAuthpassphrase(),
                node.getV3_privacy(),
                node.getPrivacyPassphrase(),
                3,
                1000 * 30);
        int allvalue = 0;
        int flag = 0;

        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            String _value = valueArray[i][0];
            String index = valueArray[i][1];

            int value = 0;
            value = Integer.parseInt(_value);
            allvalue = allvalue + Integer.parseInt(_value);
            // if(value >0){
            flag = flag + 1;
            List alist = new ArrayList();
            alist.add(index);
            alist.add(_value);
            cpuList.add(alist);
            // }
            // SysLogger.info(host.getIpAddress()+"  "+index+"   value="+value);
          }
        }

        if (flag > 0) {

          int intvalue = (allvalue / flag);
          temp = intvalue + "";
          // SysLogger.info(node.getIpAddress()+"获取的cpu=== "+allvalue/flag);
        }

        if (temp == null) {
          result = 0;
        } else {
          try {
            if (temp.equalsIgnoreCase("noSuchObject")) {
              result = 0;
            } else result = Integer.parseInt(temp);
          } catch (Exception ex) {
            ex.printStackTrace();
            result = 0;
          }
        }
        cpudata = new CPUcollectdata();
        cpudata.setIpaddress(node.getIpAddress());
        cpudata.setCollecttime(date);
        cpudata.setCategory("CPU");
        cpudata.setEntity("Utilization");
        cpudata.setSubentity("Utilization");
        cpudata.setRestype("dynamic");
        cpudata.setUnit("%");
        cpudata.setThevalue(result + "");

        cpuVector.addElement(cpudata);

      } catch (Exception e) {
        // e.printStackTrace();
      }
      // -------------------------------------------------------------------------------------------cpu end
    } catch (Exception e) {
      // returnHash=null;
      // e.printStackTrace();
      // return null;
    }

    //		Hashtable ipAllData = new Hashtable();
    //		try{
    //			ipAllData = (Hashtable)ShareData.getSharedata().get(node.getIpAddress());
    //		}catch(Exception e){
    //
    //		}
    //		if(ipAllData == null)ipAllData = new Hashtable();
    //		if(cpuVector != null && cpuVector.size()>0)ipAllData.put("cpu",cpuVector);
    //		if(cpuList != null && cpuList.size()>0)ipAllData.put("cpulist",cpuList);
    //	    ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    //	    returnHash.put("cpu", cpuVector);

    if (!(ShareData.getSharedata().containsKey(node.getIpAddress()))) {
      Hashtable ipAllData = new Hashtable();
      if (ipAllData == null) ipAllData = new Hashtable();
      if (cpuVector != null && cpuVector.size() > 0) ipAllData.put("cpu", cpuVector);
      if (cpuList != null && cpuList.size() > 0) ipAllData.put("cpulist", cpuList);
      ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    } else {
      if (cpuVector != null && cpuVector.size() > 0)
        ((Hashtable) ShareData.getSharedata().get(node.getIpAddress())).put("cpu", cpuVector);
      if (cpuList != null && cpuList.size() > 0)
        ((Hashtable) ShareData.getSharedata().get(node.getIpAddress())).put("cpulist", cpuList);
    }
    returnHash.put("cpu", cpuVector);

    // 对CPU值进行告警检测
    Hashtable collectHash = new Hashtable();
    collectHash.put("cpu", cpuVector);
    try {
      if (cpuVector != null && cpuVector.size() > 0) {
        for (int i = 0; i < cpuVector.size(); i++) {
          CPUcollectdata cpucollectdata = (CPUcollectdata) cpuVector.get(0);
          if ("Utilization".equals(cpucollectdata.getEntity())) {
            CheckEventUtil checkutil = new CheckEventUtil();
            checkutil.updateData(node, nodeGatherIndicators, cpucollectdata.getThevalue());
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    cpuVector = null;
    cpuList = null;

    // 把结果转换成sql
    NetcpuResultTosql tosql = new NetcpuResultTosql();
    tosql.CreateResultTosql(returnHash, node.getIpAddress());
    String runmodel = PollingEngine.getCollectwebflag(); // 采集与访问模式
    if (!"0".equals(runmodel)) {
      // 采集与访问是分离模式,则不需要将监视数据写入临时表格
      NetHostDatatempCpuRTosql totempsql = new NetHostDatatempCpuRTosql();
      totempsql.CreateResultTosql(returnHash, node);
    }

    return returnHash;
  }
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    Hashtable returnHash = new Hashtable();
    Vector fanVector = new Vector();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return returnHash;
    try {
      Interfacecollectdata interfacedata = new Interfacecollectdata();
      Calendar date = Calendar.getInstance();
      Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(node.getIpAddress());
      if (ipAllData == null) ipAllData = new Hashtable();

      try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        com.afunms.polling.base.Node snmpnode =
            (com.afunms.polling.base.Node)
                PollingEngine.getInstance().getNodeByIP(node.getIpAddress());
        Date cc = date.getTime();
        String time = sdf.format(cc);
        snmpnode.setLastTime(time);
      } catch (Exception e) {

      }
      try {
        String[][] valueArray = null;
        String[] oids =
            new String[] {
              "1.3.6.1.4.1.116.5.11.4.1.1.7.1.1", // dkuRaidListIndexSerialNumber
              "1.3.6.1.4.1.116.5.11.4.1.1.7.1.4" // dkuHWEnvironment
            };
        valueArray =
            SnmpUtils.getTemperatureTableData(
                node.getIpAddress(),
                node.getCommunity(),
                oids,
                node.getSnmpversion(),
                node.getSecuritylevel(),
                node.getSecurityName(),
                node.getV3_ap(),
                node.getAuthpassphrase(),
                node.getV3_privacy(),
                node.getPrivacyPassphrase(),
                3,
                1000 * 30);
        int flag = 0;
        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            String _value = valueArray[i][1];
            String index = valueArray[i][2];
            String num = valueArray[i][0];
            flag = flag + 1;
            List alist = new ArrayList();
            alist.add(index);
            alist.add(_value);
            alist.add(num);
            interfacedata = new Interfacecollectdata();
            interfacedata.setIpaddress(node.getIpAddress());
            interfacedata.setCollecttime(date);
            interfacedata.setCategory("Env");
            interfacedata.setEntity(index);
            interfacedata.setSubentity(num);
            interfacedata.setRestype("dynamic");
            interfacedata.setUnit("");
            interfacedata.setThevalue(_value);
            SysLogger.info(node.getIpAddress() + " 索引:" + index + " 环境状态: " + _value);
            fanVector.addElement(interfacedata);
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (!(ShareData.getSharedata().containsKey(node.getIpAddress()))) {
      Hashtable ipAllData = new Hashtable();
      if (ipAllData == null) ipAllData = new Hashtable();
      if (fanVector != null && fanVector.size() > 0) ipAllData.put("eenv", fanVector);
      ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    } else {
      if (fanVector != null && fanVector.size() > 0)
        ((Hashtable) ShareData.getSharedata().get(node.getIpAddress())).put("eenv", fanVector);
    }
    returnHash.put("env", fanVector);

    try {
      AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
      List list =
          alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
              String.valueOf(node.getId()), AlarmConstant.TYPE_STORAGE, "hds", "eenv");

      AlarmHelper helper = new AlarmHelper();
      Hashtable<String, EnvConfig> envHashtable =
          helper.getAlarmConfig(node.getIpAddress(), "eenv");
      for (int i = 0; i < list.size(); i++) {
        AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(i);
        // 对风扇值进行告警检测
        CheckEventUtil checkutil = new CheckEventUtil();
        if (fanVector.size() > 0) {
          for (int j = 0; j < fanVector.size(); j++) {
            Interfacecollectdata data = (Interfacecollectdata) fanVector.get(j);
            if (data != null) {
              EnvConfig config = envHashtable.get(data.getEntity());
              if (config != null && config.getEnabled() == 1) {
                alarmIndicatorsnode.setAlarm_level(config.getAlarmlevel());
                alarmIndicatorsnode.setAlarm_times(config.getAlarmtimes() + "");
                alarmIndicatorsnode.setLimenvalue0(config.getAlarmvalue() + "");
                checkutil.checkEvent(
                    node, alarmIndicatorsnode, data.getThevalue(), data.getSubentity());
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    fanVector = null;

    // 把采集结果生成sql
    HDSEnvEnvResultTosql tosql = new HDSEnvEnvResultTosql();
    tosql.CreateResultTosql(returnHash, node.getIpAddress());

    return returnHash;
  }
  /* (non-Javadoc)
   * @see com.dhcc.webnms.host.snmp.AbstractSnmp#collectData()
   */
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    // yangjun
    Hashtable returnHash = new Hashtable();
    Vector queueVector = new Vector();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return null;

    try {
      Calendar date = Calendar.getInstance();

      try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        com.afunms.polling.base.Node snmpnode =
            (com.afunms.polling.base.Node)
                PollingEngine.getInstance().getNodeByIP(node.getIpAddress());
        Date cc = date.getTime();
        String time = sdf.format(cc);
        snmpnode.setLastTime(time);
      } catch (Exception e) {

      }
      try {
        // -------------------------------------------------------------------------------------------start
        //				  INTEGER {queueSpaceAvailable(1),队列有足够的空间
        //					  queueSpaceShortage(2),队列接近满
        //					  queueFull(3)队列已满
        //					  }
        if (node.getSysOid().startsWith("1.3.6.1.4.1.15497.")) {
          String[][] valueArray = null;
          String[] oids = new String[] {"1.3.6.1.4.1.15497.1.1.1.5"};
          // valueArray = SnmpUtils.getTemperatureTableData(node.getIpAddress(),
          // node.getCommunity(), oids, node.getSnmpversion(), 3, 5000);
          valueArray =
              SnmpUtils.getTemperatureTableData(
                  node.getIpAddress(),
                  node.getCommunity(),
                  oids,
                  node.getSnmpversion(),
                  node.getSecuritylevel(),
                  node.getSecurityName(),
                  node.getV3_ap(),
                  node.getAuthpassphrase(),
                  node.getV3_privacy(),
                  node.getPrivacyPassphrase(),
                  3,
                  1000 * 30);
          if (valueArray != null) {
            for (int i = 0; i < valueArray.length; i++) {
              String value = valueArray[i][0];
              if (value != null && Integer.parseInt(value) > 0) {
                Memorycollectdata memorycollectdata = new Memorycollectdata();
                memorycollectdata.setIpaddress(node.getIpAddress());
                memorycollectdata.setCollecttime(date);
                memorycollectdata.setCategory("QueueStatue");
                memorycollectdata.setEntity("statue");
                memorycollectdata.setSubentity("队列状态");
                memorycollectdata.setRestype("dynamic");
                memorycollectdata.setUnit("");
                memorycollectdata.setThevalue(value);
                queueVector.addElement(memorycollectdata);
              }
            }
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      // -------------------------------------------------------------------------------------------内存 end
    } catch (Exception e) {
      // returnHash=null;
      e.printStackTrace();
      // return null;
    }

    Hashtable ipAllData = new Hashtable();
    try {
      ipAllData = (Hashtable) ShareData.getSharedata().get(node.getIpAddress());
    } catch (Exception e) {

    }
    if (ipAllData == null) ipAllData = new Hashtable();
    if (queueVector != null && queueVector.size() > 0) ipAllData.put("queuestatue", queueVector);
    ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    returnHash.put("queuestatue", queueVector);
    return returnHash;
  }
  /* (non-Javadoc)
   * @see com.dhcc.webnms.host.snmp.AbstractSnmp#collectData()
   */
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    Hashtable returnHash = new Hashtable();
    Vector temperatureVector = new Vector();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return null;
    try {
      Interfacecollectdata interfacedata = new Interfacecollectdata();
      Calendar date = Calendar.getInstance();
      Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(node.getIpAddress());
      if (ipAllData == null) ipAllData = new Hashtable();

      try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        com.afunms.polling.base.Node snmpnode =
            (com.afunms.polling.base.Node)
                PollingEngine.getInstance().getNodeByIP(node.getIpAddress());
        Date cc = date.getTime();
        String time = sdf.format(cc);
        snmpnode.setLastTime(time);
      } catch (Exception e) {

      }
      try {
        // -------------------------------------------------------------------------------------------温度 start
        String temp = "0";
        // if(host.getSysOid().startsWith("1.3.6.1.4.1.9.")){
        String[][] valueArray = null;
        String[] oids =
            new String[] {
              "1.3.6.1.4.1.3320.2.1.78", // bdenvTestPt1Descr
              "1.3.6.1.4.1.3320.2.1.79" // bdenvTestPt1Measure
            };
        valueArray =
            SnmpUtils.getTemperatureTableData(
                node.getIpAddress(),
                node.getCommunity(),
                oids,
                node.getSnmpversion(),
                3,
                1000 * 30);
        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            String _value = valueArray[i][1];
            String index = valueArray[i][2];
            String desc = valueArray[i][0];
            int value = 0;
            if (_value != null) {
              value = Integer.parseInt(_value);
              if (value > 0) {
                // flag = flag +1;
                List alist = new ArrayList();
                alist.add(index);
                alist.add(_value);
                alist.add(desc);
                // 内存
                // temperatureList.add(alist);
                interfacedata = new Interfacecollectdata();
                interfacedata.setIpaddress(node.getIpAddress());
                interfacedata.setCollecttime(date);
                interfacedata.setCategory("Temperature");
                interfacedata.setEntity(index);
                interfacedata.setSubentity(desc);
                interfacedata.setRestype("dynamic");
                interfacedata.setUnit("度");
                interfacedata.setThevalue(_value + "");
                SysLogger.info(node.getIpAddress() + " 温度: " + _value);
                temperatureVector.addElement(interfacedata);
              }
            }
            // SysLogger.info(host.getIpAddress()+"  "+index+"   value="+value);
          }
        }
        // }
        // cpuVector.add(3, temperatureList);
      } catch (Exception e) {
      }
      // -------------------------------------------------------------------------------------------温度 end
    } catch (Exception e) {
    }

    //		Hashtable ipAllData = (Hashtable)ShareData.getSharedata().get(node.getIpAddress());
    //		if(ipAllData == null)ipAllData = new Hashtable();
    //		ipAllData.put("temperature",temperatureVector);
    //	    ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    //	    returnHash.put("temperature", temperatureVector);

    if (!(ShareData.getSharedata().containsKey(node.getIpAddress()))) {
      Hashtable ipAllData = new Hashtable();
      if (ipAllData == null) ipAllData = new Hashtable();
      if (temperatureVector != null && temperatureVector.size() > 0)
        ipAllData.put("temperature", temperatureVector);
      ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    } else {
      if (temperatureVector != null && temperatureVector.size() > 0)
        ((Hashtable) ShareData.getSharedata().get(node.getIpAddress()))
            .put("temperature", temperatureVector);
    }
    returnHash.put("temperature", temperatureVector);

    temperatureVector = null;
    //	    ipAllData=null;

    // 把采集结果生成sql
    NetTemperatureResultTosql tosql = new NetTemperatureResultTosql();
    tosql.CreateResultTosql(returnHash, node.getIpAddress());
    NetDatatempTemperatureRtosql temptosql = new NetDatatempTemperatureRtosql();
    temptosql.CreateResultTosql(returnHash, node);

    return returnHash;
  }