Exemplo n.º 1
0
  public Hashtable collect_Data(
      NodeGatherIndicators alarmIndicatorsNode) { // Òª¸ÄΪAlarmIndicatorsNode alarmIndicatorsNode
    Hashtable returnHash = new Hashtable();
    Vector powerVector = new Vector();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return null;
    try {

      Calendar date = Calendar.getInstance();
      Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(node.getIpAddress());
      if (ipAllData == null) ipAllData = new Hashtable();

      try {
        String temp = "0";
        String[][] valueArray = null;
        String[] oids = new String[] {"1.3.6.1.4.1.7564.30.2", "1.3.6.1.4.1.7564.30.3"};

        valueArray =
            SnmpUtils.getTableData(
                node.getIpAddress(), node.getCommunity(), oids, node.getSnmpversion(), 3, 1000);
        int flag = 0;
        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            ArrayVPNSystem arrayVPNSystem = new ArrayVPNSystem();
            String connectionsPerSec = valueArray[i][0];
            String requestsPerSec = valueArray[i][1];

            arrayVPNSystem.setRequestsPerSec(Integer.parseInt(requestsPerSec));
            arrayVPNSystem.setConnectionsPerSec(Integer.parseInt(connectionsPerSec));

            arrayVPNSystem.setIpaddress(node.getIpAddress());
            arrayVPNSystem.setCollecttime(date);
            arrayVPNSystem.setType("NET");
            arrayVPNSystem.setSubtype("ArrayNetworks");
            SysLogger.info( // "cpuUtilization:"+cpuUtilization
                "   connectionsPerSec:"
                    + connectionsPerSec
                    + "  requestsPerSec :"
                    + requestsPerSec);
            powerVector.addElement(arrayVPNSystem);
          }
        }
      } catch (Exception e) {
      }
    } catch (Exception e) {
    }

    Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(node.getIpAddress());
    if (ipAllData == null) ipAllData = new Hashtable();
    ipAllData.put("VPNSystem", powerVector);
    ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    returnHash.put("VPNSystem", powerVector);
    return returnHash;
  }
 public boolean delete(String[] ids) {
   if (ids != null && ids.length > 0) {
     GgsciConfigDao ggscidao = new GgsciConfigDao();
     List list = ggscidao.loadAll();
     if (list == null) list = new ArrayList();
     ShareData.setDpconfiglist(list);
     clearRubbish(list);
   }
   return super.delete(ids);
 }
