/**
   * 把结果生成sql
   *
   * @param dataresult 采集结果
   * @param node 网元节点
   */
  public void CreateResultTosql(Hashtable dataresult, Host node) {

    if ("1".equals(PollingEngine.getCollectwebflag())) { // 是否启动分离模式

      if (dataresult != null && dataresult.size() > 0) {

        String hendsql =
            "insert into nms_storage_data_temp(nodeid,ip,`type`,subtype,name,stype,cap,storageindex,collecttime)values(";
        String endsql = ")";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        NodeUtil nodeUtil = new NodeUtil();
        Vector storageVector = (Vector) dataresult.get("storage");
        NodeDTO nodeDTO = null;
        nodeDTO = nodeUtil.creatNodeDTOByNode(node);

        String deleteSql = "delete from nms_storage_data_temp where nodeid='" + node.getId() + "'";
        if (storageVector != null && storageVector.size() > 0) {
          Calendar tempCal = Calendar.getInstance();
          Date cc = tempCal.getTime();
          String time = sdf.format(cc);

          Vector list = new Vector();
          for (int i = 0; i < storageVector.size(); i++) {
            Storagecollectdata vo = (Storagecollectdata) storageVector.elementAt(i);
            StringBuffer sbuffer = new StringBuffer(100);
            sbuffer.append(hendsql);
            sbuffer.append("'").append(node.getId()).append("',");
            sbuffer.append("'").append(node.getIpAddress()).append("',");
            sbuffer.append("'").append(nodeDTO.getType()).append("',");
            sbuffer.append("'").append(nodeDTO.getSubtype()).append("',");
            sbuffer.append("'").append(vo.getName().replace("\\", "/")).append("',");
            sbuffer.append("'").append(vo.getType()).append("',");
            sbuffer.append("'").append(vo.getCap()).append("',");
            sbuffer.append("'").append(vo.getStorageindex()).append("',");
            //							sbuffer.append("'").append(time).append("'");
            if ("mysql".equalsIgnoreCase(SystemConstant.DBType)) {
              sbuffer.append("'").append(time).append("'");
            } else if ("oracle".equalsIgnoreCase(SystemConstant.DBType)) {
              sbuffer.append("to_date('" + time + "','YYYY-MM-DD HH24:MI:SS')");
            }
            sbuffer.append(endsql);
            list.add(sbuffer.toString());
            vo = null;
            sbuffer = null;
          }

          GathersqlListManager.AdddateTempsql(deleteSql, list);
          list = null;
        }
        storageVector = null;
      }
    }
  }
  /* (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;
  }
  /**
   * 把结果生成sql
   *
   * @param dataresult 采集结果
   * @param node 网元节点
   */
  public void CreateResultTosql(Hashtable dataresult, Host node) {

    if ("1".equals(PollingEngine.getCollectwebflag())) { // 是否启动分离模式

      if (dataresult != null && dataresult.size() > 0) {

        String hendsql =
            "insert into nms_process_data_temp(nodeid,ip,`type`,subtype,entity,subentity,sindex,thevalue,chname,restype,collecttime,unit,bak)values(";
        String endsql = ")";

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        NodeUtil nodeUtil = new NodeUtil();
        NodeDTO nodeDTO = nodeUtil.creatNodeDTOByNode(node);
        Vector processVector = (Vector) dataresult.get("process");
        String deleteSql = "delete from nms_process_data_temp where nodeid='" + node.getId() + "'";
        if (processVector != null && processVector.size() > 0) {
          Vector list = new Vector();
          for (int i = 0; i < processVector.size(); i++) {
            Processcollectdata vo = (Processcollectdata) processVector.elementAt(i);
            Calendar tempCal = (Calendar) vo.getCollecttime();
            Date cc = tempCal.getTime();
            String time = sdf.format(cc);
            String thevalue = vo.getThevalue();
            if (thevalue != null) {
              thevalue = thevalue.replaceAll("\\\\", "/");
              if (thevalue.length() > 50) {
                thevalue = thevalue.substring(0, 50) + "...";
              }
            }

            StringBuffer sbuffer = new StringBuffer(200);
            sbuffer.append(hendsql);
            sbuffer.append("'").append(node.getId()).append("',");
            sbuffer.append("'").append(node.getIpAddress()).append("',");
            sbuffer.append("'").append(nodeDTO.getType()).append("',");
            sbuffer.append("'").append(nodeDTO.getSubtype()).append("',");
            sbuffer.append("'").append(vo.getCategory()).append("',");
            sbuffer.append("'").append(vo.getEntity()).append("',");
            sbuffer.append("'").append(vo.getSubentity()).append("',");
            sbuffer.append("'").append(vo.getThevalue()).append("',");
            sbuffer.append("'").append(vo.getChname()).append("',");
            sbuffer.append("'").append(vo.getRestype()).append("',");
            if ("mysql".equalsIgnoreCase(SystemConstant.DBType)) {
              sbuffer.append("'").append(time).append("',");
            } else if ("oracle".equalsIgnoreCase(SystemConstant.DBType)) {
              sbuffer.append("to_date('" + time + "','YYYY-MM-DD HH24:MI:SS'),");
            }

            sbuffer.append("'").append(vo.getUnit()).append("',");
            sbuffer.append("'").append(vo.getBak()).append("'");
            sbuffer.append(endsql);
            list.add(sbuffer.toString());

            sbuffer = null;
            vo = null;

            thevalue = null;
            // cc=null;
            // tempCal=null;
            // time=null;
          }
          GathersqlListManager.AdddateTempsql(deleteSql, list);
          list = null;
        }

        processVector = null;
      }
      // }

    }
  }
