Ejemplo n.º 1
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;
      }
    }
  }