Exemplo n.º 3
0
 @Override
 public void loading() {
   NasConfigDao dao = new NasConfigDao();
   List list = null;
   try {
     list = dao.loadAll();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     dao.close();
   }
   if (list == null) {
     list = new ArrayList();
   }
   ShareData.setNasconfiglist(list);
   clearRubbish(list);
   for (int i = 0; i < list.size(); i++) {
     NasConfig vo = (NasConfig) list.get(i);
     loadOne(vo);
   }
 }
  public void collect_data(String id, Hashtable gatherHash) {

    Hashtable data_ht = new Hashtable();
    String jvm_utilization = "0";
    try {
      ServerStream serverstream = new ServerStream();
      Hashtable returnVal = new Hashtable();
      String ipaddress = "";
      Tomcat node = new Tomcat();
      TomcatDao dao = new TomcatDao();
      try {
        node = (Tomcat) dao.findByID(id);
      } catch (Exception e) {
      } finally {
        dao.close();
      }
      try {
        com.afunms.polling.node.Tomcat tc = new com.afunms.polling.node.Tomcat();
        BeanUtils.copyProperties(tc, node);
        ipaddress = tc.getIpAddress();
        com.afunms.polling.node.Tomcat tnode =
            (com.afunms.polling.node.Tomcat) PollingEngine.getInstance().getTomcatByIP(ipaddress);
        Calendar date = Calendar.getInstance();
        Date cc = date.getTime();
        String tempsenddate = sdf.format(cc);
        // 初始化Tomcat服务的状态
        tnode.setLastTime(tempsenddate);
        tnode.setAlarm(false);
        tnode.getAlarmMessage().clear();
        tnode.setStatus(0);

        StringBuffer tmp = new StringBuffer();
        tmp.append(tc.getIpAddress());
        tmp.append(",");
        tmp.append(tc.getPort());
        tmp.append(",");
        tmp.append(tc.getUser());
        tmp.append(" , ");
        tmp.append(tc.getPassword());
        returnVal.put(String.valueOf(0), tmp.toString());
      } catch (Exception e) {
        e.printStackTrace();
      }

      String liststr = serverstream.validServer(returnVal);
      if ("".equals(liststr)) {

        try {
          com.afunms.polling.node.Tomcat tc = new com.afunms.polling.node.Tomcat();
          BeanUtils.copyProperties(tc, node);
          // if (data_ht==null){
          // 需要增加邮件服务所在的服务器是否能连通
          Host host = (Host) PollingEngine.getInstance().getNodeByIP(node.getIpAddress());
          Vector ipPingData = (Vector) ShareData.getPingdata().get(node.getIpAddress());
          if (ipPingData != null) {
            Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0);
            Calendar tempCal = (Calendar) pingdata.getCollecttime();
            Date cc = tempCal.getTime();
            String _time = sdf.format(cc);
            String lastTime = _time;
            String pingvalue = pingdata.getThevalue();
            if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0";
            double pvalue = new Double(pingvalue);
            if (pvalue == 0) {
              // 主机服务器连接不上***********************************************
              com.afunms.polling.node.Tomcat tnode =
                  (com.afunms.polling.node.Tomcat)
                      PollingEngine.getInstance().getTomcatByIP(ipaddress);
              tnode.setAlarm(true);
              tnode.setStatus(1);
              List alarmList = tnode.getAlarmMessage();
              if (alarmList == null) alarmList = new ArrayList();
              tnode.getAlarmMessage().add("TOMCAT服务停止");
              String sysLocation = "";
              try {
                SmscontentDao eventdao = new SmscontentDao();
                String eventdesc =
                    "TOMCAT服务("
                        + tnode.getAlias()
                        + " IP:"
                        + tnode.getAdminIp()
                        + ")"
                        + "的TOMCAT服务停止";
                eventdao.createEventWithReasion(
                    "poll",
                    tnode.getId() + "",
                    tnode.getAdminIp() + "(" + tnode.getAdminIp() + ")",
                    eventdesc,
                    3,
                    "tomcat",
                    "ping",
                    "所在的服务器连接不上");
              } catch (Exception e) {
                e.printStackTrace();
              }
            } else {
              com.afunms.polling.node.Tomcat tnode =
                  (com.afunms.polling.node.Tomcat)
                      PollingEngine.getInstance().getTomcatByIP(ipaddress);
              tnode.setAlarm(true);
              tnode.setStatus(3);
              List alarmList = tnode.getAlarmMessage();
              if (alarmList == null) alarmList = new ArrayList();
              tnode.getAlarmMessage().add("TOMCAT服务停止");
              Pingcollectdata hostdata = null;
              hostdata = new Pingcollectdata();
              hostdata.setIpaddress(ipaddress);
              Calendar date = Calendar.getInstance();
              hostdata.setCollecttime(date);
              hostdata.setCategory("TomcatPing");
              hostdata.setEntity("Utilization");
              hostdata.setSubentity("ConnectUtilization");
              hostdata.setRestype("dynamic");
              hostdata.setUnit("%");
              hostdata.setThevalue("0");
              TomcatDao tomcatdao = new TomcatDao();
              try {
                tomcatdao.createHostData(hostdata);
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                tomcatdao.close();
              }
            }

          } else {
            com.afunms.polling.node.Tomcat tnode =
                (com.afunms.polling.node.Tomcat)
                    PollingEngine.getInstance().getTomcatByIP(ipaddress);
            tnode.setAlarm(true);
            tnode.setStatus(3);
            List alarmList = tnode.getAlarmMessage();
            if (alarmList == null) alarmList = new ArrayList();
            tnode.getAlarmMessage().add("TOMCAT服务停止");
            Pingcollectdata hostdata = null;
            hostdata = new Pingcollectdata();
            hostdata.setIpaddress(ipaddress);
            Calendar date = Calendar.getInstance();
            hostdata.setCollecttime(date);
            hostdata.setCategory("TomcatPing");
            hostdata.setEntity("Utilization");
            hostdata.setSubentity("ConnectUtilization");
            hostdata.setRestype("dynamic");
            hostdata.setUnit("%");
            hostdata.setThevalue("0");
            TomcatDao tomcatdao = new TomcatDao();
            try {
              tomcatdao.createHostData(hostdata);
            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              tomcatdao.close();
            }
          }
          // }
          createSMS("tomcat", tc);
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else {
        Pingcollectdata hostdata = null;
        hostdata = new Pingcollectdata();
        hostdata.setIpaddress(ipaddress);
        Calendar date = Calendar.getInstance();
        hostdata.setCollecttime(date);
        hostdata.setCategory("TomcatPing");
        hostdata.setEntity("Utilization");
        hostdata.setSubentity("ConnectUtilization");
        hostdata.setRestype("dynamic");
        hostdata.setUnit("%");
        hostdata.setThevalue("100");
        TomcatDao tomcatdao = new TomcatDao();
        try {
          tomcatdao.createHostData(hostdata);
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          tomcatdao.close();
        }
      }
      String[] pos_s = liststr.split(",");
      for (int list_i = 0; list_i < pos_s.length - 1; list_i++) {
        String tmps = returnVal.get(pos_s[list_i]).toString();
        String[] serverinfo = tmps.split(",");
        serverstream.foundData(serverinfo[0], serverinfo[1], serverinfo[2], serverinfo[3]);
        data_ht = serverstream.data_ht;
        TomcatDao tomcatdao = new TomcatDao();
        Hashtable sendeddata = ShareData.getSendeddata();

        try {
          Calendar time = Calendar.getInstance();
          String lasttime = data_ht.get("mon_time").toString();
          String nexttime = data_ht.get("nexttime").toString();

          String server = data_ht.get("server").toString();
          String jvm = data_ht.get("jvm").toString();

          String ip = data_ht.get("ip").toString();
          String port = data_ht.get("port").toString();
          String portsum1 = data_ht.get("portsum1").toString();
          String portsum2 = data_ht.get("portsum2").toString();
          String portdetail1 = data_ht.get("portdetail1").toString();
          String portdetail2 = data_ht.get("portdetail2").toString();
          if (data_ht != null) {
            int jvm_memoryuiltillize = 0;

            String[] temjvm = jvm.split(",");
            double freememory = Double.parseDouble(temjvm[0].trim());
            double totalmemory = (double) Double.parseDouble(temjvm[1].trim());
            double maxmemory = (double) Double.parseDouble(temjvm[2].trim());

            jvm_memoryuiltillize = (int) Math.rint((totalmemory - freememory) * 100 / totalmemory);
            jvm_utilization = String.valueOf(jvm_memoryuiltillize);

            Pingcollectdata hostdata = null;
            hostdata = new Pingcollectdata();
            hostdata.setIpaddress(ip);
            Calendar date = Calendar.getInstance();
            hostdata.setCollecttime(date);
            hostdata.setCategory("tomcat_jvm");
            hostdata.setEntity("Utilization");
            hostdata.setSubentity("jvm_utilization");
            hostdata.setRestype("dynamic");
            hostdata.setUnit("%");
            hostdata.setThevalue(jvm_utilization);
            try {
              tomcatdao.createHostData(hostdata);

              if (sendeddata.containsKey("tomcat" + ":" + ip))
                sendeddata.remove("tomcat" + ":" + ip);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }

        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          tomcatdao.close();
        }
      }
      try {
        data_ht.put("jvm_utilization", jvm_utilization);
        ShareData.setTomcatdata(node.getIpAddress(), data_ht);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      data_ht = null;
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
    }
  }
Exemplo n.º 5
0
  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;
  }
Exemplo n.º 6
0
  /*
   * (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;
  }
Exemplo n.º 7
0
  public void collect_data(String id, Hashtable gatherHash) {
    Emailmonitor_realtimeDao emailmonitor_realtimeDao = null;
    Emailmonitor_historyDao emailmonitor_historyDao = null;
    try {
      EmailConfigDao emailConfigDao = new EmailConfigDao();
      EmailMonitorConfig mailconfig = null;
      try {
        mailconfig = (EmailMonitorConfig) emailConfigDao.findByID(id);
        if (mailconfig.getMonflag() == 0) { // 过滤掉不监控的邮箱
          return;
        }
      } catch (Exception e) {

      } finally {
        emailConfigDao.close();
      }
      Calendar date = Calendar.getInstance();

      ReceiveMail receieveMail = new ReceiveMail();
      sendMail sendmail = new sendMail();

      try {
        emailmonitor_realtimeDao = new Emailmonitor_realtimeDao();

        Hashtable realHash = null;
        try {
          realHash = emailmonitor_realtimeDao.getAllReal();
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          emailmonitor_realtimeDao.close();
        }

        Emailmonitor_history emailmonitor_history = new Emailmonitor_history();
        Emailmonitor_realtime emailold = new Emailmonitor_realtime();
        Integer iscanconnected = new Integer(0);
        String reason = "";
        Mail mail = (Mail) PollingEngine.getInstance().getMailByID(mailconfig.getId());
        if (mail == null) {
          return;
        }
        if (mail != null) {
          mail.setStatus(0);
          mail.setAlarm(false);
          mail.getAlarmMessage().clear();
          Calendar _tempCal = Calendar.getInstance();
          Date _cc = _tempCal.getTime();
          String _time = sdf.format(_cc);
          mail.setLastTime(_time);
        }

        Integer email_id = mailconfig.getId();
        boolean old = false;
        String str = "";
        Integer smssign = new Integer(0);
        if (realHash != null && realHash.get(email_id) != null) {
          old = true;
          emailold = (Emailmonitor_realtime) realHash.get(email_id);
          smssign = emailold.getSms_sign();
        }
        boolean flag = true;
        boolean receieveflag = true;
        int intflag = 0;
        int intreceieveflag = 0;

        try {
          if (gatherHash.containsKey("send")) {
            try {
              if (configSendMail(sendmail, mailconfig)) {
                flag = sendmail.sendmail();
                // intflag = 1;
              }
            } catch (Exception ex) {
              flag = false;
              ex.printStackTrace();
            }
          }

          if (gatherHash.containsKey("receieve")) {
            try {
              String mailserver = "";
              //							if (mailconfig.getAddress().indexOf("mail")>=0){
              //								//用的是MAIL服务
              //								mailserver = mailconfig.getAddress();
              //							}else if (mailconfig.getAddress().indexOf("smtp")>=0){
              //								//用的是SMTP服务
              //								mailserver = "smtp"+mailconfig.getAddress().substring(4);
              //							}else{
              //								//用的是POP3服务
              //								mailserver = "pop3."+mailconfig.getAddress();
              //							}
              mailserver = mailconfig.getReceiveAddress();
              receieveflag =
                  receieveMail.GetReceieveMail(
                      mailserver, mailconfig.getUsername(), mailconfig.getPassword());
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }

          // System.out.println("flag:"+flag+"-----receieveflag:"+receieveflag);
          if (flag && receieveflag) {
            intflag = 1;
            intreceieveflag = 1;
            iscanconnected = 1;
            reason = "服务有效";
            if (sendeddata.containsKey("emailserver:" + mailconfig.getId())) {
              sendeddata.remove("emailserver:" + mailconfig.getId());
            }

          } else {
            if (flag == true && receieveflag == false) {
              // 邮件能发送但不能接收
              intflag = 1;
              reason = "邮件接收服务无效";
              Vector mailvector = new Vector();
              // 开始设置采集值实体
              Interfacecollectdata interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Send");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intflag + "");
              interfacedata.setChname("发送服务");
              mailvector.add(interfacedata);

              interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Receieve");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intreceieveflag + "");
              interfacedata.setChname("接收服务");
              mailvector.add(interfacedata);

              Hashtable collectHash = new Hashtable();
              collectHash.put("mail", mailvector);

              //							mail.setStatus(3);
              //							mail.setAlarm(true);
              //							List alarmList = mail.getAlarmMessage();
              //							if(alarmList == null)alarmList = new ArrayList();

              // createEvent(mailconfig, reason);
              try {
                AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                List list =
                    alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                        String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                for (int k = 0; k < list.size(); k++) {
                  AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                  // 对邮件服务值进行告警检测
                  CheckEventUtil checkutil = new CheckEventUtil();
                  checkutil.updateData(mail, collectHash, "service", "mail", alarmIndicatorsnode);
                  // }
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
              // createEvent(mailconfig, reason);
            } else if (flag == false && receieveflag == true) {
              intreceieveflag = 1;
              // 邮件能接收但不能发送
              reason = "邮件发送服务无效";
              Vector mailvector = new Vector();
              // 开始设置采集值实体
              Interfacecollectdata interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Send");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intflag + "");
              interfacedata.setChname("发送服务");
              mailvector.add(interfacedata);

              interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Receieve");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intreceieveflag + "");
              interfacedata.setChname("接收服务");
              mailvector.add(interfacedata);

              Hashtable collectHash = new Hashtable();
              collectHash.put("mail", mailvector);

              //							mail.setStatus(3);
              //							mail.setAlarm(true);
              //							List alarmList = mail.getAlarmMessage();
              //							if(alarmList == null)alarmList = new ArrayList();

              // createEvent(mailconfig, reason);
              try {
                AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                List list =
                    alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                        String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                for (int k = 0; k < list.size(); k++) {
                  AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                  // 对邮件服务值进行告警检测
                  CheckEventUtil checkutil = new CheckEventUtil();
                  checkutil.updateData(mail, collectHash, "service", "mail", alarmIndicatorsnode);
                  // }
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
              // createEvent(mailconfig, reason);
            } else {
              // 邮件服务停止
              // 需要增加邮件服务所在的服务器是否能连通
              // Host host =
              // (Host)PollingEngine.getInstance().getNodeByIP(mailconfig.getIpaddress());
              Vector ipPingData = (Vector) ShareData.getPingdata().get(mailconfig.getIpaddress());
              if (ipPingData != null) {
                Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0);
                Calendar tempCal = (Calendar) pingdata.getCollecttime();
                Date cc = tempCal.getTime();
                String time = sdf.format(cc);
                String lastTime = time;
                String pingvalue = pingdata.getThevalue();
                if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0";
                double pvalue = new Double(pingvalue);
                if (pvalue == 0) {
                  // 主机服务器连接不上***********************************************
                  mail.setStatus(3);
                  mail.setAlarm(true);
                  // SysLogger.info(mail.getName()+"========================"+mail.isAlarm());
                  // dbnode.setStatus(3);
                  List alarmList = mail.getAlarmMessage();
                  if (alarmList == null) alarmList = new ArrayList();
                  mail.getAlarmMessage().add("邮件服务无效");
                  String sysLocation = "";
                  try {
                    SmscontentDao smsdao = new SmscontentDao();
                    String eventdesc =
                        "邮件服务("
                            + mailconfig.getName()
                            + " IP:"
                            + mailconfig.getAddress()
                            + ")"
                            + "的邮件服务停止";
                    smsdao.createEventWithReasion(
                        "poll",
                        mailconfig.getId() + "",
                        mailconfig.getName() + "(" + mailconfig.getAddress() + ")",
                        eventdesc,
                        3,
                        "mail",
                        "ping",
                        "所在的服务器连接不上");
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                } else {
                  //									mail.setStatus(3);
                  //									mail.setAlarm(true);
                  //									List alarmList = mail.getAlarmMessage();
                  //									if(alarmList == null)alarmList = new ArrayList();
                  //									mail.getAlarmMessage().add("邮件服务无效");
                  //									reason="邮件服务无效";
                  Vector mailvector = new Vector();
                  // 开始设置采集值实体
                  Interfacecollectdata interfacedata = new Interfacecollectdata();
                  interfacedata.setIpaddress(mail.getIpAddress());
                  interfacedata.setCollecttime(date);
                  interfacedata.setCategory("Mail");
                  interfacedata.setEntity("Send");
                  interfacedata.setSubentity(mail.getId() + "");
                  interfacedata.setRestype("static");
                  interfacedata.setUnit("");
                  interfacedata.setThevalue(intflag + "");
                  interfacedata.setChname("发送服务");
                  mailvector.add(interfacedata);

                  interfacedata = new Interfacecollectdata();
                  interfacedata.setIpaddress(mail.getIpAddress());
                  interfacedata.setCollecttime(date);
                  interfacedata.setCategory("Mail");
                  interfacedata.setEntity("Receieve");
                  interfacedata.setSubentity(mail.getId() + "");
                  interfacedata.setRestype("static");
                  interfacedata.setUnit("");
                  interfacedata.setThevalue(intreceieveflag + "");
                  interfacedata.setChname("接收服务");
                  mailvector.add(interfacedata);

                  Hashtable collectHash = new Hashtable();
                  collectHash.put("mail", mailvector);

                  //									mail.setStatus(3);
                  //									mail.setAlarm(true);

                  // createEvent(mailconfig, reason);
                  try {
                    AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                    List list =
                        alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                            String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                    for (int k = 0; k < list.size(); k++) {
                      AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                      // 对邮件服务值进行告警检测
                      CheckEventUtil checkutil = new CheckEventUtil();
                      checkutil.updateData(
                          mail, collectHash, "service", "mail", alarmIndicatorsnode);
                      // }
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                  // createEvent(mailconfig, reason);
                }

              } else {
                //								mail.setStatus(3);
                //								mail.setAlarm(true);
                //								List alarmList = mail.getAlarmMessage();
                //								if(alarmList == null)alarmList = new ArrayList();
                //								mail.getAlarmMessage().add("邮件服务无效");
                //								reason="邮件服务无效";
                Vector mailvector = new Vector();
                // 开始设置采集值实体
                Interfacecollectdata interfacedata = new Interfacecollectdata();
                interfacedata.setIpaddress(mail.getIpAddress());
                interfacedata.setCollecttime(date);
                interfacedata.setCategory("Mail");
                interfacedata.setEntity("Send");
                interfacedata.setSubentity(mail.getId() + "");
                interfacedata.setRestype("static");
                interfacedata.setUnit("");
                interfacedata.setThevalue(intflag + "");
                interfacedata.setChname("发送服务");
                mailvector.add(interfacedata);

                interfacedata = new Interfacecollectdata();
                interfacedata.setIpaddress(mail.getIpAddress());
                interfacedata.setCollecttime(date);
                interfacedata.setCategory("Mail");
                interfacedata.setEntity("Receieve");
                interfacedata.setSubentity(mail.getId() + "");
                interfacedata.setRestype("static");
                interfacedata.setUnit("");
                interfacedata.setThevalue(intreceieveflag + "");
                interfacedata.setChname("接收服务");
                mailvector.add(interfacedata);

                Hashtable collectHash = new Hashtable();
                collectHash.put("mail", mailvector);

                //								mail.setStatus(3);
                //								mail.setAlarm(true);

                // createEvent(mailconfig, reason);
                try {
                  AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                  List list =
                      alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                          String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                  for (int k = 0; k < list.size(); k++) {
                    AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                    // 对邮件服务值进行告警检测
                    CheckEventUtil checkutil = new CheckEventUtil();
                    checkutil.updateData(mail, collectHash, "service", "mail", alarmIndicatorsnode);
                    // }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
                // createEvent(mailconfig, reason);
              }
            }
          }
        } catch (Exception ex) {
          //					//不能进行邮件服务
          //					EventList event = new EventList();
          //					if (flag == true && receieveflag == false){
          //						intflag = 1;
          //						reason="邮件接收服务无效";
          //						mail.getAlarmMessage().add("邮件接收服务无效");
          //					}else if (flag == false && receieveflag == true){
          //						intreceieveflag = 1;
          //						reason="邮件发送服务无效";
          //						mail.getAlarmMessage().add("邮件发送服务无效");
          //					}
          //					Vector mailvector = new Vector();
          //					//开始设置采集值实体
          //					Interfacecollectdata interfacedata=new Interfacecollectdata();
          //					interfacedata.setIpaddress(mail.getIpAddress());
          //					interfacedata.setCollecttime(date);
          //					interfacedata.setCategory("Mail");
          //					interfacedata.setEntity("Send");
          //					interfacedata.setSubentity(mail.getId()+"");
          //					interfacedata.setRestype("static");
          //					interfacedata.setUnit("");
          //					interfacedata.setThevalue(intflag+"");
          //					interfacedata.setChname("发送服务");
          //					mailvector.add(interfacedata);
          //
          //					interfacedata=new Interfacecollectdata();
          //					interfacedata.setIpaddress(mail.getIpAddress());
          //					interfacedata.setCollecttime(date);
          //					interfacedata.setCategory("Mail");
          //					interfacedata.setEntity("Receieve");
          //					interfacedata.setSubentity(mail.getId()+"");
          //					interfacedata.setRestype("static");
          //					interfacedata.setUnit("");
          //					interfacedata.setThevalue(intreceieveflag+"");
          //					interfacedata.setChname("接收服务");
          //					mailvector.add(interfacedata);
          //
          //					Hashtable collectHash = new Hashtable();
          //					collectHash.put("mail", mailvector);
          //
          //					mail.setStatus(3);
          //					mail.setAlarm(true);
          //					List alarmList = mail.getAlarmMessage();
          //					if(alarmList == null)alarmList = new ArrayList();
          //
          //					createEvent(mailconfig, reason);
          //				    try{
          //						AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
          //						List list =
          // alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
          //						for(int k = 0 ; k < list.size() ; k ++){
          //							AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode)list.get(k);
          //							//对邮件服务值进行告警检测
          //							CheckEventUtil checkutil = new CheckEventUtil();
          //							checkutil.updateData(mail,collectHash,"service","mail",alarmIndicatorsnode);
          //							//}
          //						}
          //				    }catch(Exception e){
          //				    	e.printStackTrace();
          //				    }
        }
        // 保存进历史数据
        emailmonitor_history.setEmail_id(mailconfig.getId());
        emailmonitor_history.setIs_canconnected(iscanconnected);
        emailmonitor_history.setMon_time(Calendar.getInstance());
        emailmonitor_history.setReason(reason);
        emailmonitor_historyDao = new Emailmonitor_historyDao();
        try {
          emailmonitor_historyDao.save(emailmonitor_history);
        } catch (Exception e) {

        }
        if (sendeddata.containsKey("emailserver:" + mailconfig.getId())) {
          sendeddata.remove("emailserver:" + mailconfig.getId());
        }

        // 实时数据
        Emailmonitor_realtime emailmonitor_realtime = new Emailmonitor_realtime();
        emailmonitor_realtime.setEmail_id(mailconfig.getId());
        emailmonitor_realtime.setIs_canconnected(iscanconnected);
        emailmonitor_realtime.setMon_time(Calendar.getInstance());
        emailmonitor_realtime.setReason(reason);

        if (old == true) {
          emailmonitor_realtime.setId(emailold.getId());
          emailmonitor_realtime.setSms_sign(1);
        } else {
          emailmonitor_realtime.setSms_sign(smssign);
        }
        // 保存realtime
        if (old == true) {
          emailmonitor_realtimeDao = new Emailmonitor_realtimeDao();
          try {
            emailmonitor_realtimeDao.update(emailmonitor_realtime);
          } catch (Exception e) {

          } finally {
            emailmonitor_realtimeDao.close();
          }
        }
        if (old == false) {
          emailmonitor_realtimeDao = new Emailmonitor_realtimeDao();
          try {
            emailmonitor_realtimeDao.save(emailmonitor_realtime);
          } catch (Exception e) {

          } finally {
            emailmonitor_realtimeDao.close();
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        emailmonitor_historyDao.close();
        emailmonitor_realtimeDao.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (emailmonitor_realtimeDao != null) {
        emailmonitor_historyDao.close();
      }
      if (emailmonitor_realtimeDao != null) {
        emailmonitor_realtimeDao.close();
      }
    }
  }
  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;
  }
Exemplo n.º 10
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;
  }
Exemplo n.º 11
0
  public void collect_data(String id, Hashtable gatherHash) {
    WasConfig wasconf = null;
    try {
      int serverflag = 0;
      String ipaddress = "";
      WasConfigDao dao = new WasConfigDao();
      try {
        wasconf = (WasConfig) dao.findByID(id);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        dao.close();
      }
      // AdminClient5 wasadmin = new AdminClient5();
      UrlConncetWas conWas = new UrlConncetWas();
      Hashtable hst = new Hashtable();
      com.afunms.polling.node.Was _tnode =
          (com.afunms.polling.node.Was) PollingEngine.getInstance().getWasByID(wasconf.getId());

      Calendar _date = Calendar.getInstance();
      Date _cc = _date.getTime();
      String _tempsenddate = sdf.format(_cc);
      // 初始化Was对象的状态
      _tnode.setLastTime(_tempsenddate);
      _tnode.setAlarm(false);
      _tnode.getAlarmMessage().clear();
      _tnode.setStatus(0);

      if (gatherHash.containsKey("ping")) {
        // 对可用性进行检测
        boolean collectWasIsOK = false;
        try {
          collectWasIsOK = conWas.connectWasIsOK(wasconf.getIpaddress(), wasconf.getPortnum());
        } catch (Exception e) {
          // e.printStackTrace();
        }
        if (collectWasIsOK) {
          // 运行状态
          Pingcollectdata hostdata = null;
          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("100");
          WasConfigDao wasconfigdao = new WasConfigDao();
          try {
            wasconfigdao.createHostData(wasconf, hostdata);
            if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
              wasdata.remove("was" + ":" + wasconf.getIpaddress());
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            wasconfigdao.close();
          }
          // 进行数据采集
          try {
            hst =
                conWas.ConncetWas(
                    wasconf.getIpaddress(),
                    String.valueOf(wasconf.getPortnum()),
                    "",
                    "",
                    wasconf.getVersion(),
                    gatherHash);
          } catch (Exception e) {

          }
        } else {
          // 依据配置判断是否需要告警
          //									if
          // (wlservers.containsKey(weblogicconf.getIpaddress()+":"+server.getServerRuntimeName()))
          //										createSMS(weblogicconf,server);

          try {
            // com.afunms.polling.node.Weblogic tc = new com.afunms.polling.node.Weblogic();
            // BeanUtils.copyProperties(tc, weblogicconf);
            // if (data_ht==null){
            // 需要增加邮件服务所在的服务器是否能连通
            Host host = (Host) PollingEngine.getInstance().getNodeByIP(wasconf.getIpaddress());
            Vector ipPingData = (Vector) ShareData.getPingdata().get(wasconf.getIpaddress());
            ipaddress = wasconf.getIpaddress();
            if (ipPingData != null) {
              Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0);
              Calendar tempCal = (Calendar) pingdata.getCollecttime();
              Date cc = tempCal.getTime();
              String _time = sdf.format(cc);
              String lastTime = _time;
              String pingvalue = pingdata.getThevalue();
              if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0";
              double pvalue = new Double(pingvalue);
              if (pvalue == 0) {
                // 主机服务器连接不上***********************************************
                // com.afunms.polling.node.Weblogic
                // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress);
                _tnode.setAlarm(true);
                _tnode.setStatus(1);
                List alarmList = _tnode.getAlarmMessage();
                if (alarmList == null) alarmList = new ArrayList();
                _tnode.getAlarmMessage().add("WAS服务停止");
                String sysLocation = "";
                Pingcollectdata hostdata = null;
                hostdata = new Pingcollectdata();
                hostdata.setIpaddress(ipaddress);
                Calendar date = Calendar.getInstance();
                hostdata.setCollecttime(date);
                hostdata.setCategory("WasPing");
                hostdata.setEntity("Utilization");
                hostdata.setSubentity("ConnectUtilization");
                hostdata.setRestype("dynamic");
                hostdata.setUnit("%");
                hostdata.setThevalue("0");
                WasConfigDao wasconfigdao = new WasConfigDao();
                try {
                  wasconfigdao.createHostData(wasconf, hostdata);
                  if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
                    wasdata.remove("was" + ":" + wasconf.getIpaddress());
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  wasconfigdao.close();
                }
                try {
                  SmscontentDao eventdao = new SmscontentDao();
                  String eventdesc =
                      "WAS服务(" + wasconf.getName() + " IP:" + wasconf.getIpaddress() + ")" + "停止";
                  eventdao.createEventWithReasion(
                      "poll",
                      _tnode.getId() + "",
                      _tnode.getAdminIp() + "(" + _tnode.getAdminIp() + ")",
                      eventdesc,
                      3,
                      "wasserver",
                      "ping",
                      "所在的服务器连接不上");
                } catch (Exception e) {
                  e.printStackTrace();
                }
              } else {
                // com.afunms.polling.node.Weblogic
                // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress);
                _tnode.setAlarm(true);
                _tnode.setStatus(3);
                List alarmList = _tnode.getAlarmMessage();
                if (alarmList == null) alarmList = new ArrayList();
                _tnode.getAlarmMessage().add("WAS服务停止");
                Pingcollectdata hostdata = null;
                hostdata = new Pingcollectdata();
                hostdata.setIpaddress(ipaddress);
                Calendar date = Calendar.getInstance();
                hostdata.setCollecttime(date);
                hostdata.setCategory("WasPing");
                hostdata.setEntity("Utilization");
                hostdata.setSubentity("ConnectUtilization");
                hostdata.setRestype("dynamic");
                hostdata.setUnit("%");
                hostdata.setThevalue("0");
                WasConfigDao wasconfigdao = new WasConfigDao();
                try {
                  wasconfigdao.createHostData(wasconf, hostdata);
                  if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
                    wasdata.remove("was" + ":" + wasconf.getIpaddress());
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  wasconfigdao.close();
                }
              }

            } else {
              // com.afunms.polling.node.Weblogic
              // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress);
              _tnode.setAlarm(true);
              _tnode.setStatus(3);
              List alarmList = _tnode.getAlarmMessage();
              if (alarmList == null) alarmList = new ArrayList();
              _tnode.getAlarmMessage().add("WAS服务停止");
              Pingcollectdata hostdata = null;
              hostdata = new Pingcollectdata();
              hostdata.setIpaddress(ipaddress);
              Calendar date = Calendar.getInstance();
              hostdata.setCollecttime(date);
              hostdata.setCategory("WasPing");
              hostdata.setEntity("Utilization");
              hostdata.setSubentity("ConnectUtilization");
              hostdata.setRestype("dynamic");
              hostdata.setUnit("%");
              hostdata.setThevalue("0");
              WasConfigDao wasconfigdao = new WasConfigDao();
              try {
                wasconfigdao.createHostData(wasconf, hostdata);
                if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
                  wasdata.remove("was" + ":" + wasconf.getIpaddress());
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                wasconfigdao.close();
              }
            }
            try {
              createSMS("wasserver", wasconf);
              serverflag = 1;
            } catch (Exception e) {
              e.printStackTrace();
            }
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
      //				try{
      //					/**
      //					 * Author by QuZhi
      //					 * 可以取到的指标模块名称
      //					 * JVM/JDBCProvider/SessionManager/SystemMetrics/DynaCache/TransactionService/ORB
      //					 * @return /ObjectPool/ThreadPool
      //					 */
      //					//	 com.afunms.common.util.ShareData.setWasdata("was"+":"+wasconf.getIpaddress(),hst);
      //				}catch(Exception ex){
      //					ex.printStackTrace();
      //				}
      if (hst != null) {
        ShareData.getWasdata().put(wasconf.getIpaddress(), hst);
      }
      hst = null;
    } catch (Exception exc) {
      exc.printStackTrace();
    }
  }