Ejemplo n.º 4
0
  @SuppressWarnings("unchecked")
  public Hashtable collect_Data(NodeGatherIndicators nodeGatherIndicators) {
    WasConfig wasconf = null;
    String id = nodeGatherIndicators.getNodeid();
    SysLogger.info("#######################WebSphere Ping 开始采集###################################");

    try {
      WasConfigDao dao = new WasConfigDao();
      try {
        wasconf = (WasConfig) dao.findByID(id);
        SysLogger.info(
            "###############WebSphere   Ping  名称:"
                + wasconf.getName()
                + " ipaddress:"
                + wasconf.getIpaddress()
                + "#####################");
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        dao.close();
      }
      Hashtable hst = (Hashtable) ShareData.getWasdata().get(wasconf.getIpaddress());
      if (hst == null) {
        hst = new Hashtable();
      }
      UrlConncetWas conWas = new UrlConncetWas();
      boolean collectWasIsOK = false;
      // 采集数据
      try {
        String url =
            "http://"
                + wasconf.getIpaddress()
                + ":"
                + wasconf.getPortnum()
                + "/wasPerfTool/servlet/perfservlet?refreshConfig=true";
        System.out.println(url);
        collectWasIsOK = conWas.connectWasIsOK(wasconf.getIpaddress(), wasconf.getPortnum());
      } catch (Exception e) {
        e.printStackTrace();
      }
      String pingValue = "0";
      if (collectWasIsOK) {
        pingValue = "100";
        hst.put("ping", "100");
      } else {
        hst.put("ping", "0");
      }

      // 保存数据库
      Pingcollectdata hostdata = new Pingcollectdata();
      hostdata.setIpaddress(wasconf.getIpaddress());
      Calendar date = Calendar.getInstance();
      hostdata.setCollecttime(date);
      hostdata.setCategory("WasPing");
      hostdata.setEntity("Utilization");
      hostdata.setSubentity("ConnectUtilization");
      hostdata.setRestype("dynamic");
      hostdata.setUnit("%");
      hostdata.setThevalue(pingValue);
      WasConfigDao wasconfigdao = new WasConfigDao();
      try {
        wasconfigdao.createHostData(wasconf, hostdata);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        wasconfigdao.close();
      }
      ShareData.getWasdata().put(wasconf.getIpaddress(), hst);
      // 告警,只告警PING值
      if (pingValue != null) {
        NodeUtil nodeUtil = new NodeUtil();
        NodeDTO nodeDTO = nodeUtil.conversionToNodeDTO(wasconf);
        // 判断是否存在此告警指标
        AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
        List list =
            alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                nodeDTO.getId() + "", nodeDTO.getType(), nodeDTO.getSubtype());
        CheckEventUtil checkEventUtil = new CheckEventUtil();
        for (int i = 0; i < list.size(); i++) {
          AlarmIndicatorsNode alarmIndicatorsNode = (AlarmIndicatorsNode) list.get(i);
          if ("ping".equalsIgnoreCase(alarmIndicatorsNode.getName())) {
            if (pingValue != null) {
              checkEventUtil.checkEvent(nodeDTO, alarmIndicatorsNode, pingValue);
            }
          }
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
  /**
   * 把结果生成sql
   *
   * @param dataresult 采集结果
   * @param node 网元节点
   */
  public void CreateResultTosql(Hashtable dataresult, Host node) {

    if ("1".equals(PollingEngine.getCollectwebflag())) { // 是否启动分离模式

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      NodeUtil nodeUtil = new NodeUtil();
      NodeDTO nodeDTO = nodeUtil.creatNodeDTOByNode(node);
      Vector volumeVector = (Vector) dataresult.get("");
      String deleteSql =
          "delete from nms_other_data_temp where nodeid='"
              + node.getId()
              + "' and entity = 'volume'";
      if (volumeVector != null && volumeVector.size() > 0) {
        Calendar tempCal = Calendar.getInstance();
        Date cc = tempCal.getTime();
        String time = sdf.format(cc);

        Vector list = new Vector();

        for (int i = 0; i < volumeVector.size(); i++) {
          Hashtable volumeItemHash = (Hashtable) volumeVector.elementAt(i);
          Enumeration tempEnumeration2 = volumeItemHash.keys();
          while (tempEnumeration2.hasMoreElements()) {
            String key = (String) tempEnumeration2.nextElement();
            String value = (String) volumeItemHash.get(key);
            try {
              StringBuffer sql = new StringBuffer(500);
              sql.append(
                  "insert into nms_other_data_temp(nodeid,ip,type,subtype,entity,subentity,sindex,thevalue,collecttime)values('");
              sql.append(nodeDTO.getId());
              sql.append("','");
              sql.append(node.getIpAddress());
              sql.append("','");
              sql.append(nodeDTO.getType()); // type
              sql.append("','");
              sql.append(nodeDTO.getSubtype()); // subtype
              sql.append("','");
              sql.append("volume"); // entity
              sql.append("','");
              sql.append(key); // subentity
              sql.append("','");
              sql.append(i + 1); // sindex
              sql.append("','");
              sql.append(value); // thevalue
              if ("mysql".equalsIgnoreCase(SystemConstant.DBType)) {
                sql.append("','");
                sql.append(time); // collecttime
                sql.append("')");
              } else if ("oracle".equalsIgnoreCase(SystemConstant.DBType)) {
                sql.append("',");
                sql.append("to_date('" + time + "','YYYY-MM-DD HH24:MI:SS')"); // collecttime
                sql.append(")");
              }

              list.add(sql.toString());
              sql = null;

            } catch (Exception e) {
              e.printStackTrace();
            }
          }

          volumeItemHash = null;
        }

        GathersqlListManager.AdddateTempsql(deleteSql, list);
        list = null;
      }
    }
  }