Esempio n. 1
0
  public void executeTask() {

    if (!PollingEngine.getInstance().getCurrentDate().equals(SysUtil.getCurrentDate())) // 过了一天	
    {
      PollingEngine.getInstance().setCurrentDate(SysUtil.getCurrentDate());
      List nodeList = PollingEngine.getInstance().getNodeList();
      for (int i = 0; i < nodeList.size(); i++) {
        Node node = (Host) nodeList.get(i);
        node.setFailTimes(0); // failTimes和normalTimes用于计算今天的可用率
        node.setNormalTimes(0);
      }
      PerformanceDao dao = new PerformanceDao();
      try {
        dao.deleteData();
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        dao.close();
      }
    }
  }
Esempio n. 2
0
  /* (non-Javadoc)
   * @see com.dhcc.webnms.host.snmp.AbstractSnmp#collectData()
   */
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    // yangjun
    Hashtable returnHash = new Hashtable();
    Vector cpuVector = new Vector();
    List cpuList = new ArrayList();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return null;
    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;
      String temp = "0";
      try {
        // String temp = "0";
        String[] oids = new String[] {"1.3.6.1.4.1.94.1.21.1.7.1"};
        String[][] valueArray = null;
        valueArray =
            SnmpUtils.getCpuTableData(
                node.getIpAddress(), node.getCommunity(), oids, node.getSnmpversion(), 3, 1000);
        int allvalue = 0;
        int flag = 0;

        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            String _value = valueArray[i][0];
            String index = "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;
    }

    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 {
      AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
      List list =
          alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
              String.valueOf(node.getId()), "firewall", "nokia", "cpu");
      for (int i = 0; i < list.size(); i++) {
        AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(i);
        // 对CPU值进行告警检测
        CheckEventUtil checkutil = new CheckEventUtil();
        checkutil.updateData(node, collectHash, "firewall", "nokia", alarmIndicatorsnode);
        // }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    // 把结果转换成sql
    NetcpuResultTosql tosql = new NetcpuResultTosql();
    tosql.CreateResultTosql(returnHash, node.getIpAddress());
    NetHostDatatempCpuRTosql totempsql = new NetHostDatatempCpuRTosql();
    totempsql.CreateResultTosql(returnHash, node);
    return returnHash;
  }
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    Hashtable returnHash = new Hashtable();
    Vector tempVector = new Vector();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return returnHash;

    try {
      NetAppPlex netAppPlex = 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) {
        e.printStackTrace();
      }
      try {
        String[] oids =
            new String[] {
              ".1.3.6.1.4.1.789.1.6.11.1.1", // Plex索引
              ".1.3.6.1.4.1.789.1.6.11.1.2", // Plex标志名称
              ".1.3.6.1.4.1.789.1.6.11.1.3", // Plex所属Volume
              ".1.3.6.1.4.1.789.1.6.11.1.4", // Plex状态
              ".1.3.6.1.4.1.789.1.6.11.1.5", // plex 重建比例
            };

        String[][] valueArray = null;
        try {
          valueArray =
              SnmpUtils.getTableData(
                  node.getIpAddress(),
                  node.getCommunity(),
                  oids,
                  node.getSnmpversion(),
                  node.getSecuritylevel(),
                  node.getSecurityName(),
                  node.getV3_ap(),
                  node.getAuthpassphrase(),
                  node.getV3_privacy(),
                  node.getPrivacyPassphrase(),
                  3,
                  1000 * 30);
        } catch (Exception e) {
          valueArray = null;
        }
        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            netAppPlex = new NetAppPlex();
            netAppPlex.setIpaddress(node.getIpAddress());
            netAppPlex.setCollectTime(date);
            netAppPlex.setPlexIndex(valueArray[i][0]);
            netAppPlex.setPlexName(valueArray[i][1]);
            netAppPlex.setPlexVolName(valueArray[i][2]);
            netAppPlex.setPlexStatus(valueArray[i][3]);
            netAppPlex.setPlexPercentResyncing(valueArray[i][4]);
            tempVector.addElement(netAppPlex);
          }
        }
      } 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 (tempVector != null && tempVector.size() > 0) ipAllData.put("plex", tempVector);
      ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    } else {
      if (tempVector != null && tempVector.size() > 0)
        ((Hashtable) ShareData.getSharedata().get(node.getIpAddress())).put("plex", tempVector);
    }

    returnHash.put("plex", tempVector);

    tempVector = null;

    NetAppDataOperator op = new NetAppDataOperator();
    op.CreateResultTosql(returnHash, node.getIpAddress());

    return returnHash;
  }
  /* (non-Javadoc)
   * @see com.dhcc.webnms.host.snmp.AbstractSnmp#collectData()
   */
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    Hashtable returnHash = new Hashtable();
    Vector deviceVector = new Vector();
    List cpuList = new ArrayList();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    // 判断是否在采集时间段内
    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() + " 不在采集内存时间段内,退出##########");
          // 清除之前内存中产生的告警信息
          //    			    try{
          //    			    	//清除之前内存中产生的内存告警信息
          //						CheckEventUtil checkutil = new CheckEventUtil();
          //						checkutil.deleteEvent(node.getId()+":net:memory");
          //    			    }catch(Exception e){
          //    			    	e.printStackTrace();
          //    			    }
          return returnHash;
        }
      }
    }

    try {
      Devicecollectdata devicedata = 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) {

      }
      // -------------------------------------------------------------------------------------------device start
      try {
        String[] oids =
            new String[] {
              "1.3.6.1.2.1.25.3.2.1.1", // hrDeviceIndex
              "1.3.6.1.2.1.25.3.2.1.2", // hrDeviceType
              "1.3.6.1.2.1.25.3.2.1.3", // hrDeviceDescr
              "1.3.6.1.2.1.25.3.2.1.5"
            }; // hrDeviceStatus

        String[][] valueArray = null;
        try {
          // valueArray = SnmpUtils.getTableData(node.getIpAddress(), node.getCommunity(), oids,
          // node.getSnmpversion(), 3, 1000*30);
          valueArray =
              SnmpUtils.getTableData(
                  node.getIpAddress(),
                  node.getCommunity(),
                  oids,
                  node.getSnmpversion(),
                  node.getSecuritylevel(),
                  node.getSecurityName(),
                  node.getV3_ap(),
                  node.getAuthpassphrase(),
                  node.getV3_privacy(),
                  node.getPrivacyPassphrase(),
                  3,
                  1000 * 30);
        } catch (Exception e) {
          valueArray = null;
          // SysLogger.error(node.getIpAddress() + "_WindowsSnmp");
        }
        for (int i = 0; i < valueArray.length; i++) {
          devicedata = new Devicecollectdata();
          String devindex = valueArray[i][0];
          String type = valueArray[i][1];
          String name = valueArray[i][2];
          String status = valueArray[i][3];
          if (status == null) status = "";
          if (device_Status.containsKey(status)) status = (String) device_Status.get(status);
          devicedata.setDeviceindex(devindex);
          devicedata.setIpaddress(node.getIpAddress());
          devicedata.setName(name);
          devicedata.setStatus(status);
          devicedata.setType((String) device_Type.get(type));
          deviceVector.addElement(devicedata);
          // SysLogger.info(name+"######"+devindex+"######"+(String)device_Type.get(type)+"######"+status);

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

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

    if (!(ShareData.getSharedata().containsKey(node.getIpAddress()))) {
      Hashtable ipAllData = new Hashtable();
      if (ipAllData == null) ipAllData = new Hashtable();
      if (deviceVector != null && deviceVector.size() > 0) ipAllData.put("device", deviceVector);

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

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

    return returnHash;
  }
  /* (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;
  }
  /* (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;
  }
  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) {
    Hashtable returnHash = new Hashtable();
    Vector hardwareVector = new Vector();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return null;
    try {
      Systemcollectdata systemdata = 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) {
        SysLogger.info("HardWare collect:设备节点信息获取失败!");
        e.printStackTrace();
      }
      // -------------------------------------------------------------------------------------------HardWare
      // start
      try {
        final String[] desc = SnmpMibConstants.NetWorkMibHardwareDesc;
        final String[] chname = SnmpMibConstants.NetWorkMibHardwareChname;
        String[] oids =
            new String[] {
              "1.3.6.1.2.1.47.1.1.1.1.2.278",
              "1.3.6.1.2.1.47.1.1.1.1.2.279",
              "1.3.6.1.2.1.47.1.1.1.1.2.470",
              "1.3.6.1.2.1.47.1.1.1.1.2.471"
            };

        String[][] valueArray = null;
        try {
          valueArray = snmp.getTableData(node.getIpAddress(), node.getCommunity(), oids);
        } catch (Exception e) {
          valueArray = null;
        }
        if (valueArray != null && valueArray.length > 0) {
          for (int i = 0; i < valueArray.length; i++) {
            for (int j = 0; j < 6; j++) {
              systemdata = new Systemcollectdata();
              systemdata.setIpaddress(node.getIpAddress());
              systemdata.setCollecttime(date);
              systemdata.setCategory("device");
              systemdata.setEntity(desc[i]);
              systemdata.setSubentity(desc[j]);
              systemdata.setChname(chname[j]);
              systemdata.setRestype("static");
              systemdata.setUnit("");
              String value = valueArray[i][j];
              if (j == 0) {
                systemdata.setThevalue(value);
              } else systemdata.setThevalue(value);
              hardwareVector.addElement(systemdata);
            }
          }
        }
      } catch (Exception e) {
        // e.printStackTrace();
        SysLogger.info("HardWare collect:error!");
      }
      // -------------------------------------------------------------------------------------------system
      // end

      // -------------------------------------------------------------------------------------------mac
      // start
      // try{
      //
      // String[] oids =
      // new String[] {
      // "1.3.6.1.2.1.2.2.1.6"
      // };
      // String[][] valueArray = null;
      // try {
      // valueArray =
      // snmp.getTableData(node.getIpAddress(),node.getCommunity(),oids);
      // } catch(Exception e){
      // valueArray = null;
      // //SysLogger.error(node.getIpAddress() + "_WindowsSnmp");
      // }
      // systemdata=new Systemcollectdata();
      // systemdata.setIpaddress(node.getIpAddress());
      // systemdata.setCollecttime(date);
      // systemdata.setCategory("System");
      // systemdata.setEntity("MacAddr");
      // systemdata.setSubentity("MacAddr");
      // systemdata.setRestype("static");
      // systemdata.setUnit(" ");
      // if(valueArray != null){
      // for(int i=0;i<valueArray.length;i++){
      // String value=valueArray[i][0];
      // if (value == null || value.length()==0)continue;
      // systemdata.setThevalue(value);
      // break;
      // }
      // }
      // systemVector.addElement(systemdata);
      //
      // }
      // catch(Exception e){
      // //e.printStackTrace();
      // }
      // -------------------------------------------------------------------------------------------mac
      // end

    } catch (Exception e) {
      // returnHash=null;
      // e.printStackTrace();
      // return null;
    } finally {
      // System.gc();
    }

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

    if (!(ShareData.getSharedata().containsKey(node.getIpAddress()))) {
      Hashtable ipAllData = new Hashtable();
      if (ipAllData == null) ipAllData = new Hashtable();
      if (hardwareVector != null && hardwareVector.size() > 0)
        ipAllData.put("device", hardwareVector);

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

    return returnHash;
  }
Esempio n. 9
0
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    Hashtable returnHash = new Hashtable();
    Vector processVector = new Vector();
    Host host =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (host == null) {
      return returnHash;
    }
    try {
      ProcessCollectEntity processdata = new ProcessCollectEntity();
      Calendar date = Calendar.getInstance();
      Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(host.getIpAddress());
      if (ipAllData == null) {
        ipAllData = new Hashtable();
      }
      try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        com.afunms.polling.base.Node snmpnode =
            PollingEngine.getInstance().getNodeByIP(host.getIpAddress());
        Date cc = date.getTime();
        String time = sdf.format(cc);
        snmpnode.setLastTime(time);
      } catch (Exception e) {
        e.printStackTrace();
      }
      try {

        String[] oids =
            new String[] {
              "1.3.6.1.2.1.25.4.2.1.1",
              "1.3.6.1.2.1.25.4.2.1.2",
              "1.3.6.1.2.1.25.4.2.1.5",
              "1.3.6.1.2.1.25.4.2.1.6",
              "1.3.6.1.2.1.25.4.2.1.7",
              "1.3.6.1.2.1.25.5.1.1.2",
              "1.3.6.1.2.1.25.5.1.1.1",
            };
        String[][] valueArray1 = null;
        try {
          valueArray1 =
              SnmpUtils.getTableData(
                  host.getIpAddress(),
                  host.getCommunity(),
                  oids,
                  host.getSnmpversion(),
                  host.getSecuritylevel(),
                  host.getSecurityName(),
                  host.getV3_ap(),
                  host.getAuthpassphrase(),
                  host.getV3_privacy(),
                  host.getPrivacyPassphrase(),
                  3,
                  1000 * 30);
        } catch (Exception e) {
          e.printStackTrace();
          valueArray1 = null;
        }
        int allMemorySize = 0;
        if (valueArray1 != null) {
          for (int i = 0; i < valueArray1.length; i++) {
            String svb0 = valueArray1[i][0];
            if (svb0 == null) {
              continue;
            }
            allMemorySize = Integer.parseInt(svb0);
          }
        }

        String[][] valueArray = null;
        try {
          valueArray = snmp.getTableData(host.getIpAddress(), host.getCommunity(), oids);
        } catch (Exception e) {
          e.printStackTrace();
          valueArray = null;
        }

        List procslist = new ArrayList();
        ProcsDao procsdao = new ProcsDao();
        try {
          procslist = procsdao.loadByIp(host.getIpAddress());
        } catch (Exception ex) {
          ex.printStackTrace();
        } finally {
          procsdao.close();
        }

        Hashtable procshash = new Hashtable();
        Vector procsV = new Vector();
        if (procslist != null && procslist.size() > 0) {
          for (int i = 0; i < procslist.size(); i++) {
            Procs procs = (Procs) procslist.get(i);
            procshash.put(procs.getProcname(), procs);
            procsV.add(procs.getProcname());
          }
        }
        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            if (allMemorySize != 0) {
              String vbstring0 = valueArray[i][0];
              String vbstring1 = valueArray[i][1];
              String vbstring2 = valueArray[i][2];
              String vbstring3 = valueArray[i][3];
              String vbstring4 = valueArray[i][4];
              String vbstring5 = valueArray[i][5];
              String vbstring6 = valueArray[i][6];
              String processIndex = vbstring0.trim();

              float value = 0.0f;
              value = Integer.parseInt(vbstring5.trim()) * 100.0f / allMemorySize;

              String processName = vbstring1.trim();

              processdata = new ProcessCollectEntity();
              processdata.setIpaddress(host.getIpAddress());
              processdata.setCollecttime(date);
              processdata.setCategory("Process");
              processdata.setEntity("MemoryUtilization");
              processdata.setSubentity(processIndex);
              processdata.setRestype("dynamic");
              processdata.setUnit("%");
              processdata.setThevalue(Float.toString(value));
              processdata.setChname(processName);
              processVector.addElement(processdata);

              String processMemory = vbstring5.trim();
              processdata = new ProcessCollectEntity();
              processdata.setIpaddress(host.getIpAddress());
              processdata.setCollecttime(date);
              processdata.setCategory("Process");
              processdata.setEntity("Memory");
              processdata.setSubentity(processIndex);
              processdata.setRestype("static");
              processdata.setUnit("K");
              processdata.setThevalue(processMemory);
              processdata.setChname(processName);
              processVector.addElement(processdata);

              String processType = vbstring3.trim();
              processdata = new ProcessCollectEntity();
              processdata.setIpaddress(host.getIpAddress());
              processdata.setCollecttime(date);
              processdata.setCategory("Process");
              processdata.setEntity("Type");
              processdata.setSubentity(processIndex);
              processdata.setRestype("static");
              processdata.setUnit(" ");
              processdata.setThevalue(HOST_hrSWRun_hrSWRunType.get(processType).toString());
              processdata.setChname(processName);
              processVector.addElement(processdata);

              String processPath = vbstring2.trim();
              processdata = new ProcessCollectEntity();
              processdata.setIpaddress(host.getIpAddress());
              processdata.setCollecttime(date);
              processdata.setCategory("Process");
              processdata.setEntity("Path");
              processdata.setSubentity(processIndex);
              processdata.setRestype("static");
              processdata.setUnit(" ");
              processdata.setThevalue(processPath);
              processdata.setChname(processName);
              processVector.addElement(processdata);

              String processStatus = vbstring4.trim();
              processdata = new ProcessCollectEntity();
              processdata.setIpaddress(host.getIpAddress());
              processdata.setCollecttime(date);
              processdata.setCategory("Process");
              processdata.setEntity("Status");
              processdata.setSubentity(processIndex);
              processdata.setRestype("static");
              processdata.setUnit(" ");
              processdata.setThevalue(HOST_hrSWRun_hrSWRunStatus.get(processStatus).toString());
              processdata.setChname(processName);
              processVector.addElement(processdata);

              processdata = new ProcessCollectEntity();
              processdata.setIpaddress(host.getIpAddress());
              processdata.setCollecttime(date);
              processdata.setCategory("Process");
              processdata.setEntity("Name");
              processdata.setSubentity(processIndex);
              processdata.setRestype("static");
              processdata.setUnit(" ");
              processdata.setThevalue(processName);
              processVector.addElement(processdata);

              String processCpu = vbstring6.trim();
              processdata = new ProcessCollectEntity();
              processdata.setIpaddress(host.getIpAddress());
              processdata.setCollecttime(date);
              processdata.setCategory("Process");
              processdata.setEntity("CpuTime");
              processdata.setSubentity(processIndex);
              processdata.setRestype("static");
              processdata.setUnit("秒");
              processdata.setThevalue(Integer.toString((Integer.parseInt(processCpu) / 100)));
              processdata.setChname(processName);
              processVector.addElement(processdata);

              // 判断是否有需要监视的进程,若取得的列表里包含监视进程,则从Vector里去掉
              if (procsV != null && procsV.size() > 0) {
                if (procsV.contains(processName)) {
                  procsV.remove(processName);
                  // 判断已经发送的进程短信列表里是否有该进程,若有,则从已发送列表里去掉该短信信息
                  if (sendeddata.containsKey(host + ":" + processName)) {
                    sendeddata.remove(host + ":" + processName);
                  }
                  // 判断进程丢失列表里是否有该进程,若有,则从该列表里去掉该信息
                  Hashtable iplostprocdata = ShareData.getLostprocdata(host.getIpAddress());
                  if (iplostprocdata == null) {
                    iplostprocdata = new Hashtable();
                  }
                  if (iplostprocdata.containsKey(processName)) {
                    iplostprocdata.remove(processName);
                    ShareData.setLostprocdata(host.getIpAddress(), iplostprocdata);
                  }
                }
              }
            } else {
              throw new Exception("Process is 0");
            }
          }
        }

        // 判断ProcsV里还有没有需要监视的进程,若有,则说明当前没有启动该进程,则用命令重新启动该进程,同时写入事件
        Vector eventtmpV = new Vector();
        if (procsV != null && procsV.size() > 0) {
          for (int i = 0; i < procsV.size(); i++) {
            Procs procs = (Procs) procshash.get(procsV.get(i));

            Hashtable iplostprocdata = ShareData.getLostprocdata(host.getIpAddress());
            if (iplostprocdata == null) {
              iplostprocdata = new Hashtable();
            }
            iplostprocdata.put(procs.getProcname(), procs);
            ShareData.setLostprocdata(host.getIpAddress(), iplostprocdata);
            EventList eventlist = new EventList();
            eventlist.setEventtype("poll");
            eventlist.setEventlocation(host.getSysLocation());
            eventlist.setContent(procs.getProcname() + "进程丢失");
            eventlist.setLevel1(1);
            eventlist.setManagesign(0);
            eventlist.setBak("");
            eventlist.setRecordtime(Calendar.getInstance());
            eventlist.setReportman("系统轮询");
            eventlist.setEventlocation(host.getAlias() + "(" + host.getIpAddress() + ")");
            NodeToBusinessDao ntbdao = new NodeToBusinessDao();
            List ntblist = new ArrayList();
            try {
              ntblist = ntbdao.loadByNodeAndEtype(host.getId(), "equipment");
            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              ntbdao.close();
            }
            String bids = ",";
            if (ntblist != null && ntblist.size() > 0) {

              for (int k = 0; k < ntblist.size(); k++) {
                NodeToBusiness ntb = (NodeToBusiness) ntblist.get(k);
                bids = bids + ntb.getBusinessid() + ",";
              }
            }
            eventlist.setBusinessid(bids);
            eventlist.setNodeid(host.getId());
            eventlist.setOid(0);
            eventlist.setSubtype("host");
            eventlist.setSubentity("proc");
            EventListDao eventlistdao = new EventListDao();
            eventlistdao.save(eventlist);
            eventtmpV.add(eventlist);
            // 发送手机短信并写事件和声音告警
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (!(ShareData.getSharedata().containsKey(host.getIpAddress()))) {
      Hashtable ipAllData = new Hashtable();
      if (ipAllData == null) {
        ipAllData = new Hashtable();
      }
      if (processVector != null && processVector.size() > 0) {
        ipAllData.put("process", processVector);
      }
      ShareData.getSharedata().put(host.getIpAddress(), ipAllData);
    } else {
      if (processVector != null && processVector.size() > 0) {
        ((Hashtable) ShareData.getSharedata().get(host.getIpAddress()))
            .put("process", processVector);
      }
    }
    returnHash.put("process", processVector);
    processVector = null;
    List proEventList = new ArrayList();
    boolean alarm = false;
    try {
      if (processVector != null && processVector.size() > 0) {
        AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
        List list =
            alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                host.getId() + "", "host", "windows");
        AlarmIndicatorsNode alarmIndicatorsNode2 = null;
        if (list == null) {
          for (int i = 0; i < list.size(); i++) {
            AlarmIndicatorsNode alarmIndicatorsNode2_per = (AlarmIndicatorsNode) list.get(i);
            if (alarmIndicatorsNode2_per != null
                && "process".equals(alarmIndicatorsNode2_per.getName())) {
              alarmIndicatorsNode2 = alarmIndicatorsNode2_per;
              break;
            }
          }
          CheckEventUtil checkutil = new CheckEventUtil();
          proEventList =
              checkutil.createProcessGroupEventList(
                  host.getIpAddress(), processVector, alarmIndicatorsNode2);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (proEventList != null && proEventList.size() > 0) {
      alarm = true;
    }
    if (alarm) {
      Host node = (Host) PollingEngine.getInstance().getNodeByID(host.getId());
      StringBuffer msg = new StringBuffer(200);
      msg.append("<font color='red'>--报警信息:--</font><br>");
      msg.append(node.getAlarmMessage().toString());
      if (proEventList != null && proEventList.size() > 0) {
        for (int i = 0; i < proEventList.size(); i++) {
          EventList eventList = (EventList) proEventList.get(i);
          msg.append(eventList.getContent() + "<br>");
          if (eventList.getLevel1() > node.getAlarmlevel()) {
            node.setAlarmlevel(eventList.getLevel1());
          }
        }
      }
      node.getAlarmMessage().clear();
      node.getAlarmMessage().add(msg.toString());
      node.setStatus(node.getAlarmlevel());
      node.setAlarm(true);
    }
    String runmodel = PollingEngine.getCollectwebflag(); // 采集与访问模式
    if (!"0".equals(runmodel)) {
      HostDatatempProcessRtTosql temptosql = new HostDatatempProcessRtTosql();
      temptosql.CreateResultTosql(returnHash, host);
    }

    return returnHash;
  }
Esempio n. 10
0
  /**
   * 根据 psTypeVo 来组装 中间件
   *
   * @param psTypeVo
   * @return
   */
  public MonitorServiceDTO getMonitorServiceDTOByPSTypeVo(PSTypeVo psTypeVo) {

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String date = simpleDateFormat.format(new Date());

    String starttime = date + " 00:00:00";
    String totime = date + " 23:59:59";

    int id = psTypeVo.getId();
    String alias = psTypeVo.getPort();
    String ipAddress = psTypeVo.getIpaddress();
    String category = "portService";

    Node psTypeVoNode = PollingEngine.getInstance().getSocketByID(id);

    int status = 0;
    try {
      status = psTypeVoNode.getStatus();
    } catch (RuntimeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Hashtable eventListSummary = new Hashtable();

    String generalAlarm = "0"; // 普通告警数  默认为 0
    String urgentAlarm = "0"; // 严重告警数  默认为 0
    String seriousAlarm = "0"; // 紧急告警数  默认为 0

    EventListDao eventListDao = new EventListDao();
    try {
      generalAlarm =
          eventListDao.getCountByWhere(
              " where nodeid='"
                  + id
                  + "'"
                  + " and level1='1' and recordtime>='"
                  + starttime
                  + "' and recordtime<='"
                  + totime
                  + "'");
      urgentAlarm =
          eventListDao.getCountByWhere(
              " where nodeid='"
                  + id
                  + "'"
                  + " and level1='2' and recordtime>='"
                  + starttime
                  + "' and recordtime<='"
                  + totime
                  + "'");
      seriousAlarm =
          eventListDao.getCountByWhere(
              " where nodeid='"
                  + id
                  + "'"
                  + " and level1='3' and recordtime>='"
                  + starttime
                  + "' and recordtime<='"
                  + totime
                  + "'");
    } catch (RuntimeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      eventListDao.close();
    }
    eventListSummary.put("generalAlarm", generalAlarm);
    eventListSummary.put("urgentAlarm", urgentAlarm);
    eventListSummary.put("seriousAlarm", seriousAlarm);

    String monflag = "否";
    if (psTypeVo.getMonflag() == 1) {
      monflag = "是";
    }

    MonitorServiceDTO monitorServiceDTO = new MonitorServiceDTO();
    monitorServiceDTO.setId(id);
    monitorServiceDTO.setStatus(String.valueOf(status));
    monitorServiceDTO.setAlias(alias);
    monitorServiceDTO.setIpAddress(ipAddress);
    monitorServiceDTO.setPingValue("");
    monitorServiceDTO.setCategory(category);
    monitorServiceDTO.setEventListSummary(eventListSummary);
    monitorServiceDTO.setMonflag(monflag);
    return monitorServiceDTO;
  }
Esempio n. 11
0
  /**
   * 根据 ftpConfig 来组装 中间件
   *
   * @param ftpConfig
   * @return
   */
  public MonitorServiceDTO getMonitorServiceDTOByFtp(FTPConfig ftpConfig) {

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String date = simpleDateFormat.format(new Date());

    String starttime = date + " 00:00:00";
    String totime = date + " 23:59:59";

    int id = ftpConfig.getId();
    String alias = ftpConfig.getName();
    String ipAddress = ftpConfig.getIpaddress();
    String category = "ftp";

    Node ftpNode = PollingEngine.getInstance().getFtpByID(id);

    int status = 0;
    try {
      status = ftpNode.getStatus();
    } catch (RuntimeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    Hashtable eventListSummary = new Hashtable();

    String generalAlarm = "0"; // 普通告警数  默认为 0
    String urgentAlarm = "0"; // 严重告警数  默认为 0
    String seriousAlarm = "0"; // 紧急告警数  默认为 0

    Ftpmonitor_historyDao ftpmonitor_historyDao = new Ftpmonitor_historyDao();
    try {
      seriousAlarm =
          ftpmonitor_historyDao.getCountByWhere(
              " where ftp_id='"
                  + id
                  + "'"
                  + " and is_canconnected='0' and mon_time>='"
                  + starttime
                  + "' and mon_time<='"
                  + totime
                  + "'");
    } catch (RuntimeException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      ftpmonitor_historyDao.close();
    }
    eventListSummary.put("generalAlarm", generalAlarm);
    eventListSummary.put("urgentAlarm", urgentAlarm);
    eventListSummary.put("seriousAlarm", seriousAlarm);

    String monflag = "否";
    if (ftpConfig.getMonflag() == 1) {
      monflag = "是";
    }

    MonitorServiceDTO monitorServiceDTO = new MonitorServiceDTO();
    monitorServiceDTO.setId(id);
    monitorServiceDTO.setStatus(String.valueOf(status));
    monitorServiceDTO.setAlias(alias);
    monitorServiceDTO.setIpAddress(ipAddress);
    monitorServiceDTO.setPingValue("");
    monitorServiceDTO.setCategory(category);
    monitorServiceDTO.setEventListSummary(eventListSummary);
    monitorServiceDTO.setMonflag(monflag);
    return monitorServiceDTO;
  }
Esempio n. 12
0
  /* (non-Javadoc)
   * @see com.dhcc.webnms.host.snmp.AbstractSnmp#collectData()
   */
  public Hashtable collect_Data(NodeGatherIndicators alarmIndicatorsNode) {
    Hashtable returnHash = new Hashtable();
    Vector diskVector = new Vector();
    List cpuList = new ArrayList();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));

    try {
      Diskcollectdata diskdata = null;
      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) {

      }
      // -------------------------------------------------------------------------------------------disk start
      try {
        String[] oids =
            new String[] {
              "1.3.6.1.2.1.25.2.3.1.1",
              "1.3.6.1.2.1.25.2.3.1.2",
              "1.3.6.1.2.1.25.2.3.1.3",
              "1.3.6.1.2.1.25.2.3.1.4",
              "1.3.6.1.2.1.25.2.3.1.5",
              "1.3.6.1.2.1.25.2.3.1.6",
              "1.3.6.1.2.1.25.2.3.1.7"
            };

        String[][] valueArray = null;
        try {
          valueArray =
              SnmpUtils.getTableData(
                  node.getIpAddress(),
                  node.getCommunity(),
                  oids,
                  node.getSnmpversion(),
                  3,
                  1000 * 30);
        } catch (Exception e) {
          valueArray = null;
          SysLogger.error(node.getIpAddress() + "_WindowsDiskSnmp");
        }
        for (int i = 0; i < valueArray.length; i++) {
          diskdata = new Diskcollectdata();
          diskdata.setIpaddress(node.getIpAddress());
          diskdata.setCollecttime(date);
          diskdata.setCategory("Disk");
          diskdata.setEntity("Utilization");
          diskdata.setRestype("static");
          diskdata.setUnit("%");
          String descriptions = valueArray[i][2];
          String byteunit = valueArray[i][3];
          String desc = "";
          if (descriptions == null) descriptions = "";
          if (descriptions.indexOf("Memory") >= 0) {
          } else {
            if (descriptions.trim().length() > 2) {
              desc = descriptions.substring(0, 3);
            }
          }
          if (descriptions.indexOf("\\") >= 0) {
            desc = desc.replace("\\", "/");
          }
          diskdata.setSubentity(desc);
          float value = 0.0f;
          String svb4 = valueArray[i][4];
          String svb5 = valueArray[i][5];
          int allsize = Integer.parseInt(svb4.trim());
          int used = Integer.parseInt(svb5.trim());
          if (allsize != 0) {
            value = used * 100.0f / allsize;
          } else {
            value = 0.0f;
          }
          diskdata.setThevalue(Float.toString(value));

          if (diskdata.getSubentity().equals("Physical Memory")) {
          } else if (diskdata.getSubentity().equals("Virtual Memory")) {
          } else {
            if (diskdata.getSubentity().trim().length() > 0) {
              // SysLogger.info(diskdata.getSubentity()+"===="+diskdata.getThevalue());
              diskVector.addElement(diskdata);
            }
          }

          diskdata = new Diskcollectdata();
          diskdata.setIpaddress(node.getIpAddress());
          diskdata.setCollecttime(date);
          diskdata.setCategory("Disk");
          diskdata.setEntity("AllSize");
          diskdata.setRestype("static");
          diskdata.setSubentity(desc);
          float size = 0.0f;
          size = allsize * Long.parseLong(byteunit) * 1.0f / 1024 / 1024;
          String unit = "";
          if (size >= 1024.0f) {
            size = size / 1024;
            diskdata.setUnit("G");
            unit = "G";
          } else {
            diskdata.setUnit("M");
            unit = "M";
          }
          diskdata.setThevalue(Float.toString(size));
          if (diskdata.getSubentity().equals("Virtual Memory")) {}

          if (!diskdata.getSubentity().equals("Physical Memory")
              && !diskdata.getSubentity().equals("Virtual Memory")
              && diskdata.getSubentity().trim().length() > 0) {
            diskVector.addElement(diskdata);
          }
          diskdata = new Diskcollectdata();
          diskdata.setIpaddress(node.getIpAddress());
          diskdata.setCollecttime(date);
          diskdata.setCategory("Disk");
          diskdata.setEntity("UsedSize");
          diskdata.setRestype("static");
          diskdata.setSubentity(desc);
          size = used * Long.parseLong(byteunit) * 1.0f / 1024 / 1024;
          if ("G".equals(unit)) {
            size = size / 1024;
            diskdata.setUnit("G");
          } else {
            diskdata.setUnit("M");
          }
          diskdata.setThevalue(Float.toString(size));
          if (!diskdata.getSubentity().equals("Physical Memory")
              && !diskdata.getSubentity().equals("Virtual Memory")
              && diskdata.getSubentity().trim().length() > 0) {
            diskVector.addElement(diskdata);
          }
          try {
            String diskinc = "0.0";
            float pastutil = 0.0f;
            Vector disk_v = (Vector) ipAllData.get("disk");
            if (disk_v != null && disk_v.size() > 0) {
              for (int si = 0; si < disk_v.size(); si++) {
                Diskcollectdata disk_data = (Diskcollectdata) disk_v.elementAt(si);
                if ((desc).equals(disk_data.getSubentity())
                    && "Utilization".equals(disk_data.getEntity())) {
                  pastutil = Float.parseFloat(disk_data.getThevalue());
                }
              }
            } else {
              pastutil = value;
            }
            if (pastutil == 0) {
              pastutil = value;
            }
            if (value - pastutil > 0) {
              diskinc = (value - pastutil) + "";
            }
            // System.out.println("diskinc------------------"+diskinc);
            diskdata = new Diskcollectdata();
            diskdata.setIpaddress(node.getIpAddress());
            diskdata.setCollecttime(date);
            diskdata.setCategory("Disk");
            diskdata.setEntity("UtilizationInc"); // 利用增长率百分比
            diskdata.setSubentity(desc);
            diskdata.setRestype("dynamic");
            diskdata.setUnit("%");
            diskdata.setThevalue(diskinc);
            if (diskdata.getSubentity().equals("Physical Memory")
                || diskdata.getSubentity().equals("Virtual Memory")) {

            } else {
              if (diskdata.getSubentity().trim().length() > 0) {

                diskVector.addElement(diskdata);
              }
            }
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      } catch (Exception e) {
        // e.printStackTrace();
      }
      // --------------------------------------------------------------------------------------disk
      // 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();
    //		ipAllData.put("disk",diskVector);
    //	    ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    //	    returnHash.put("disk", diskVector);

    if (!(ShareData.getSharedata().containsKey(node.getIpAddress()))) {
      Hashtable ipAllData = new Hashtable();
      if (ipAllData == null) ipAllData = new Hashtable();
      if (diskVector != null && diskVector.size() > 0) ipAllData.put("disk", diskVector);

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

    // 进行磁盘告警检测
    // SysLogger.info("### 开始运行检测磁盘是否告警### ... ###");
    try {
      AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
      List list =
          alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
              String.valueOf(node.getId()), AlarmConstant.TYPE_HOST, "windows");
      for (int i = 0; i < list.size(); i++) {
        AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(i);
        // SysLogger.info("alarmIndicatorsnode name ======"+alarmIndicatorsnode.getName());
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("diskperc")) {
          CheckEventUtil checkutil = new CheckEventUtil();
          checkutil.checkDisk(node, diskVector, alarmIndicatorsnode);
          break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // 进行磁盘告警检测
    // SysLogger.info("### 开始运行检测磁盘是否告警### ... ###");
    try {
      AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
      List list =
          alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
              String.valueOf(node.getId()), AlarmConstant.TYPE_HOST, "windows");
      for (int i = 0; i < list.size(); i++) {
        AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(i);
        // SysLogger.info("alarmIndicatorsnode name ======"+alarmIndicatorsnode.getName());
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("diskinc")) {
          CheckEventUtil checkutil = new CheckEventUtil();
          checkutil.checkDisk(node, diskVector, alarmIndicatorsnode);
          break;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

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

    HostDatatempDiskRttosql temptosql = new HostDatatempDiskRttosql();
    temptosql.CreateResultTosql(returnHash, node);

    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;
  }