Exemplo n.º 12
0
public class WasDataCollector {
  private Hashtable sendeddata = ShareData.getSendeddata();
  private Hashtable wasdata = ShareData.getWasdata();
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  public WasDataCollector() {}

  public void collect_data(String id, Hashtable gatherHash) {
    WasConfig wasconf = null;
    try {
      int serverflag = 0;
      String ipaddress = "";
      WasConfigDao dao = new WasConfigDao();
      try {
        wasconf = (WasConfig) dao.findByID(id);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        dao.close();
      }
      // AdminClient5 wasadmin = new AdminClient5();
      UrlConncetWas conWas = new UrlConncetWas();
      Hashtable hst = new Hashtable();
      com.afunms.polling.node.Was _tnode =
          (com.afunms.polling.node.Was) PollingEngine.getInstance().getWasByID(wasconf.getId());

      Calendar _date = Calendar.getInstance();
      Date _cc = _date.getTime();
      String _tempsenddate = sdf.format(_cc);
      // 初始化Was对象的状态
      _tnode.setLastTime(_tempsenddate);
      _tnode.setAlarm(false);
      _tnode.getAlarmMessage().clear();
      _tnode.setStatus(0);

      if (gatherHash.containsKey("ping")) {
        // 对可用性进行检测
        boolean collectWasIsOK = false;
        try {
          collectWasIsOK = conWas.connectWasIsOK(wasconf.getIpaddress(), wasconf.getPortnum());
        } catch (Exception e) {
          // e.printStackTrace();
        }
        if (collectWasIsOK) {
          // 运行状态
          Pingcollectdata hostdata = null;
          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("100");
          WasConfigDao wasconfigdao = new WasConfigDao();
          try {
            wasconfigdao.createHostData(wasconf, hostdata);
            if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
              wasdata.remove("was" + ":" + wasconf.getIpaddress());
          } catch (Exception e) {
            e.printStackTrace();
          } finally {
            wasconfigdao.close();
          }
          // 进行数据采集
          try {
            hst =
                conWas.ConncetWas(
                    wasconf.getIpaddress(),
                    String.valueOf(wasconf.getPortnum()),
                    "",
                    "",
                    wasconf.getVersion(),
                    gatherHash);
          } catch (Exception e) {

          }
        } else {
          // 依据配置判断是否需要告警
          //									if
          // (wlservers.containsKey(weblogicconf.getIpaddress()+":"+server.getServerRuntimeName()))
          //										createSMS(weblogicconf,server);

          try {
            // com.afunms.polling.node.Weblogic tc = new com.afunms.polling.node.Weblogic();
            // BeanUtils.copyProperties(tc, weblogicconf);
            // if (data_ht==null){
            // 需要增加邮件服务所在的服务器是否能连通
            Host host = (Host) PollingEngine.getInstance().getNodeByIP(wasconf.getIpaddress());
            Vector ipPingData = (Vector) ShareData.getPingdata().get(wasconf.getIpaddress());
            ipaddress = wasconf.getIpaddress();
            if (ipPingData != null) {
              Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0);
              Calendar tempCal = (Calendar) pingdata.getCollecttime();
              Date cc = tempCal.getTime();
              String _time = sdf.format(cc);
              String lastTime = _time;
              String pingvalue = pingdata.getThevalue();
              if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0";
              double pvalue = new Double(pingvalue);
              if (pvalue == 0) {
                // 主机服务器连接不上***********************************************
                // com.afunms.polling.node.Weblogic
                // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress);
                _tnode.setAlarm(true);
                _tnode.setStatus(1);
                List alarmList = _tnode.getAlarmMessage();
                if (alarmList == null) alarmList = new ArrayList();
                _tnode.getAlarmMessage().add("WAS服务停止");
                String sysLocation = "";
                Pingcollectdata hostdata = null;
                hostdata = new Pingcollectdata();
                hostdata.setIpaddress(ipaddress);
                Calendar date = Calendar.getInstance();
                hostdata.setCollecttime(date);
                hostdata.setCategory("WasPing");
                hostdata.setEntity("Utilization");
                hostdata.setSubentity("ConnectUtilization");
                hostdata.setRestype("dynamic");
                hostdata.setUnit("%");
                hostdata.setThevalue("0");
                WasConfigDao wasconfigdao = new WasConfigDao();
                try {
                  wasconfigdao.createHostData(wasconf, hostdata);
                  if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
                    wasdata.remove("was" + ":" + wasconf.getIpaddress());
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  wasconfigdao.close();
                }
                try {
                  SmscontentDao eventdao = new SmscontentDao();
                  String eventdesc =
                      "WAS服务(" + wasconf.getName() + " IP:" + wasconf.getIpaddress() + ")" + "停止";
                  eventdao.createEventWithReasion(
                      "poll",
                      _tnode.getId() + "",
                      _tnode.getAdminIp() + "(" + _tnode.getAdminIp() + ")",
                      eventdesc,
                      3,
                      "wasserver",
                      "ping",
                      "所在的服务器连接不上");
                } catch (Exception e) {
                  e.printStackTrace();
                }
              } else {
                // com.afunms.polling.node.Weblogic
                // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress);
                _tnode.setAlarm(true);
                _tnode.setStatus(3);
                List alarmList = _tnode.getAlarmMessage();
                if (alarmList == null) alarmList = new ArrayList();
                _tnode.getAlarmMessage().add("WAS服务停止");
                Pingcollectdata hostdata = null;
                hostdata = new Pingcollectdata();
                hostdata.setIpaddress(ipaddress);
                Calendar date = Calendar.getInstance();
                hostdata.setCollecttime(date);
                hostdata.setCategory("WasPing");
                hostdata.setEntity("Utilization");
                hostdata.setSubentity("ConnectUtilization");
                hostdata.setRestype("dynamic");
                hostdata.setUnit("%");
                hostdata.setThevalue("0");
                WasConfigDao wasconfigdao = new WasConfigDao();
                try {
                  wasconfigdao.createHostData(wasconf, hostdata);
                  if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
                    wasdata.remove("was" + ":" + wasconf.getIpaddress());
                } catch (Exception e) {
                  e.printStackTrace();
                } finally {
                  wasconfigdao.close();
                }
              }

            } else {
              // com.afunms.polling.node.Weblogic
              // tnode=(com.afunms.polling.node.Weblogic)PollingEngine.getInstance().getWeblogicByIP(ipaddress);
              _tnode.setAlarm(true);
              _tnode.setStatus(3);
              List alarmList = _tnode.getAlarmMessage();
              if (alarmList == null) alarmList = new ArrayList();
              _tnode.getAlarmMessage().add("WAS服务停止");
              Pingcollectdata hostdata = null;
              hostdata = new Pingcollectdata();
              hostdata.setIpaddress(ipaddress);
              Calendar date = Calendar.getInstance();
              hostdata.setCollecttime(date);
              hostdata.setCategory("WasPing");
              hostdata.setEntity("Utilization");
              hostdata.setSubentity("ConnectUtilization");
              hostdata.setRestype("dynamic");
              hostdata.setUnit("%");
              hostdata.setThevalue("0");
              WasConfigDao wasconfigdao = new WasConfigDao();
              try {
                wasconfigdao.createHostData(wasconf, hostdata);
                if (wasdata.containsKey("was" + ":" + wasconf.getIpaddress()))
                  wasdata.remove("was" + ":" + wasconf.getIpaddress());
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                wasconfigdao.close();
              }
            }
            try {
              createSMS("wasserver", wasconf);
              serverflag = 1;
            } catch (Exception e) {
              e.printStackTrace();
            }
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
      //				try{
      //					/**
      //					 * Author by QuZhi
      //					 * 可以取到的指标模块名称
      //					 * JVM/JDBCProvider/SessionManager/SystemMetrics/DynaCache/TransactionService/ORB
      //					 * @return /ObjectPool/ThreadPool
      //					 */
      //					//	 com.afunms.common.util.ShareData.setWasdata("was"+":"+wasconf.getIpaddress(),hst);
      //				}catch(Exception ex){
      //					ex.printStackTrace();
      //				}
      if (hst != null) {
        ShareData.getWasdata().put(wasconf.getIpaddress(), hst);
      }
      hst = null;
    } catch (Exception exc) {
      exc.printStackTrace();
    }
  }

  private Runnable createTask(final WasConfig wasconf) {
    return new Runnable() {
      public void run() {}
    };
  }

  public void createSMS(String was, WasConfig wasconf) {

    // 建立短信
    // 从内存里获得当前这个IP的PING的值
    Calendar date = Calendar.getInstance();
    try {
      if (!sendeddata.containsKey(was + ":" + wasconf.getId())) {
        // 若不在,则建立短信,并且添加到发送列表里
        Smscontent smscontent = new Smscontent();
        String time = sdf.format(date.getTime());
        smscontent.setLevel("2");
        smscontent.setObjid(wasconf.getId() + "");
        if ("wasserver".equals(was)) {
          smscontent.setMessage(
              "WAS" + " (" + wasconf.getName() + ":" + wasconf.getIpaddress() + ")" + "的服务停止!");
        }
        smscontent.setRecordtime(time);
        smscontent.setSubtype("wasserver");
        smscontent.setSubentity("ping");
        smscontent.setIp(wasconf.getIpaddress());
        // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止");
        // 发送短信
        SmscontentDao smsmanager = new SmscontentDao();
        smsmanager.sendURLSmscontent(smscontent);
        sendeddata.put(was + ":" + wasconf.getId(), date);
      } else {
        // 若在,则从已发送短信列表里判断是否已经发送当天的短信
        Calendar formerdate = (Calendar) sendeddata.get(was + ":" + wasconf.getId());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date last = null;
        Date current = null;
        Calendar sendcalen = formerdate;
        Date cc = sendcalen.getTime();
        String tempsenddate = formatter.format(cc);

        Calendar currentcalen = date;
        cc = currentcalen.getTime();
        last = formatter.parse(tempsenddate);
        String currentsenddate = formatter.format(cc);
        current = formatter.parse(currentsenddate);

        long subvalue = current.getTime() - last.getTime();
        if (subvalue / (1000 * 60 * 60 * 24) >= 1) {
          // 超过一天,则再发信息
          Smscontent smscontent = new Smscontent();
          String time = sdf.format(date.getTime());
          smscontent.setLevel("2");
          smscontent.setObjid(wasconf.getId() + "");
          if ("wasserver".equals(was)) {
            smscontent.setMessage(
                "WAS" + " (" + wasconf.getName() + ":" + wasconf.getIpaddress() + ")" + "的服务停止!");
          }
          smscontent.setRecordtime(time);
          smscontent.setSubtype("wasserver");
          smscontent.setSubentity("ping");
          smscontent.setIp(wasconf.getIpaddress());
          // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止");
          // 发送短信
          SmscontentDao smsmanager = new SmscontentDao();
          smsmanager.sendURLSmscontent(smscontent);
          // 修改已经发送的短信记录
          sendeddata.put(was + ":" + wasconf.getId(), date);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
  @SuppressWarnings("unchecked")
  public Hashtable collect_Data(NodeGatherIndicators nodeGatherIndicators) {
    Hashtable returndata = new Hashtable();
    String htKey = "dbio";
    List dbmonitorlists = new ArrayList();
    dbmonitorlists = ShareData.getDBList();
    DBVo dbmonitorlist = new DBVo();
    if (dbmonitorlists != null && dbmonitorlists.size() > 0) {
      for (int i = 0; i < dbmonitorlists.size(); i++) {
        DBVo vo = (DBVo) dbmonitorlists.get(i);
        if (vo.getId() == Integer.parseInt(nodeGatherIndicators.getNodeid())) {
          dbmonitorlist = vo;
          break;
        }
      }
    }
    if (dbmonitorlist != null) {
      if (dbmonitorlist.getManaged() == 0) {
        // 如果未被管理,不采集,user信息为空
        return returndata;
      }
      String serverip = dbmonitorlist.getIpAddress();
      String[] args = new String[] {"name", "filename", "pyr", "pbr", "pyw", "pbw", "mon_time"};
      returndata = LogParser.parse(this, dbmonitorlist, htKey, args);

      // 更新内存
      if (!(ShareData.getSharedata()
          .containsKey(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId()))) {
        ShareData.getSharedata()
            .put(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId(), returndata);
      } else {
        Hashtable oracleHash =
            (Hashtable)
                ShareData.getSharedata()
                    .get(dbmonitorlist.getIpAddress() + ":" + dbmonitorlist.getId());
        oracleHash.put("dbio", returndata.get(htKey));
      }

      // ----------------------------------保存到数据库及告警 start
      Vector info_v = (Vector) returndata.get(htKey);
      if (info_v != null && !info_v.isEmpty()) {
        String hex = IpTranslation.formIpToHex(dbmonitorlist.getIpAddress());
        serverip = hex + ":" + dbmonitorlist.getId();

        try {
          Calendar tempCal = Calendar.getInstance();
          Date cc = tempCal.getTime();
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          String montime = sdf.format(cc);
          String deletesql = "delete from nms_oradbio where serverip='" + serverip + "'";
          GathersqlListManager.Addsql(deletesql);

          String name = null;
          String pyr = null;
          String pbr = null;
          String pyw = null;
          String pbw = null;

          String insertsql = null;

          for (int j = 0; j < info_v.size(); j++) {
            Hashtable dbiohash = (Hashtable) info_v.get(j);
            name = "";
            pyr = "";
            pbr = "";
            pyw = "";
            pbw = "";

            String filename = (String) dbiohash.get("filename");
            filename = filename.replaceAll("\\\\", "/");
            name = (String) dbiohash.get("name");
            pyr = (String) dbiohash.get("pyr");
            pbr = (String) dbiohash.get("pbr");
            pyw = (String) dbiohash.get("pyw");
            pbw = (String) dbiohash.get("pbw");

            insertsql =
                "insert into nms_oradbio(serverip, name, filename, pyr, pbr, pyw, pbw,mon_time) "
                    + "values('"
                    + serverip
                    + "','"
                    + name
                    + "','"
                    + filename
                    + "','"
                    + pyr
                    + "','"
                    + pbr
                    + "','"
                    + pyw
                    + "','"
                    + pbw;
            if ("mysql".equalsIgnoreCase(SystemConstant.DBType)) {
              insertsql = insertsql + "','" + montime + "')";
            } else if ("oracle".equalsIgnoreCase(SystemConstant.DBType)) {
              insertsql = insertsql + "',to_date('" + montime + "','YYYY-MM-DD HH24:MI:SS'))";
            }
            GathersqlListManager.Addsql(insertsql);
          }
          // ---------------------------------dbio不需告警

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

        // ----------------------------------保存到数据库及告警 end
      }
    }
    return returndata;
  }
Exemplo n.º 14
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;
  }
Exemplo n.º 15
0
  /* (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;
  }
  /** @author nielin modify at 2010-01-08 */
  public int writeXml(int flag) {
    int done = 0;
    // 需要做分布式判断
    String runmodel = PollingEngine.getCollectwebflag();
    try {
      I_HostLastCollectData hostlastmanager = new HostLastCollectDataManager();
      Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(ipaddress);

      Vector vector = new Vector();
      String[] netInterfaceItem = {
        "index",
        "ifDescr",
        "ifSpeed",
        "ifAdminStatus",
        "ifOperStatus",
        "OutBandwidthUtilHdx",
        "InBandwidthUtilHdx"
      };
      try {
        if ("0".equals(runmodel)) {
          // 采集与访问是集成模式
          vector = hostlastmanager.getInterface_share(ipaddress, netInterfaceItem, "index", "", "");
        } else {
          // 采集与访问是分离模式
          vector = hostlastmanager.getInterface(ipaddress, netInterfaceItem, "index", "", "");
        }
      } catch (Exception e) {
        e.printStackTrace();
        return done;
      }
      try {
        _fis =
            new FileInputStream(
                ResourceCenter.getInstance().getSysPath()
                    + "panel/model/"
                    + oid
                    + "_"
                    + imageType
                    + ".jsp");
      } catch (Exception e) {
        e.printStackTrace();
        _fis.close();
        return done;
      }
      _fis.skip(headBytes.getBytes().length);
      _builder = new SAXBuilder();
      _doc = _builder.build(_fis);
      _root = _doc.getRootElement();
      _nodes = _root.getChild("nodes");

      List list = _nodes.getChildren();

      PortconfigDao dao = new PortconfigDao();

      try {

        for (int i = 0; i < list.size(); i++) {
          Element eleNode = (Element) list.get(i);
          if (eleNode.getChildText("index") == null) break;
          int index = Integer.valueOf(eleNode.getChildText("index")).intValue();
          String x = eleNode.getChildText("x");
          String y = eleNode.getChildText("y");
          String img = eleNode.getChildText("img");
          String direction = eleNode.getChildText("direction");
          String ifname = "";
          String OutBandwidthUtilHdx = "0";
          String InBandwidthUtilHdx = "0";
          String portuse = "";
          if (vector != null && vector.size() > 0) {
            for (int m = 0; m < vector.size(); m++) {
              String[] strs = (String[]) vector.get(m);
              String _ifname = strs[1];
              String _index = strs[0];
              String opstatus = strs[4];
              OutBandwidthUtilHdx = strs[5];
              InBandwidthUtilHdx = strs[6];

              Portconfig portconfig = null;
              try {
                portconfig = dao.getPanelByipandindex(ipaddress, index + "");
              } catch (Exception e) {

              }
              if (portconfig != null
                  && portconfig.getLinkuse() != null
                  && portconfig.getLinkuse().trim().length() > 0) {
                portuse = portconfig.getLinkuse();
              }

              // SysLogger.info(ipaddress+"====ifOperStatus====="+strs[4]);
              if (Integer.parseInt(_index) == index) {
                ifname = _ifname;
                if ("down".equalsIgnoreCase(opstatus)) {
                  // DOWN
                  if ("1".equalsIgnoreCase(direction)) {
                    // 向上的端口
                    img = "image/up_down_gray.gif";
                  } else {
                    // 向下的端口
                    img = "image/down_down_gray.gif";
                  }
                } else {
                  // UP
                  if ("1".equalsIgnoreCase(direction)) {
                    // 向上的端口
                    img = "image/up_up_green.gif";
                  } else {
                    // 向下的端口
                    img = "image/down_up_green.gif";
                  }
                }
                break;
              }
            }
          }
          addNode(
              index + "",
              InBandwidthUtilHdx,
              OutBandwidthUtilHdx,
              img,
              ipaddress,
              ifname,
              portuse,
              x,
              y);
        }

      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        dao.close();
      }

      Format format = Format.getCompactFormat();
      format.setEncoding("GB2312");
      format.setIndent("	");
      serializer = new XMLOutputter(format);
      // SysLogger.info("path==="+fullPath);
      fos = new FileOutputStream(fullPath);
      fos.write(headBytes.getBytes());
      serializer.output(doc, fos);
      fos.close();
      done = 1;
    } catch (Exception e) {
      done = 0;
      e.printStackTrace();
      SysLogger.error("Error in XmlOperator.close()", e);
    }
    return done;
  }
  /* (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;
  }
Exemplo n.º 18
0
/**
 * @author Administrator
 *     <p>To change the template for this generated type comment go to
 *     Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class ArrayVPNSystemSnmp extends SnmpMonitor {
  private Hashtable sendeddata = ShareData.getProcsendeddata();
  java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  /** */
  public ArrayVPNSystemSnmp() {}

  public void collectData(Node node, MonitoredItem item) {}

  public void collectData(HostNode node) {}

  public Hashtable collect_Data(
      NodeGatherIndicators alarmIndicatorsNode) { // Òª¸ÄΪAlarmIndicatorsNode alarmIndicatorsNode
    Hashtable returnHash = new Hashtable();
    Vector powerVector = new Vector();
    Host node =
        (Host)
            PollingEngine.getInstance()
                .getNodeByID(Integer.parseInt(alarmIndicatorsNode.getNodeid()));
    if (node == null) return null;
    try {

      Calendar date = Calendar.getInstance();
      Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(node.getIpAddress());
      if (ipAllData == null) ipAllData = new Hashtable();

      try {
        String temp = "0";
        String[][] valueArray = null;
        String[] oids = new String[] {"1.3.6.1.4.1.7564.30.2", "1.3.6.1.4.1.7564.30.3"};

        valueArray =
            SnmpUtils.getTableData(
                node.getIpAddress(), node.getCommunity(), oids, node.getSnmpversion(), 3, 1000);
        int flag = 0;
        if (valueArray != null) {
          for (int i = 0; i < valueArray.length; i++) {
            ArrayVPNSystem arrayVPNSystem = new ArrayVPNSystem();
            String connectionsPerSec = valueArray[i][0];
            String requestsPerSec = valueArray[i][1];

            arrayVPNSystem.setRequestsPerSec(Integer.parseInt(requestsPerSec));
            arrayVPNSystem.setConnectionsPerSec(Integer.parseInt(connectionsPerSec));

            arrayVPNSystem.setIpaddress(node.getIpAddress());
            arrayVPNSystem.setCollecttime(date);
            arrayVPNSystem.setType("NET");
            arrayVPNSystem.setSubtype("ArrayNetworks");
            SysLogger.info( // "cpuUtilization:"+cpuUtilization
                "   connectionsPerSec:"
                    + connectionsPerSec
                    + "  requestsPerSec :"
                    + requestsPerSec);
            powerVector.addElement(arrayVPNSystem);
          }
        }
      } catch (Exception e) {
      }
    } catch (Exception e) {
    }

    Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(node.getIpAddress());
    if (ipAllData == null) ipAllData = new Hashtable();
    ipAllData.put("VPNSystem", powerVector);
    ShareData.getSharedata().put(node.getIpAddress(), ipAllData);
    returnHash.put("VPNSystem", powerVector);
    return returnHash;
  }

  //	public static void main(String[] args){
  //		ArrayVPNSystemSnmp arrayVPNCountSnmp = new ArrayVPNSystemSnmp();
  //		Host node = new Host();
  //		node.setIpAddress("10.204.3.254");
  //		node.setCommunity("oavpn-1");
  //		node.setSnmpversion(1);
  //		Hashtable returnHash = arrayVPNCountSnmp.collect_Data(node);
  //		System.out.println(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;
  }
  /*
   *
   * 从内存和数据库表里获取每个IP的端口信息,存入端口配置表里
   */
  public void fromLastToOraspaceconfig() throws Exception {
    List list = new ArrayList();
    List list1 = new ArrayList();
    List shareList = new ArrayList();
    Hashtable oraspacehash = new Hashtable();
    Session session = null;
    Vector configV = new Vector();
    IpTranslation tranfer = new IpTranslation();
    try {
      // 从ORASPACCE配置表里获取列表
      rs = conn.executeQuery("select * from system_oraspaceconf order by ipaddress");
      while (rs.next()) list1.add(loadFromRS(rs));
      if (list1 != null && list1.size() > 0) {
        for (int i = 0; i < list1.size(); i++) {
          Oraspaceconfig oraspaceconfig = (Oraspaceconfig) list1.get(i);
          // IP:表空间名称

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

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

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

    String username = "";
    String pws = "";
    String password = "";
    ConnectDao condao = new ConnectDao();
    List<Connect> list_vo = condao.getbynodeid(Long.parseLong(host.getId() + ""));
    Connect vo = null;
    if (list_vo != null && list_vo.size() > 0) {
      vo = list_vo.get(0);
    }
    username = vo.getUsername();
    pws = vo.getPwd();
    try {
      if (!pws.equals("")) {
        password = EncryptUtil.decode(pws);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(host.getIpAddress());
    if (ipAllData == null) {
      ipAllData = new Hashtable();
    }

    Runtime runtime = Runtime.getRuntime();
    StringBuffer dataBuffer = new StringBuffer();
    try {
      process =
          runtime.exec(
              "naviseccli -user "
                  + username
                  + " -password "
                  + password
                  + " -Scope 0 -h "
                  + host.getIpAddress()
                  + " environment -list -all");
      inputStream = process.getInputStream();
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
      String inStr = "";
      while ((inStr = bufferedReader.readLine()) != null) {
        dataBuffer.append(inStr + "\r\n");
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    Environment environment = EnvironmentParser.parse(dataBuffer.toString());
    Hashtable emcdata = null;
    if (!(ShareData.getEmcdata().containsKey(host.getIpAddress()))) {
      if (emcdata == null) {
        emcdata = new Hashtable();
      }
      if (environment != null) {
        emcdata.put("environment", environment);
      }
      ShareData.getEmcdata().put(host.getIpAddress(), emcdata);
    } else {
      if (environment != null) {
        ((Hashtable) ShareData.getEmcdata().get(host.getIpAddress()))
            .put("environment", environment);
      }
    }
    returnHash.put("environment", environment);

    try {
      EMCLUNConfigController util = new EMCLUNConfigController();
      List list =
          util.EMCgetAlarmInicatorsThresholdForNode(
              String.valueOf(alarmIndicatorsNode.getNodeid()),
              AlarmConstant.TYPE_STORAGE,
              "emc",
              "envpower");

      for (int i = 0; i < list.size(); i++) {
        AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(i);
        String flag = "";
        String name = "";
        if (alarmIndicatorsnode.getEnabled().equals("1")) {
          flag = alarmIndicatorsnode.getSubentity();
          name = alarmIndicatorsnode.getName();
        } else {
          continue;
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("envwt")) {
          util.checkDisk(
              host,
              flag,
              alarmIndicatorsnode,
              "envpower",
              "envwt",
              name,
              flag); // vid=AlarmIndicatorsNode.getSubentity();flag=map的键值(在utilDao
          // 的queryLast()方法里定义的);
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("envavgwt")) {
          util.checkDisk(host, flag, alarmIndicatorsnode, "envpower", "envavgwt", name, flag);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      EMCLUNConfigController util = new EMCLUNConfigController();
      List list =
          util.EMCgetAlarmInicatorsThresholdForNode(
              String.valueOf(alarmIndicatorsNode.getNodeid()),
              AlarmConstant.TYPE_STORAGE,
              "emc",
              "envstore");

      for (int i = 0; i < list.size(); i++) {
        AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(i);
        String flag = "";
        String name = "";
        if (alarmIndicatorsnode.getEnabled().equals("1")) {
          flag = alarmIndicatorsnode.getSubentity();
          name = alarmIndicatorsnode.getName();
        } else {
          continue;
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("memtmp")) {
          util.checkDisk(host, flag, alarmIndicatorsnode, "envstore", "memtmp", name, flag);
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("memavgtmp")) {
          util.checkDisk(host, flag, alarmIndicatorsnode, "envstore", "memavgtmp", name, flag);
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("memwt")) {
          util.checkDisk(host, flag, alarmIndicatorsnode, "envstore", "memwt", name, flag);
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("memavgwt")) {
          util.checkDisk(host, flag, alarmIndicatorsnode, "envstore", "memavgwt", name, flag);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    try {
      EMCLUNConfigController util = new EMCLUNConfigController();
      List list =
          util.EMCgetAlarmInicatorsThresholdForNode(
              String.valueOf(alarmIndicatorsNode.getNodeid()),
              AlarmConstant.TYPE_STORAGE,
              "emc",
              "bakpower");

      for (int i = 0; i < list.size(); i++) {
        AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(i);
        String flag = "";
        String name = "";
        if (alarmIndicatorsnode.getEnabled().equals("1")) {
          flag = alarmIndicatorsnode.getSubentity();
          name = alarmIndicatorsnode.getName();
        } else {
          continue;
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("bakwt")) {
          util.checkDisk(
              host,
              flag,
              alarmIndicatorsnode,
              "bakpower",
              "bakwt",
              name,
              flag); // vid=AlarmIndicatorsNode.getSubentity();flag=map的键值(在utilDao
          // 的queryLast()方法里定义的);
        }
        if (alarmIndicatorsnode.getName().equalsIgnoreCase("bakavgwt")) {
          util.checkDisk(host, flag, alarmIndicatorsnode, "bakpower", "bakavgwt", name, flag);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (environment != null) {
      com.afunms.emc.model.Array array = environment.getArray();
      List<MemModel> liststore = environment.getMemList();
      List<MemModel> listbakpower = environment.getBakPowerList();

      envPerDao dao = new envPerDao();
      dao.saveArray(array, host.getIpAddress());

      dao = new envPerDao();
      dao.saveStore(liststore, host.getIpAddress());

      dao = new envPerDao();
      dao.saveBakPower(listbakpower, host.getIpAddress());
    }
    return returnHash;
  }
Exemplo n.º 22
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;
  }
Exemplo n.º 23
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;
  }
Exemplo n.º 24
0
/**
 * @author Administrator
 *     <p>TODO To change the template for this generated type comment go to Window - Preferences -
 *     Java - Code Style - Code Templates
 */
public class MailDataCollector {
  private Hashtable sendeddata = ShareData.getSendeddata();
  private MailMonitorManager mailconf = null;
  private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  private SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");

  public MailDataCollector() {}

  public void collect_data(String id, Hashtable gatherHash) {
    Emailmonitor_realtimeDao emailmonitor_realtimeDao = null;
    Emailmonitor_historyDao emailmonitor_historyDao = null;
    try {
      EmailConfigDao emailConfigDao = new EmailConfigDao();
      EmailMonitorConfig mailconfig = null;
      try {
        mailconfig = (EmailMonitorConfig) emailConfigDao.findByID(id);
        if (mailconfig.getMonflag() == 0) { // 过滤掉不监控的邮箱
          return;
        }
      } catch (Exception e) {

      } finally {
        emailConfigDao.close();
      }
      Calendar date = Calendar.getInstance();

      ReceiveMail receieveMail = new ReceiveMail();
      sendMail sendmail = new sendMail();

      try {
        emailmonitor_realtimeDao = new Emailmonitor_realtimeDao();

        Hashtable realHash = null;
        try {
          realHash = emailmonitor_realtimeDao.getAllReal();
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          emailmonitor_realtimeDao.close();
        }

        Emailmonitor_history emailmonitor_history = new Emailmonitor_history();
        Emailmonitor_realtime emailold = new Emailmonitor_realtime();
        Integer iscanconnected = new Integer(0);
        String reason = "";
        Mail mail = (Mail) PollingEngine.getInstance().getMailByID(mailconfig.getId());
        if (mail == null) {
          return;
        }
        if (mail != null) {
          mail.setStatus(0);
          mail.setAlarm(false);
          mail.getAlarmMessage().clear();
          Calendar _tempCal = Calendar.getInstance();
          Date _cc = _tempCal.getTime();
          String _time = sdf.format(_cc);
          mail.setLastTime(_time);
        }

        Integer email_id = mailconfig.getId();
        boolean old = false;
        String str = "";
        Integer smssign = new Integer(0);
        if (realHash != null && realHash.get(email_id) != null) {
          old = true;
          emailold = (Emailmonitor_realtime) realHash.get(email_id);
          smssign = emailold.getSms_sign();
        }
        boolean flag = true;
        boolean receieveflag = true;
        int intflag = 0;
        int intreceieveflag = 0;

        try {
          if (gatherHash.containsKey("send")) {
            try {
              if (configSendMail(sendmail, mailconfig)) {
                flag = sendmail.sendmail();
                // intflag = 1;
              }
            } catch (Exception ex) {
              flag = false;
              ex.printStackTrace();
            }
          }

          if (gatherHash.containsKey("receieve")) {
            try {
              String mailserver = "";
              //							if (mailconfig.getAddress().indexOf("mail")>=0){
              //								//用的是MAIL服务
              //								mailserver = mailconfig.getAddress();
              //							}else if (mailconfig.getAddress().indexOf("smtp")>=0){
              //								//用的是SMTP服务
              //								mailserver = "smtp"+mailconfig.getAddress().substring(4);
              //							}else{
              //								//用的是POP3服务
              //								mailserver = "pop3."+mailconfig.getAddress();
              //							}
              mailserver = mailconfig.getReceiveAddress();
              receieveflag =
                  receieveMail.GetReceieveMail(
                      mailserver, mailconfig.getUsername(), mailconfig.getPassword());
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }

          // System.out.println("flag:"+flag+"-----receieveflag:"+receieveflag);
          if (flag && receieveflag) {
            intflag = 1;
            intreceieveflag = 1;
            iscanconnected = 1;
            reason = "服务有效";
            if (sendeddata.containsKey("emailserver:" + mailconfig.getId())) {
              sendeddata.remove("emailserver:" + mailconfig.getId());
            }

          } else {
            if (flag == true && receieveflag == false) {
              // 邮件能发送但不能接收
              intflag = 1;
              reason = "邮件接收服务无效";
              Vector mailvector = new Vector();
              // 开始设置采集值实体
              Interfacecollectdata interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Send");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intflag + "");
              interfacedata.setChname("发送服务");
              mailvector.add(interfacedata);

              interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Receieve");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intreceieveflag + "");
              interfacedata.setChname("接收服务");
              mailvector.add(interfacedata);

              Hashtable collectHash = new Hashtable();
              collectHash.put("mail", mailvector);

              //							mail.setStatus(3);
              //							mail.setAlarm(true);
              //							List alarmList = mail.getAlarmMessage();
              //							if(alarmList == null)alarmList = new ArrayList();

              // createEvent(mailconfig, reason);
              try {
                AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                List list =
                    alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                        String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                for (int k = 0; k < list.size(); k++) {
                  AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                  // 对邮件服务值进行告警检测
                  CheckEventUtil checkutil = new CheckEventUtil();
                  checkutil.updateData(mail, collectHash, "service", "mail", alarmIndicatorsnode);
                  // }
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
              // createEvent(mailconfig, reason);
            } else if (flag == false && receieveflag == true) {
              intreceieveflag = 1;
              // 邮件能接收但不能发送
              reason = "邮件发送服务无效";
              Vector mailvector = new Vector();
              // 开始设置采集值实体
              Interfacecollectdata interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Send");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intflag + "");
              interfacedata.setChname("发送服务");
              mailvector.add(interfacedata);

              interfacedata = new Interfacecollectdata();
              interfacedata.setIpaddress(mail.getIpAddress());
              interfacedata.setCollecttime(date);
              interfacedata.setCategory("Mail");
              interfacedata.setEntity("Receieve");
              interfacedata.setSubentity(mail.getId() + "");
              interfacedata.setRestype("static");
              interfacedata.setUnit("");
              interfacedata.setThevalue(intreceieveflag + "");
              interfacedata.setChname("接收服务");
              mailvector.add(interfacedata);

              Hashtable collectHash = new Hashtable();
              collectHash.put("mail", mailvector);

              //							mail.setStatus(3);
              //							mail.setAlarm(true);
              //							List alarmList = mail.getAlarmMessage();
              //							if(alarmList == null)alarmList = new ArrayList();

              // createEvent(mailconfig, reason);
              try {
                AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                List list =
                    alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                        String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                for (int k = 0; k < list.size(); k++) {
                  AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                  // 对邮件服务值进行告警检测
                  CheckEventUtil checkutil = new CheckEventUtil();
                  checkutil.updateData(mail, collectHash, "service", "mail", alarmIndicatorsnode);
                  // }
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
              // createEvent(mailconfig, reason);
            } else {
              // 邮件服务停止
              // 需要增加邮件服务所在的服务器是否能连通
              // Host host =
              // (Host)PollingEngine.getInstance().getNodeByIP(mailconfig.getIpaddress());
              Vector ipPingData = (Vector) ShareData.getPingdata().get(mailconfig.getIpaddress());
              if (ipPingData != null) {
                Pingcollectdata pingdata = (Pingcollectdata) ipPingData.get(0);
                Calendar tempCal = (Calendar) pingdata.getCollecttime();
                Date cc = tempCal.getTime();
                String time = sdf.format(cc);
                String lastTime = time;
                String pingvalue = pingdata.getThevalue();
                if (pingvalue == null || pingvalue.trim().length() == 0) pingvalue = "0";
                double pvalue = new Double(pingvalue);
                if (pvalue == 0) {
                  // 主机服务器连接不上***********************************************
                  mail.setStatus(3);
                  mail.setAlarm(true);
                  // SysLogger.info(mail.getName()+"========================"+mail.isAlarm());
                  // dbnode.setStatus(3);
                  List alarmList = mail.getAlarmMessage();
                  if (alarmList == null) alarmList = new ArrayList();
                  mail.getAlarmMessage().add("邮件服务无效");
                  String sysLocation = "";
                  try {
                    SmscontentDao smsdao = new SmscontentDao();
                    String eventdesc =
                        "邮件服务("
                            + mailconfig.getName()
                            + " IP:"
                            + mailconfig.getAddress()
                            + ")"
                            + "的邮件服务停止";
                    smsdao.createEventWithReasion(
                        "poll",
                        mailconfig.getId() + "",
                        mailconfig.getName() + "(" + mailconfig.getAddress() + ")",
                        eventdesc,
                        3,
                        "mail",
                        "ping",
                        "所在的服务器连接不上");
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                } else {
                  //									mail.setStatus(3);
                  //									mail.setAlarm(true);
                  //									List alarmList = mail.getAlarmMessage();
                  //									if(alarmList == null)alarmList = new ArrayList();
                  //									mail.getAlarmMessage().add("邮件服务无效");
                  //									reason="邮件服务无效";
                  Vector mailvector = new Vector();
                  // 开始设置采集值实体
                  Interfacecollectdata interfacedata = new Interfacecollectdata();
                  interfacedata.setIpaddress(mail.getIpAddress());
                  interfacedata.setCollecttime(date);
                  interfacedata.setCategory("Mail");
                  interfacedata.setEntity("Send");
                  interfacedata.setSubentity(mail.getId() + "");
                  interfacedata.setRestype("static");
                  interfacedata.setUnit("");
                  interfacedata.setThevalue(intflag + "");
                  interfacedata.setChname("发送服务");
                  mailvector.add(interfacedata);

                  interfacedata = new Interfacecollectdata();
                  interfacedata.setIpaddress(mail.getIpAddress());
                  interfacedata.setCollecttime(date);
                  interfacedata.setCategory("Mail");
                  interfacedata.setEntity("Receieve");
                  interfacedata.setSubentity(mail.getId() + "");
                  interfacedata.setRestype("static");
                  interfacedata.setUnit("");
                  interfacedata.setThevalue(intreceieveflag + "");
                  interfacedata.setChname("接收服务");
                  mailvector.add(interfacedata);

                  Hashtable collectHash = new Hashtable();
                  collectHash.put("mail", mailvector);

                  //									mail.setStatus(3);
                  //									mail.setAlarm(true);

                  // createEvent(mailconfig, reason);
                  try {
                    AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                    List list =
                        alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                            String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                    for (int k = 0; k < list.size(); k++) {
                      AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                      // 对邮件服务值进行告警检测
                      CheckEventUtil checkutil = new CheckEventUtil();
                      checkutil.updateData(
                          mail, collectHash, "service", "mail", alarmIndicatorsnode);
                      // }
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                  // createEvent(mailconfig, reason);
                }

              } else {
                //								mail.setStatus(3);
                //								mail.setAlarm(true);
                //								List alarmList = mail.getAlarmMessage();
                //								if(alarmList == null)alarmList = new ArrayList();
                //								mail.getAlarmMessage().add("邮件服务无效");
                //								reason="邮件服务无效";
                Vector mailvector = new Vector();
                // 开始设置采集值实体
                Interfacecollectdata interfacedata = new Interfacecollectdata();
                interfacedata.setIpaddress(mail.getIpAddress());
                interfacedata.setCollecttime(date);
                interfacedata.setCategory("Mail");
                interfacedata.setEntity("Send");
                interfacedata.setSubentity(mail.getId() + "");
                interfacedata.setRestype("static");
                interfacedata.setUnit("");
                interfacedata.setThevalue(intflag + "");
                interfacedata.setChname("发送服务");
                mailvector.add(interfacedata);

                interfacedata = new Interfacecollectdata();
                interfacedata.setIpaddress(mail.getIpAddress());
                interfacedata.setCollecttime(date);
                interfacedata.setCategory("Mail");
                interfacedata.setEntity("Receieve");
                interfacedata.setSubentity(mail.getId() + "");
                interfacedata.setRestype("static");
                interfacedata.setUnit("");
                interfacedata.setThevalue(intreceieveflag + "");
                interfacedata.setChname("接收服务");
                mailvector.add(interfacedata);

                Hashtable collectHash = new Hashtable();
                collectHash.put("mail", mailvector);

                //								mail.setStatus(3);
                //								mail.setAlarm(true);

                // createEvent(mailconfig, reason);
                try {
                  AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
                  List list =
                      alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(
                          String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
                  for (int k = 0; k < list.size(); k++) {
                    AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode) list.get(k);
                    // 对邮件服务值进行告警检测
                    CheckEventUtil checkutil = new CheckEventUtil();
                    checkutil.updateData(mail, collectHash, "service", "mail", alarmIndicatorsnode);
                    // }
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
                // createEvent(mailconfig, reason);
              }
            }
          }
        } catch (Exception ex) {
          //					//不能进行邮件服务
          //					EventList event = new EventList();
          //					if (flag == true && receieveflag == false){
          //						intflag = 1;
          //						reason="邮件接收服务无效";
          //						mail.getAlarmMessage().add("邮件接收服务无效");
          //					}else if (flag == false && receieveflag == true){
          //						intreceieveflag = 1;
          //						reason="邮件发送服务无效";
          //						mail.getAlarmMessage().add("邮件发送服务无效");
          //					}
          //					Vector mailvector = new Vector();
          //					//开始设置采集值实体
          //					Interfacecollectdata interfacedata=new Interfacecollectdata();
          //					interfacedata.setIpaddress(mail.getIpAddress());
          //					interfacedata.setCollecttime(date);
          //					interfacedata.setCategory("Mail");
          //					interfacedata.setEntity("Send");
          //					interfacedata.setSubentity(mail.getId()+"");
          //					interfacedata.setRestype("static");
          //					interfacedata.setUnit("");
          //					interfacedata.setThevalue(intflag+"");
          //					interfacedata.setChname("发送服务");
          //					mailvector.add(interfacedata);
          //
          //					interfacedata=new Interfacecollectdata();
          //					interfacedata.setIpaddress(mail.getIpAddress());
          //					interfacedata.setCollecttime(date);
          //					interfacedata.setCategory("Mail");
          //					interfacedata.setEntity("Receieve");
          //					interfacedata.setSubentity(mail.getId()+"");
          //					interfacedata.setRestype("static");
          //					interfacedata.setUnit("");
          //					interfacedata.setThevalue(intreceieveflag+"");
          //					interfacedata.setChname("接收服务");
          //					mailvector.add(interfacedata);
          //
          //					Hashtable collectHash = new Hashtable();
          //					collectHash.put("mail", mailvector);
          //
          //					mail.setStatus(3);
          //					mail.setAlarm(true);
          //					List alarmList = mail.getAlarmMessage();
          //					if(alarmList == null)alarmList = new ArrayList();
          //
          //					createEvent(mailconfig, reason);
          //				    try{
          //						AlarmIndicatorsUtil alarmIndicatorsUtil = new AlarmIndicatorsUtil();
          //						List list =
          // alarmIndicatorsUtil.getAlarmInicatorsThresholdForNode(String.valueOf(mailconfig.getId()), AlarmConstant.TYPE_SERVICE, "mail");
          //						for(int k = 0 ; k < list.size() ; k ++){
          //							AlarmIndicatorsNode alarmIndicatorsnode = (AlarmIndicatorsNode)list.get(k);
          //							//对邮件服务值进行告警检测
          //							CheckEventUtil checkutil = new CheckEventUtil();
          //							checkutil.updateData(mail,collectHash,"service","mail",alarmIndicatorsnode);
          //							//}
          //						}
          //				    }catch(Exception e){
          //				    	e.printStackTrace();
          //				    }
        }
        // 保存进历史数据
        emailmonitor_history.setEmail_id(mailconfig.getId());
        emailmonitor_history.setIs_canconnected(iscanconnected);
        emailmonitor_history.setMon_time(Calendar.getInstance());
        emailmonitor_history.setReason(reason);
        emailmonitor_historyDao = new Emailmonitor_historyDao();
        try {
          emailmonitor_historyDao.save(emailmonitor_history);
        } catch (Exception e) {

        }
        if (sendeddata.containsKey("emailserver:" + mailconfig.getId())) {
          sendeddata.remove("emailserver:" + mailconfig.getId());
        }

        // 实时数据
        Emailmonitor_realtime emailmonitor_realtime = new Emailmonitor_realtime();
        emailmonitor_realtime.setEmail_id(mailconfig.getId());
        emailmonitor_realtime.setIs_canconnected(iscanconnected);
        emailmonitor_realtime.setMon_time(Calendar.getInstance());
        emailmonitor_realtime.setReason(reason);

        if (old == true) {
          emailmonitor_realtime.setId(emailold.getId());
          emailmonitor_realtime.setSms_sign(1);
        } else {
          emailmonitor_realtime.setSms_sign(smssign);
        }
        // 保存realtime
        if (old == true) {
          emailmonitor_realtimeDao = new Emailmonitor_realtimeDao();
          try {
            emailmonitor_realtimeDao.update(emailmonitor_realtime);
          } catch (Exception e) {

          } finally {
            emailmonitor_realtimeDao.close();
          }
        }
        if (old == false) {
          emailmonitor_realtimeDao = new Emailmonitor_realtimeDao();
          try {
            emailmonitor_realtimeDao.save(emailmonitor_realtime);
          } catch (Exception e) {

          } finally {
            emailmonitor_realtimeDao.close();
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        emailmonitor_historyDao.close();
        emailmonitor_realtimeDao.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (emailmonitor_realtimeDao != null) {
        emailmonitor_historyDao.close();
      }
      if (emailmonitor_realtimeDao != null) {
        emailmonitor_realtimeDao.close();
      }
    }
  }

  public sendMail createSendMail() {
    sendMail sendmail = new sendMail();
    return sendmail;
  }

  public ReceiveMail createReceiveMail() {
    ReceiveMail receiveMail = new ReceiveMail();
    return receiveMail;
  }

  public String configAddress(EmailMonitorConfig mailCnfig) {
    String fromAddress = "";
    //		if (mailCnfig.getAddress().indexOf("mail")== -1 && mailCnfig.getAddress().indexOf("smtp")==
    // -1){
    //			//为IP地址
    //			fromAddress = mailCnfig.getAddress();
    //		}else{
    //			//为接受服务器(pop) 或者 为发送服务器(smtp)
    //			fromAddress = mailCnfig.getAddress().substring(5,mailCnfig.getAddress().length());
    //		}
    fromAddress = mailCnfig.getAddress();
    return fromAddress;
  }

  public boolean configSendMail(sendMail sendmail, EmailMonitorConfig mailConfig)
      throws AddressException {
    Address[] ccAddress = {
      new InternetAddress("*****@*****.**"), new InternetAddress("*****@*****.**")
    };
    sendmail.setMailaddress(configAddress(mailConfig));
    System.out.println(configAddress(mailConfig));
    sendmail.setSendmail(mailConfig.getUsername());
    sendmail.setSendpasswd(mailConfig.getPassword());
    sendmail.setToAddr(mailConfig.getRecivemail());
    sendmail.setBody("邮件服务测试");
    sendmail.setSubject("邮件服务设置");
    sendmail.setFromAddr(mailConfig.getUsername() + "@" + mailConfig.getAddress());
    sendmail.setCcAddress(ccAddress);
    return true;
  }

  public void createEvent(EmailMonitorConfig mailconfig, String reason) {
    Calendar date = Calendar.getInstance();
    String time = sdf.format(date.getTime());
    EventList event = new EventList();
    event.setEventtype("mailserver");
    event.setEventlocation(mailconfig.getName());
    event.setBusinessid(mailconfig.getBid());
    event.setManagesign(new Integer(0));
    event.setReportman("系统轮询");
    event.setRecordtime(new GregorianCalendar());
    String errorcontent =
        time
            + " "
            + "邮件服务("
            + mailconfig.getName()
            + " IP:"
            + mailconfig.getIpaddress()
            + ")"
            + "的邮件服务停止";
    event.setContent(errorcontent);
    Integer level = new Integer(2);
    event.setLevel1(level);
    Vector eventtmpV = new Vector();
    eventtmpV.add(event);
    // EventListDao eventListDao = null ;
    try {
      // eventListDao = new EventListDao();
      // eventListDao.save(event);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      // eventListDao.close();
    }
    try {
      createSMS("mailserver", mailconfig.getId() + "", errorcontent, mailconfig.getName());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void createSMS(String mailserver, String mail_id, String errmsg, String mailstr) {
    // 建立短信
    // 从内存里获得当前这个IP的PING的值
    Calendar date = Calendar.getInstance();
    try {
      if (!sendeddata.containsKey(mailserver + ":" + mail_id)) {
        // 若不在,则建立短信,并且添加到发送列表里
        Smscontent smscontent = new Smscontent();
        smscontent.setMessage(errmsg);
        smscontent.setObjid(mail_id);
        Calendar _tempCal = Calendar.getInstance();
        Date _cc = _tempCal.getTime();
        String _time = sdf.format(_cc);
        smscontent.setRecordtime(_time);
        smscontent.setSubtype("mail");
        smscontent.setLevel(3 + "");
        // 发送短信
        SmscontentDao smsmanager = new SmscontentDao();
        smsmanager.sendURLSmscontent(smscontent);
        sendeddata.put(mailserver + ":" + mail_id, date);
      } else {
        // 若在,则从已发送短信列表里判断是否已经发送当天的短信
        Calendar formerdate = (Calendar) sendeddata.get(mailserver + ":" + mail_id);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date last = null;
        Date current = null;
        Calendar sendcalen = formerdate;
        Date cc = sendcalen.getTime();
        String tempsenddate = formatter.format(cc);

        Calendar currentcalen = date;
        cc = currentcalen.getTime();
        last = formatter.parse(tempsenddate);
        String currentsenddate = formatter.format(cc);
        current = formatter.parse(currentsenddate);

        long subvalue = current.getTime() - last.getTime();
        if (subvalue / (1000 * 60 * 60 * 24) >= 1) {
          // 超过一天,则再发信息
          Smscontent smscontent = new Smscontent();
          // String time = sdf.format(date.getTime());
          smscontent.setMessage(errmsg.replace("&", " "));
          smscontent.setObjid(mail_id);
          Calendar _tempCal = Calendar.getInstance();
          Date _cc = _tempCal.getTime();
          String _time = sdf.format(_cc);
          smscontent.setRecordtime(_time);
          smscontent.setSubtype("mail");
          smscontent.setLevel(3 + "");
          // 发送短信
          SmscontentDao smsmanager = new SmscontentDao();
          smsmanager.sendURLSmscontent(smscontent);
          // 修改已经发送的短信记录
          sendeddata.put(mailserver + ":" + mail_id, date);
        } else {
          // 则写声音告警数据
          // 向声音告警表里写数据
          AlarmInfo alarminfo = new AlarmInfo();
          alarminfo.setContent(errmsg.replace("&", " "));
          alarminfo.setIpaddress(mailstr);
          alarminfo.setLevel1(new Integer(2));
          alarminfo.setRecordtime(Calendar.getInstance());
          AlarmInfoDao alarmdao = new AlarmInfoDao();
          alarmdao.save(alarminfo);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}