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 {
    }
  }
  public void createSMS(String web, com.afunms.polling.node.Tomcat node) {
    // 建立短信
    // 从内存里获得当前这个IP的PING的值
    Calendar date = Calendar.getInstance();
    try {
      if (!sendeddata.containsKey(web + ":" + node.getId())) {
        // 若不在,则建立短信,并且添加到发送列表里
        Smscontent smscontent = new Smscontent();
        String time = sdf.format(date.getTime());
        smscontent.setLevel("2");
        smscontent.setObjid(node.getId() + "");
        smscontent.setMessage(node.getIpAddress() + "的TOMCAT服务停止");
        smscontent.setRecordtime(time);
        smscontent.setSubtype("tomcat");
        smscontent.setSubentity("ping");
        smscontent.setIp(node.getIpAddress());

        // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止");
        // 发送短信
        SmscontentDao smsmanager = new SmscontentDao();
        smsmanager.sendURLSmscontent(smscontent);
        sendeddata.put(web + ":" + node.getId(), date);
      } else {
        // 若在,则从已发送短信列表里判断是否已经发送当天的短信
        Calendar formerdate = (Calendar) sendeddata.get(web + ":" + node.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(node.getId() + "");
          smscontent.setMessage(node.getAlias() + " (" + node.getIpAddress() + ")" + "的访问服务停止");
          smscontent.setRecordtime(time);
          smscontent.setSubtype("tomcat");
          smscontent.setSubentity("ping");
          smscontent.setIp(node.getIpAddress());
          // smscontent.setMessage("db&"+time+"&"+dbmonitorlist.getId()+"&"+db+"("+dbmonitorlist.getDbName()+" IP:"+dbmonitorlist.getIpAddress()+")"+"的数据库服务停止");
          // 发送短信
          SmscontentDao smsmanager = new SmscontentDao();
          smsmanager.sendURLSmscontent(smscontent);
          // 修改已经发送的短信记录
          sendeddata.put(web + ":" + node.getId(), date);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  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();
    }
  }
Пример #4
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();
    }
  }
Пример #5
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();
      }
    }
  }