コード例 #1
0
 private void changeMailManage() {
   boolean result = false;
   EmailMonitorConfig emailMonitorConfig = new EmailMonitorConfig();
   EmailConfigDao emailConfigDao = null;
   try {
     String id = getParaValue("id");
     int monflag = getParaIntValue("value");
     emailConfigDao = new EmailConfigDao();
     emailMonitorConfig = (EmailMonitorConfig) emailConfigDao.findByID(id);
     emailMonitorConfig.setMonflag(monflag);
     result = emailConfigDao.update(emailMonitorConfig);
     Mail mail = (Mail) PollingEngine.getInstance().getMailByID(Integer.parseInt(id));
     mail.setFlag(monflag);
   } catch (Exception e) {
     e.printStackTrace();
     result = false;
   } finally {
     emailConfigDao.close();
   }
 }
コード例 #2
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();
      }
    }
  }